Distributed systems fundamentals, covering CAP, consistency, consensus & failure
The fallacies of distributed computing, CAP and PACELC, consistency models, replication and quorums, consensus (Raft), clocks and ordering, and partial failure.
Your projects are monoliths with one database, which spares you most distributed-systems pain. You still cross into distributed territory every time you call Paystack, publish to RabbitMQ, or run two instances. You need these ideas for interviews and for scaling.
The 8 fallacies of distributed computing
- The network is reliable.
- Latency is zero.
- Bandwidth is infinite.
- The network is secure.
- Topology doesn’t change.
- There is one administrator.
- Transport cost is zero.
- The network is homogeneous.
Every remote call can succeed, fail, or time out with an unknown result. The third case is why idempotency and reconciliation exist (Modules 5–6).
CAP theorem
When a network Partition happens, a distributed data store must choose between:
- Consistency: every read sees the latest write, or gets an error.
- Availability: every request gets a response, possibly stale.
CP examples are etcd, ZooKeeper and a single-leader Postgres refusing writes without its leader. AP examples are Cassandra, DynamoDB (by default) and DNS.
PACELC extends this: if Partition, choose A or C; Else, choose Latency or Consistency. Even without failures, synchronous replication (consistent) is slower than asynchronous replication (lower latency).
Consistency models (strongest to weakest)
| Model | Guarantee | Example |
|---|---|---|
| Linearizable | Behaves like one copy, in real-time order | A single Postgres primary |
| Sequential | Everyone sees the same order (not necessarily real time) | |
| Causal | Cause before effect (“reply after message”) | Chat systems |
| Read-your-writes | You see your own updates | Route a user’s reads to the primary after a write |
| Eventual | Replicas converge eventually | DNS, CDN caches, read replicas, your RabbitMQ-fed notifications |
Replication and quorums
With N replicas, W write acks and R read replicas: if W + R > N, reads see the latest write. For example, N=3, W=2, R=2 tolerates one failed node.
Consensus
How do nodes agree on a leader or a log despite failures? Raft (etcd, Consul, Kafka KRaft, CockroachDB) and Paxos. They need a majority (3 nodes tolerate 1 failure, 5 tolerate 2), which is why clusters have odd sizes.
Time and ordering
- Wall clocks drift and jump (NTP). Never order distributed events by timestamp alone.
- Lamport clocks / vector clocks order events causally.
- Fencing tokens. A lock holder that paused for GC may still think it holds the lock, so every write carries a monotonically increasing token, and storage rejects old ones. This is why Redis locks alone aren’t safe for correctness-critical work.
Partial failure patterns
- Timeouts everywhere (no infinite waits), plus retries with exponential backoff and jitter.
- Idempotency to make retries safe.
- Circuit breakers and bulkheads (resilience lesson).
- Sagas instead of distributed transactions (next lesson).