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

Building an MCP Server in Go: Graph Tools & Access Control

Consider a social media platform with 8 million users facing a content moderation bottleneck: hate speech reports take 4-6 hours to reach moderators, and at scale—120,000 reports per week—harmful content stays visible long enough to go viral. By building an MCP server in Go to expose moderation graphs and access controls to AI-powered triage, response time could drop to under 2 minutes—a 180× improvement—while accuracy increases from 67% (keyword-based) to 94% (context-aware AI analysis). The architecture shift isn’t just about speed. It’s about building composable tools that can understand social graphs, enforce access hierarchies, and apply legal frameworks programmatically. ...

March 25, 2025 · 30 min · 6240 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

Feed Ranking Architecture & Operations (Part 5 of 6)

Part 5 of 6 | ← Part 4: Ethics & Safety | Part 6: Advanced Topics → Case Study: Feed Ranking Architecture The following synthesizes public disclosures from major platforms (Meta, TikTok, YouTube, Twitter/X) into a representative architecture. Request Flow sequenceDiagram participant Client participant Gateway participant Retrieval participant Ranking participant Reranking participant Collator Client->>Gateway: Feed request Gateway->>Retrieval: Get candidates (user_id, context) Retrieval-->>Gateway: 5000 candidates Gateway->>Ranking: Score candidates Ranking-->>Gateway: 500 scored items Gateway->>Reranking: Apply diversity, policy Reranking-->>Gateway: 100 items Gateway->>Collator: Mix organic + ads + notifications Collator-->>Gateway: 50 items Gateway-->>Client: Feed response (paginated) Component Details Component Implementation Retrieval Two-tower model (user/item embeddings) + graph-based (friends’ posts) + trending Ranking Multi-task DCN with 100+ features; outputs P(click), P(like), P(share), P(hide), E(watch_time) Re-ranking MMR for diversity; policy filters; creator frequency caps Feed Collator Interleaves organic posts, ads (from separate auction), and system notifications Latency Budget Stage Target Latency (P99) Feature fetch 10 ms Retrieval 30 ms Ranking (500 items) 50 ms Re-ranking 10 ms Total < 150 ms Caching, precomputation, and model optimization keep end-to-end latency within budget. ...

July 10, 2024 · 8 min · 1539 words · Svein Erik

Recommendation System Architecture & Features (Part 1 of 6)

Part 1 of 6 | Part 2: Ranking & Re-ranking → Introduction Social media platforms generate value by connecting users with content they find engaging. The recommendation system—the algorithmic machinery that selects which posts, videos, or accounts to surface—is the engine of this engagement. A well-designed recommender balances multiple objectives: user satisfaction, content diversity, creator economics, and platform health. This article examines the architecture of production-grade recommendation systems, drawing on published designs from major platforms while maintaining a principled, systems-oriented perspective. ...

July 10, 2024 · 24 min · 4944 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

The Actor Model: Concurrency Through Message Passing

Introduction As modern systems evolve toward distributed, highly parallel architectures, traditional concurrency techniques—locks, mutexes, and shared memory—quickly reveal their limitations. Deadlocks, race conditions, complex state coordination, and scaling bottlenecks become the norm rather than the exception. The Actor Model offers a radically different paradigm. Instead of sharing memory between threads, actors communicate by sending immutable messages, allowing systems to scale horizontally, avoid shared-state complexity, and model real-world workflows with surprising elegance. ...

April 17, 2022 · 34 min · 7033 words · Svein Erik

Building a Derivatives Pricing DSL in Rust

Financial institutions require precise, auditable, and performant valuation of derivative portfolios. This article presents the design and implementation of a domain-specific language (DSL) for pricing futures and forwards, embedded in Rust. We examine the mathematical foundations of derivative pricing, construct a type-safe expression language, and build an evaluation engine capable of handling portfolios containing thousands of instruments. Introduction Futures and forwards are fundamental derivatives: contracts obligating parties to transact an underlying asset at a predetermined price on a future date. While conceptually similar, they differ in standardization (futures trade on exchanges, forwards are OTC) and settlement mechanics (futures mark-to-market daily, forwards settle at maturity). ...

April 29, 2021 · 17 min · 3418 words · Svein Erik