System Design & Distributed Architecture Concepts
20 in-depth architectural topics from Consistent Hashing and Raft Consensus to Sharding, WALs, and Rate Limiters.
Consistent Hashing & Virtual Nodes (Dynamo Ring)
Consistent Hashing maps both servers and data keys to a 2^32-1 hash ring. When a node is added or removed, only K/N keys are migrated (where K is total keys and N is servers), preventing cluster-wide cache invalidation.
Raft Distributed Consensus & Quorum Log Replication
Raft provides fault-tolerant distributed consensus via Leader Election, Heartbeats, Log Replication, and strict Quorum Supermajority (N/2 + 1) voting, preventing split-brain states.
Distributed Rate Limiting: Token Bucket vs Sliding Window Counter
Rate limiters protect downstream services from cascading failure and abusive traffic. Sliding Window Counters combine boundary precision with O(1) memory overhead by interpolating previous window weight.
CAP Theorem & PACELC Tradeoffs in Distributed Databases
The CAP Theorem states that in the presence of a Network Partition (P), a distributed system must choose between Consistency (C) or Availability (A). PACELC extends this to normal operating conditions (Latency vs Consistency).
Database Sharding, Partition Keys & Write-Ahead Logging (WAL)
Sharding horizontally splits huge database tables across independent physical database servers using a Shard Key. Write-Ahead Logs (WAL) append sequential disk writes before mutating in-memory buffers to guarantee ACID durability.
Caching Strategies & Thundering Herd (Cache Stampede) Defense
Caching patterns (Cache-Aside, Write-Through, Write-Behind) optimize latency. Cache Stampedes occur when high-traffic keys expire, causing 10,000 concurrent database queries; resolved via Distributed Mutexes or Probabilistic Early Expiration (XFetch).
Message Queues: Kafka Partitions, Consumer Groups & DLQ
Distributed message queues (Kafka, RabbitMQ, SQS) decouple microservices. Kafka uses partitioned append-only commit logs where consumer groups maintain offset pointers, supporting millions of events/sec.
Fault Tolerance: Circuit Breaker, Bulkhead & Exponential Backoff
Microservice architectures prevent cascading death spirals using Circuit Breakers (Closed -> Open -> Half-Open), Bulkhead Thread Isolation, and Exponential Backoff with Random Jitter.
Database Replication: Read Replicas, Replication Lag & Split-Brain
Primary-Replica database topologies scale read throughput by offloading queries to asynchronous read replicas. Replication lag introduces read-your-own-writes inconsistencies, requiring sticky sessions or primary reads.
Distributed Transactions: 2-Phase Commit (2PC) vs Saga Pattern
2-Phase Commit (Prepare -> Commit) guarantees ACID consistency across microservices but suffers from blocking coordinator bottlenecks. The Saga Pattern uses asynchronous choreography or orchestration with compensating transactions.
Load Balancing: Layer-4 vs Layer-7 & Routing Algorithms
Layer-4 load balancers (IP/TCP port level, e.g. AWS NLB, IPVS) route millions of raw packets with microsecond latency. Layer-7 load balancers (HTTP/gRPC header inspection, e.g. NGINX, Envoy) route based on path, cookies, and TLS SNI.
API Gateways & Service Mesh: North-South vs East-West Traffic
API Gateways (Kong, Envoy, AWS API Gateway) manage North-South external client traffic (auth, rate limiting, TLS). Service Meshes (Istio, Linkerd) manage East-West internal microservice-to-microservice traffic with mTLS sidecars.
Event Sourcing & CQRS (Command Query Responsibility Segregation)
Event Sourcing stores state as an immutable sequence of domain events rather than current state snapshots. CQRS splits the write model (optimized for validation) from the read model (optimized for denormalized queries).
Distributed Locking: Redis Redlock vs ZooKeeper Fencing Tokens
Distributed locks coordinate exclusive access to shared resources across servers. Redlock acquires locks across N independent Redis nodes with TTLs. Fencing tokens prevent GC pause race conditions by issuing monotonically increasing sequence IDs.
Gossip Protocols & Epidemic Cluster Membership (SWIM)
Gossip protocols achieve decentralized cluster state dissemination and node failure detection in O(log N) rounds by having nodes periodically exchange heartbeat messages with random peers.
Storage Engines: LSM-Trees (Write-Heavy) vs B+ Trees (Read-Heavy)
B+ Trees optimize for point and range reads via fixed 4KB-16KB disk pages. Log-Structured Merge (LSM) Trees optimize for high write throughput by buffering writes in memory (MemTable) and flushing immutable SSTables to disk with background compaction.
Content Delivery Networks (CDNs), Anycast & Edge Computing
CDNs cache static assets and execute serverless edge compute at hundreds of Points of Presence (PoPs) worldwide. BGP Anycast routes client DNS/TCP requests to the topologically nearest physical data center.
Distributed ID Generation: Twitter Snowflake vs UUIDv4/v7
UUIDv4 (128-bit random) causes severe B+ Tree database index fragmentation. Twitter Snowflake generates 64-bit monotonically time-sortable IDs containing Timestamp, Machine ID, and Sequence counter.
Retry Storms & Full Jitter Exponential Backoff Algorithms
When a database or service experiences an outage, thousands of client retries arrive simultaneously (Retry Storm). Full Jitter randomizes retry intervals across the entire backoff window to prevent synchronized thundering herds.
Distributed Tracing & Observability (OpenTelemetry & Jaeger)
Distributed Tracing tracks requests across microservice boundaries by propagating W3C TraceContext headers (TraceID, SpanID). Spans capture timing, errors, and database queries across the distributed call graph.