Archive·The System Design
PDF·30Stories

The System Design

An Engineering Newspaper · Curated by Adarsh Kumar

  /\_/\
 (=^.^=)
 (")_(")
				
  /\_/\
 (=^.^=)
 (")_(")
				

Source
Signal

No stories match the selected filters in today's edition.

Amazon DynamoDB achieves single-digit millisecond response times at any scale by completely decoupling request admission, consistent hashing routing, and multi-Paxos storage groups. When a client SDK issues an operation, a stateless fleet of HTTP/2 request routers hashes the partition key using MD5 into a 128-bit ring to forward the request directly to the leader of the corresponding storage group.

Each storage partition is replicated across three availability zones using a Multi-Paxos consensus quorum. Writes require confirmation from a two-of-three majority before returning, while strongly consistent reads verify leadership leases on local storage nodes. When any partition exceeds 10 gigabytes of data or reaches its throughput threshold, DynamoDB autonomously provisions two child partitions and transparently splits the token space in the background without dropping client traffic.

A centralized partition management coordinator orchestrates the split protocol by taking an asynchronous snapshot of the parent partition’s B-tree storage engine, synchronizing recent transaction logs, and performing an atomic metadata pointer swap in global routing tables.

This strict architectural isolation ensures that runaway queries or localized traffic spikes never cascade into global cluster degradation, providing reliable predictability from single requests to hundreds of millions of operations per second.

During autoregressive large language model inference, the Key-Value cache expands with every generated token. Earlier serving engines pre-allocated contiguous memory based on maximum sequence lengths, stranding up to eighty percent of expensive GPU High Bandwidth Memory in unused allocations and severely constraining concurrent batch sizes.

Inspired by operating system virtual memory paging, vLLM introduces PagedAttention to partition the KV cache into fixed-size physical memory blocks. A lightweight page table maps logical token sequences to non-contiguous blocks in GPU RAM on the fly, eliminating internal memory fragmentation completely.

When evaluating parallel decoding branches or speculative sampling, PagedAttention executes lockless copy-on-write pointer updates at the block level rather than cloning entire prompt sequence memory arrays in VRAM.

This architecture enables near-optimal continuous batching and lockless copy-on-write sharing for parallel decoding streams, boosting serving throughput by up to four times under identical hardware footprints.

Achieving strict serializability across globally distributed database nodes typically requires either a centralized timestamp oracle bottleneck or high-latency multi-round consensus handshakes for every read transaction.

Google Spanner solves this distributed consensus challenge by integrating hardware TrueTime master daemons equipped with atomic rubidium clocks and GPS antennas across all datacenter locations. The TrueTime API returns time as a deterministic range [earliest, latest] where the absolute real time is mathematically guaranteed to fall within the bounded error margin epsilon (typically under 7 milliseconds).

When a leader node commits a transaction, it assigns a commit timestamp equal to or greater than the current TrueTime latest. The leader then waits out the uncertainty window (commit wait) before releasing write locks and publishing results to read clients.

Because commit timestamps reflect true physical causality, read-only transactions execute without acquiring locks or communicating with Paxos quorums, reading consistent data snapshots at any past timestamp globally.

As Discord scaled past trillions of messages, their Apache Cassandra cluster suffered severe latency spikes driven by JVM garbage collection pauses, heavy tombstone evaluation on channel deletions, and unpredictable OS page cache eviction cycles.

Discord re-architected their entire storage layer by migrating to ScyllaDB, a C++ rewrite of Cassandra utilizing the Seastar asynchronous shared-nothing framework. By binding worker threads directly to CPU cores and bypassing the OS page cache with direct asynchronous I/O, ScyllaDB eliminated stop-the-world GC latency spikes.

To protect ScyllaDB from hot partition storms when millions of users simultaneously open active channels, Discord deployed a stateless intermediate Rust caching layer (Monolith and Request Coalescing Proxy).

The Rust proxy coalesces concurrent identical read queries into a single upstream database request using futures-based singleflight channels, reducing read traffic to storage nodes by an order of magnitude.

In HTTP/2 over standard TCP, dropping a single packet across an unstable cellular network causes the entire TCP stream buffer to stall (Head-of-Line blocking), halting all multiplexed HTTP streams until the lost packet is retransmitted.

HTTP/3 replaces TCP with QUIC, a transport protocol implemented on top of UDP with embedded TLS 1.3 encryption. In QUIC, stream multiplexing is native to the transport layer: a dropped packet on stream A pauses only stream A, allowing streams B and C to continue processing without delay.

QUIC establishes 0-RTT connection resumption by combining cryptographic and transport handshakes into a single round trip.

Furthermore, QUIC identifies connections using 64-bit Connection IDs rather than TCP 4-tuples (IP:Port), allowing mobile devices to transition from Wi-Fi to cellular networks without tearing down active connections.

The 2007 Amazon Dynamo paper established the design blueprint for modern highly available distributed NoSQL key-value storage systems. Dynamo prioritizes write availability over strict consistency (following the CAP theorem) to guarantee that customers can always add items to their shopping carts.

Dynamo partitions data across a consistent hashing ring using virtual nodes (tokens) to balance storage distribution. Each key is replicated to N successive physical nodes along the ring (the preference list).

Read and write operations execute using configurable sloppy quorums (R + W > N).

When primary replica nodes become unreachable during network partitions, sibling nodes accept hinted handoffs, storing mutation logs locally and forwarding them once the primary node recovers.

Traditional Kubernetes service mesh architectures inject an Envoy proxy sidecar container into every application pod. When pod A communicates with pod B on the same host, packets traverse the TCP/IP network stack four separate times (App -> Sidecar A -> Host Net -> Sidecar B -> App), consuming excessive CPU and adding milliseconds of latency.

Cilium reimagines service mesh networking by running eBPF programs directly inside the Linux kernel socket layer (sock_ops and sk_msg). When application containers initiate TCP connections, Cilium attaches eBPF bytecode to the sys_connect and sock_msg kernel hooks, performing L4 load balancing and policy enforcement directly at the socket struct level.

For pod-to-pod communication on the same node, Cilium bypasses the TCP/IP stack completely, streaming data directly from sender socket buffers to receiver socket buffers via memory pointers.

For L7 traffic inspection (such as HTTP header routing and mTLS), Cilium runs an optimized per-node Envoy daemon rather than per-pod sidecars, slashing cluster-wide memory usage by up to 80%.

Executing exact k-nearest neighbor (k-NN) search across millions of high-dimensional dense vector embeddings requires computing full cosine or Euclidean distance matrices, leading to O(N * D) computational complexity that breaks real-time latency budgets.

Hierarchical Navigable Small World (HNSW) graphs solve this search challenge by constructing a multi-layer graph hierarchy analogous to a probabilistic skip list. The top layers contain sparse networks of long-range links between vector centroids, while lower layers contain increasingly dense local connectivity graphs.

During query evaluation, search algorithms enter at the top layer, greedily traversing long-range edges to rapidly zoom into the query vector’s spatial neighborhood.

Once a local minimum is reached, the search drops to the next denser layer and repeats until reaching the bottom ground layer, returning high-recall nearest neighbors in logarithmic O(log N) time.

Traditional Apache Kafka clusters face severe operational friction when scaling storage independently of compute. Retaining historical event logs on high-performance broker NVMe drives forces teams to over-provision expensive instances and endure multi-hour partition rebalances whenever nodes are added or replaced.

Kafka Tiered Storage resolves this scaling bottleneck by separating hot tail data from cold historical log segments. Brokers retain only the active working window on local disk to serve real-time consumer groups with sub-millisecond latency. Once segments roll over, a background RemoteLogManager daemon asynchronously copies the payload and index marks to cloud object storage.

Remote metadata indexes track exact offset-to-object chunk mappings in a dedicated internal topic (__remote_log_metadata), allowing analytical consumers to issue chunked HTTP GET range requests directly against S3 without loading historical segments into broker page caches.

By offloading long-term data to cloud object storage, partition reassignment becomes a near-instantaneous metadata operation, while overall cluster storage expenses decrease by more than seventy percent.

Traditional relational databases process queries using tuple-at-a-time volcano iterator models. Passing single rows through deeply nested virtual function dispatch hierarchies incurs heavy CPU instruction cache misses and prevents CPU loop vectorization.

ClickHouse overcomes this fundamental bottleneck through vectorized block processing. Data is organized into tightly packed contiguous columnar vectors containing thousands of values per block. Analytical operators evaluate transformations in tight loops that the compiler converts directly into AVX-512 and Neon SIMD parallel vector instructions.

Disk persistence employs the MergeTree engine family, sorting rows by primary key granules and applying specialized compression codecs such as Gorilla for floats, Delta for timestamps, and DoubleDelta for sequential counters.

As background merge processes reconcile primary key parts, query planners execute sparse primary index lookups to prune unneeded physical data files before initiating vectorized disk streaming.

Envoy Proxy powers the network data plane of modern cloud infrastructure by enforcing a pure non-blocking, event-driven threading architecture. A single main coordination thread manages dynamic control plane configuration updates via xDS gRPC streams, while incoming TCP and TLS client connections are distributed across an array of worker threads using kernel SO_REUSEPORT socket options.

Each worker thread runs an independent libevent-based event loop. Once a worker accepts a client stream, parsing, filter chain execution, TLS termination, and upstream connection pooling all proceed within that single thread without taking global locks.

Thread-local storage (TLS) caches routing tables and upstream endpoint clusters, allowing workers to execute complex load-balancing decisions without synchronization overhead.

Hot restarts achieve zero dropped packets during binary upgrades by passing listening socket file descriptors across processes over Unix domain sockets with shared memory coordination.

Enterprises operating global services require multi-region active-active database architectures to minimize client round-trip latency and ensure seamless business continuity during catastrophic regional cloud outages.

In an active-active setup, write traffic is accepted simultaneously across multiple geographically separated cloud regions. Asynchronous replication streams propagate local mutations across region boundaries over low-latency dedicated backbone connections.

To handle concurrent conflicting updates to identical primary keys in separate regions, systems implement deterministic conflict resolution strategies such as Last-Write-Wins (LWW) utilizing monotonic timestamps, or domain-specific Conflict-Free Replicated Data Types (CRDTs).

Properly designed multi-region architectures partition data ownership to minimize cross-region write contention, delivering 99.999% global availability.

Building scalable distributed databases that support full ACID transactions without compromising on fault tolerance requires decoupling transactional coordination from long-term storage persistence.

FoundationDB achieves strict serializability by dividing its architecture into an in-memory Transaction Authority and a decoupled Storage System. When transactions execute, a stateless Sequencer assigns read and commit versions, while a cluster of Commit Proxies coordinates optimistic concurrency validation.

If no write conflicts exist across concurrent transactions, mutations are logged synchronously to a Paxos-backed Transaction Log (TLog) quorum before acknowledging the client.

Asynchronous background processes stream committed mutations from TLogs into distributed Storage Servers that persist data using custom SQLite B-Tree engines, allowing reads to scale independently of transaction rate.

Distributed consensus algorithms ensure that a cluster of replicated state machines agrees on an identical sequence of state transitions even when individual nodes crash or network partitions occur.

Raft decomposes the consensus problem into three independent subproblems: Leader Election, Log Replication, and Safety. Nodes operate in one of three states: Leader, Follower, or Candidate. Randomized election timers prevent split-vote scenarios during leader failure, allowing a single candidate to collect a majority quorum of RequestVote RPCs.

The elected leader accepts client commands, appends entries to its local log, and replicates them to follower nodes via AppendEntries RPCs.

To prevent write-ahead logs from growing indefinitely, Raft nodes periodically generate asynchronous state machine snapshots, discarding processed log segments and streaming snapshots to lagging followers.

In distributed payment infrastructure, network timeouts are ambiguous: a client disconnect may occur before the server processes a charge, during database persistence, or while transmitting the confirmation response.

Stripe guarantees exactly-once transaction processing through an HTTP Idempotency-Key header and atomic state machine orchestration. When an API request arrives, the gateway opens a database transaction that attempts to insert an idempotency record locking the key with a processing state and an initial timeout lease.

If a duplicate request arrives with the same key while the first is executing, the gateway detects the pending lock and polls until the original transaction commits. Once execution completes, the full HTTP response body, headers, and status code are committed directly alongside the domain model mutation into transactional storage.

Subsequent duplicate requests bypass downstream payment microservices entirely, returning the cached response instantaneously and preventing duplicate card debits.

Standard consistent hashing distributes keys evenly across an identifier ring when the keyspace is accessed uniformly. However, when specific viral keys experience extreme popularity spikes, the single node responsible for that hash slot becomes overwhelmed, leading to cascading failures.

Google researchers introduced Consistent Hashing with Bounded Loads to enforce an explicit upper bound on the maximum capacity any single cache server can accept (for example, 1 + epsilon times the average load across the cluster).

When a client routes a request to the primary node on the hash ring, the algorithm checks the node’s current load against its capacity limit.

If the primary node is operating at maximum capacity, the algorithm advances clockwise along the hash ring to the next available server, seamlessly redistributing traffic bursts without requiring cluster topology changes.

Executing schema migrations (such as adding columns, renaming fields, or splitting tables) on large relational databases using standard ALTER TABLE commands can acquire exclusive metadata table locks, stalling production traffic for hours.

The Expand-Contract (Parallel Run) pattern executes schema migrations safely across multiple incremental phases. During the Expand phase, engineers create the new schema structure alongside the old structure and update application code to perform dual-writes to both fields.

A background backfill worker migrates historical records in small transactional batches without causing lock contention or replication lag.

Once validation confirms data parity, application reads are switched to the new structure, and the legacy column or table is safely dropped during the Contract phase.

High-dimensional vector embeddings generated by machine learning models require hundreds of bytes per vector. Storing billions of uncompressed 1536-dimensional float vectors in memory exceeds the RAM capacity of standard database clusters.

Product Quantization (PQ) compresses high-dimensional vector spaces by splitting each vector into m smaller sub-vectors and quantizing each sub-vector against a trained k-means codebook centroid. This reduces a 1536-dimensional floating-point vector from 6,144 bytes down to just 64 bytes.

Inverted File (IVF) indexing partitions the vector space into Voronoi cells using k-means clustering.

During search, query evaluation compares the query vector only against the centroids of the nearest Voronoi cells, pruning over 95% of the total vector dataset before computing asymmetric distance lookups in RAM.

Traditional two-phase locking protocols force read transactions to block write transactions and write transactions to block read transactions, creating severe concurrency bottlenecks in relational database management systems.

Multi-Version Concurrency Control (MVCC) resolves this contention by ensuring that readers never block writers and writers never block readers. When a row is updated, the database does not overwrite existing disk data; instead, it appends a new tuple version containing creation (xmin) and expiration (xmax) transaction identifiers.

Read transactions are assigned a transaction snapshot, viewing only the tuple versions that were committed before the snapshot’s creation.

While Snapshot Isolation prevents dirty reads and non-repeatable reads, concurrent transactions modifying overlapping constraint boundaries can experience Write Skew anomalies unless explicit serializable locking or predicate locks are enforced.

Handling hundreds of thousands of concurrent client connections on high-performance web servers (like Nginx and Envoy) requires event-multiplexing system calls with O(1) time complexity.

The Linux epoll subsystem manages file descriptor event registrations inside kernel red-black trees and returns ready descriptors via a shared ready list, avoiding the O(N) array scans of select and poll.

In Level-Triggered (LT) mode (the default), epoll_wait notifies the application as long as a socket’s receive buffer contains data. In Edge-Triggered (ET) mode (EPOLLET), the kernel notifies the application only when a state change occurs (such as new incoming bytes).

Edge-triggered mode reduces redundant kernel wakeups, requiring worker threads to drain socket buffers completely using non-blocking loops until EAGAIN or EWOULDBLOCK is returned.

Physical wall clocks in distributed nodes experience continuous clock drift and unpredictable NTP skew, making physical timestamps unreliable for ordering causal events across independent machines.

Lamport Timestamps establish a partial causal ordering (happens-before relation ->) using a monotonically increasing integer counter attached to every message. When a node receives a message with timestamp T, it sets its internal clock to max(local_clock, T) + 1.

Vector Clocks extend this concept by maintaining an array of logical clocks representing every node in the cluster, allowing systems to detect both causal dependencies and concurrent conflicting mutations.

Hybrid Logical Clocks (HLC) combine physical NTP time with logical counters, bounding logical time to physical time intervals while preserving strict monotonicity across distributed database nodes.

Shared-nothing data warehouse architectures bind compute nodes to dedicated local storage drives. When analytical queries demand massive temporary compute power, administrators must resize the entire cluster, redistributing terabytes of data across disks in expensive rebalancing operations.

Snowflake pioneered a multi-cluster shared-data architecture that separates data storage, compute execution, and global cloud services into independent layers. Persistent storage resides entirely in cloud object storage (Amazon S3, Azure Blob, or Google Cloud Storage) formatted into micro-partitions containing column-compressed data along with rich min-max metadata headers.

Compute clusters (Virtual Warehouses) are stateless VM fleets that spin up in seconds, executing independent queries without competing for compute cycles.

Each virtual warehouse node retains a local NVMe SSD cache that buffers accessed micro-partitions using lazy read-ahead and LRU eviction, achieving local disk performance while retaining cloud elasticity.

PostgreSQL guarantees ACID durability through Write-Ahead Logging: before any table or index page modification is flushed to disk, the corresponding change must be recorded sequentially in the WAL log.

Every WAL record is identified by a 64-bit Log Sequence Number (LSN) representing the byte offset in the log stream. Data pages in the shared buffer pool store the LSN of their most recent modification in the page header.

In physical streaming replication, the primary node’s walsender process streams raw WAL byte streams over a TCP connection to replica nodes.

The replica’s walreceiver process writes the log stream to disk while startup recovery workers replay changes sequentially into the replica’s local data pages.

Distributed consensus protocols form the backbone of fault-tolerant replicated state machines, ensuring consistent agreement across cluster nodes despite arbitrary node failures and message drops.

Classic Paxos requires two network round trips (Prepare-Promise, Propose-Accept) for every single consensus decision. Multi-Paxos optimizes this by electing a stable leader, amortizing the Prepare phase and achieving single-round-trip consensus during steady-state execution.

Raft enforces a strong leader invariant where log entries flow strictly from leader to followers, simplifying state transitions and leader election proofs.

ZooKeeper Atomic Broadcast (ZAB) is tailored specifically for primary-backup systems, separating recovery phase synchronization from high-throughput FIFO atomic broadcast pipelines.

Traditional serialization formats (like JSON, XML, and standard Protocol Buffers) require explicit encoding and decoding steps: the CPU must parse byte streams and instantiate in-memory object graphs.

Zero-copy serialization systems (such as FlatBuffers and Cap’n Proto) format data in-memory such that the serialized representation on the wire or disk is identical to its in-memory layout.

Data fields are accessed through relative pointer offsets and vtables without decoding, allocating memory, or parsing strings.

Applications can mmap multi-gigabyte data files from disk or read incoming network buffers directly, accessing individual fields in nanoseconds with zero allocation overhead.

Traditional B-Trees convert logical database writes into random in-place disk page overwrites, causing severe flash drive wear and write amplification on high-throughput ingest workloads.

RocksDB eliminates random disk writes by implementing a Log-Structured Merge-Tree (LSM-Tree) architecture. Inbound writes append sequentially to an in-memory skip list (MemTable) and a Write-Ahead Log (WAL). When the MemTable reaches its size threshold, it transforms into an immutable MemTable and flushes sequentially to Level 0 (L0) as a Block-Based SSTable file.

Because L0 SSTables contain overlapping key ranges, background compaction threads continuously merge sorted runs into Level 1 and subsequent exponentially larger levels (L2 through LN).

Each level maintains disjoint key intervals, enabling point lookups to locate target SSTables using binary search over metadata indexes and Bloom filters before touching flash storage blocks.

Edge network infrastructure must route inbound L4 TCP and UDP traffic across thousands of backend application servers while tolerating dynamic node removals, software rollouts, and DDoS spikes without terminating active client TCP connections.

Cloudflare Unimog replaces dedicated hardware appliances with a software load balancer running on Linux eXpress Data Path (XDP) and DPDK. Unimog combines BGP Anycast with a distributed consistent hashing lookup algorithm based on Google Maglev, ensuring that all load balancing nodes map a given TCP 5-tuple flow to the exact same backend server.

When backend nodes enter maintenance or shift load, Unimog uses GUE (Generic UDP Encapsulation) tunnels to forward misplaced packets between edge servers in a single hop.

By inspecting TCP SYN, ACK, and FIN flags inside eBPF packet filters at the network interface card driver ring buffer, Unimog processes tens of millions of packets per second per machine with negligible CPU overhead.

Real-time browser-based graphic design presents unprecedented synchronization challenges: multiple designers can simultaneously edit complex scene trees containing nested groups, vector paths, and property hierarchies without introducing state drift or visual latency.

Figma built their multiplayer engine by compiling a high-performance C++ scene graph engine directly to WebAssembly inside the browser, coupled with a centralized state coordinator written in Rust and TypeScript on the server. Rather than full operational transformation, Figma treats the document as an immutable hierarchical tree of object nodes where each property has an independent lamport timestamp.

Client mutations apply optimistically to local WebAssembly memory arrays, rendering at 60 FPS instantly. Simultaneously, property diffs are transmitted over WebSockets to the central server.

The server orders inbound operations sequentially, broadcasts confirmed changes to peer clients, and uses last-write-wins property resolution to converge all connected clients onto identical document trees.

Hardware network load balancers present significant operational challenges: they are expensive to scale, difficult to program dynamically, and vulnerable to failover disruption when active connection state tables fail to synchronize across backup appliances.

Google Maglev is a software-defined distributed network load balancer running on commodity Linux servers. Maglev achieves line-rate 100GbE packet processing by implementing custom kernel-bypass network drivers that read raw packets directly from NIC ring buffers into user-space memory without invoking Linux kernel interrupt handlers.

To distribute traffic evenly without synchronizing connection tables across load balancer instances, Maglev introduces the Maglev Consistent Hashing algorithm.

Each backend service is mapped into a large fixed-size lookup table (typically 65,537 entries) using distinct permutation generator functions. When packets arrive, any Maglev node computes the 5-tuple hash and indexes into the table, guaranteeing identical backend server selection across the entire load balancing fleet.

Running a single monolithic Raft consensus group limits a database cluster to the write throughput of a single leader node. To scale distributed relational databases horizontally, system architects must divide the keyspace into thousands of discrete consensus shards.

CockroachDB implements Multi-Raft, partitioning the ordered keyspace into contiguous 64-megabyte chunks called Ranges. Each Range forms an independent Raft consensus group replicated across three or five nodes across multiple availability zones.

Range leases grant the leader exclusive authority to serve reads and bypass Raft round-trips for non-conflicting point lookups. When a range exceeds its size threshold through continuous writes, it splits dynamically into two child ranges without pausing query execution.

Cross-range distributed transactions execute atomically using a decentralized Two-Phase Commit protocol combined with Hybrid Logical Clocks (HLC), guaranteeing strict serializability across global clusters.