Wire Formats Compared: Protobuf, Cap'n Proto & FlatBuffers

Every microservice architecture faces a fundamental question: how should services encode data when communicating? The answer matters enormously at scale. When you’re transferring terabytes daily between services, serialization format determines network bandwidth costs, latency, CPU utilization, and ultimately whether your system can handle peak load. A poorly chosen format can double your AWS bill or add 50ms to every request; a well-chosen format essentially disappears from your performance profile. This article examines wire formats for service-to-service communication in distributed systems handling extreme data volumes. We analyze JSON, MessagePack, Protocol Buffers, FlatBuffers, Cap’n Proto, Apache Avro, and Apache Thrift, implementing each in Rust and measuring their performance characteristics. Through mathematical modeling and empirical benchmarks, we determine when each format excels and quantify the cost implications of format choices at terabyte scale. ...

November 24, 2025 · 26 min · 5411 words · Svein Erik

Columnar Storage in Go: Fast Financial Aggregation

Consider a financial analytics platform serving real-time portfolio metrics to thousands of clients. Traditional row-oriented storage loads entire transaction records into memory—customer ID, timestamp, instrument, quantity, price, fees—even when clients only request daily trade volumes. At 10 million transactions per day with 50-byte records, this means loading 500MB to calculate a single sum. By switching to columnar storage where each field lives in its own contiguous array, the same aggregation touches only 40MB (the price column), fits in CPU cache, and completes 18× faster. The architecture shift isn’t just about memory efficiency. It’s about aligning data layout with how modern CPUs actually process numerical operations. ...

March 26, 2025 · 21 min · 4400 words · Svein Erik

Neural Networks from Scratch in Rust

In 2017, a fraud detection startup discovered their Python-based neural network inference was creating a hidden cost: 200 milliseconds of latency per transaction. At their scale—15,000 transactions per second—this meant holding $3 million in pending transactions at any moment, exposing them to market risk and regulatory scrutiny. When they rewrote their inference engine in Rust, latency dropped to 8 milliseconds—a 25× improvement—and throughput increased enough to handle 10× growth without additional hardware. The difference wasn’t algorithmic sophistication. It was understanding how neural networks actually execute on real hardware and choosing a language that exposed rather than obscured those realities. ...

March 18, 2025 · 31 min · 6572 words · Svein Erik

Caching Strategies: Cache-Aside, Write-Through & Eviction

Caching is a classical systems technique that reduces access latency by retaining temporary replicas of data closer to the point of consumption. A typical deployment comprises a backing store (for example, a relational database) that maintains the authoritative copy and one or more cache layers that materialize frequently accessed subsets. Although caching shares certain characteristics with colocation and replication, it introduces its own spectrum of latency, consistency, and operational trade-offs. This note surveys the conceptual foundations of caching and examines the strategies that practitioners employ in production systems. ...

February 14, 2025 · 47 min · 9937 words · Svein Erik

Low-Latency Trading Systems in Rust

In high-frequency trading (HFT), microseconds determine profitability. When an arbitrage opportunity appears—say, a 0.01% price discrepancy between two exchanges—it vanishes within 100-500 microseconds as competing algorithms exploit it. The firm that detects and acts fastest captures the profit; everyone else loses. At this timescale, traditional software engineering practices (dynamic allocation, garbage collection, high-level abstractions) become liabilities. Systems must operate at the edge of hardware capability: cache-line optimization, lock-free algorithms, kernel bypass networking. ...

September 2, 2024 · 52 min · 10914 words · Svein Erik

Recommendation Systems in Production (Part 3 of 6)

Part 3 of 6 | ← Part 2: Ranking | Part 4: Ethics & Safety → Evaluation and Metrics Recommendation systems require rigorous evaluation across offline, online, and long-term dimensions. Offline Metrics Metric Definition Use Case AUC-ROC Area under ROC curve for engagement prediction Pointwise model quality Log-loss Cross-entropy of predicted probabilities Calibration quality NDCG@k Normalized discounted cumulative gain at rank k Ranking quality Recall@k Fraction of relevant items in top-k Retrieval coverage Hit Rate Whether the engaged item appears in top-k Retrieval success Offline metrics use held-out interaction logs; they are necessary but not sufficient for production decisions. ...

July 10, 2024 · 27 min · 5544 words · Svein Erik

Social Media Platform Architecture at Scale

Modern social media platforms serve billions of users with sub-second latency requirements while handling massive write throughput and complex relationship graphs. This article examines the systems architecture required to build an Instagram or Facebook-scale platform, analyzing the mathematical models, algorithmic optimizations, and distributed systems patterns that enable performance at scale. Building a social media platform that can scale to billions of users is one of the most challenging problems in distributed systems. Unlike e-commerce sites with predictable traffic patterns or enterprise applications with controlled user bases, social platforms face extreme challenges: viral content creates massive traffic spikes, the social graph creates complex data dependencies, and user expectations demand instant updates. When Kim Kardashian posts a photo, millions of users want to see it within seconds—the system must handle this gracefully while simultaneously serving billions of other requests. ...

October 8, 2023 · 30 min · 6219 words · Svein Erik

Building a Time Series Database in Go

Time series databases (TSDBs) are specialized storage engines optimized for time-stamped data at massive scale. Unlike general-purpose databases, TSDBs exploit temporal locality, high write throughput, and read patterns dominated by range queries and aggregations. This article explores the architecture, algorithms, and implementation techniques for building a production-grade TSDB in Go, examining both storage and query engines with mathematical analysis of performance characteristics. Modern observability platforms like Prometheus, Grafana, and Datadog rely on time series databases to handle billions of metrics per second. These systems face unique challenges: metrics arrive continuously at high velocity, queries scan large time ranges for trend analysis, and storage costs must remain manageable despite exponential data growth. A general-purpose database like PostgreSQL or MongoDB would struggle under this workload—the access patterns are fundamentally different from transactional (OLTP) or analytical (OLAP) systems. ...

June 11, 2023 · 44 min · 9276 words · Svein Erik

Vector Optimization: SIMD, Cache Lines & Memory Bandwidth

In 2019, a quantitative trading firm discovered their portfolio risk calculation was bottlenecked not by algorithmic complexity, but by memory access patterns. By restructuring their data layout and applying SIMD vectorization, they reduced computation time from 47 seconds to 890 milliseconds—a 53× speedup—without changing a single line of business logic. The difference between naive and optimized vector operations isn’t just academic; it’s the difference between real-time decision making and stale analysis in production systems. ...

March 11, 2022 · 33 min · 6981 words · Svein Erik