Patterns from Distributed Systems
High-throughput messaging and trading systems push throughput patterns to the extreme.
| Pattern | Project | Where | What It Does |
|---|---|---|---|
| Ring Buffer | LMAX Disruptor | RingBuffer.java | Core data structure — 6M orders/sec at LMAX Exchange |
| Batch Processing | Apache Kafka | RecordAccumulator.java | Accumulate records into batches per partition for throughput |
| Circuit Breaker | Netflix Hystrix | HystrixCircuitBreaker.java | Three-state circuit breaker for microservice resilience |
| Circuit Breaker | Sony gobreaker | gobreaker.go | Go circuit breaker with generation-based staleness detection |
| Backpressure | Reactive Streams | Subscription.java | request(n) pull-based flow control specification |
| Write-Ahead Log | etcd | wal.go | Raft consensus WAL — source of truth for distributed state |
| Write-Ahead Log | PostgreSQL | xlog.c | Transaction WAL for crash recovery, replication, PITR |
| MVCC | PostgreSQL | heapam_visibility.c | HeapTupleSatisfiesMVCC — snapshot isolation visibility check |
| MVCC | etcd | kvstore.go | Multi-version key-value store powering Kubernetes config |
| Consistent Hashing | groupcache | consistenthash.go | Hash ring with virtual replicas for distributed caching |
| Actor Model | Akka | Actor.scala | trait Actor — message-driven concurrency for JVM |
| Actor Model | Erlang/OTP | erl_process.h | BEAM VM process struct — lightweight actor with mailbox |
| Rate Limiter | Nginx | ngx_http_limit_req_module.c | Leaky bucket rate limiting for HTTP requests |
| Logical Clock | etcd | mvcc/revision.go | Monotonic revision counter for event ordering across cluster |
| Logical Clock | LevelDB | db_impl.cc sequence number | Sequence numbers order all writes without wall-clock time |
| Retry Backoff | Kubernetes | backoff.go | Pod restart backoff, API server retries with exponential delay |
| Tombstone | Cassandra | Tombstone markers | Delete markers in distributed delete propagation |
| LSM Tree | LevelDB | db_impl.cc | Buffer writes in memory, flush to sorted files, compact in background |
| Checkpointing | PostgreSQL | checkpointer.c | Periodic state snapshot bounds WAL replay time on crash recovery |
How They Compose: A Distributed Write
When a client writes a key to a distributed database like etcd, patterns chain across the entire path:
Client: PUT /key "value"▼The gateway applies a token bucket to prevent any single client from overwhelming the cluster.
The router determines which node owns this key. Virtual nodes ensure load stays balanced even when nodes join/leave.
Before modifying state, the leader appends the operation to a WAL on disk. If the process crashes, replay recovers state.
The write gets a monotonic revision number. No wall-clock sync needed — all nodes agree on ordering via the revision.
The new version is stored alongside old versions. Concurrent readers see a consistent snapshot without blocking the write.
Periodically, the system takes a snapshot. Future crash recovery replays only the WAL entries after the last checkpoint.
The patterns form a durability pipeline: rate limiting protects the system, consistent hashing routes the request, WAL ensures durability, logical clocks order events, MVCC provides isolation, and checkpoints bound recovery time.