CAP TheoremPACELCConsistencyConsensusLinearizabilityDistributed Systems

Consistency & Consensus

Deep dive into distributed systems theory — CAP theorem, PACELC model, strong vs eventual consistency, and linearizability. Understand how systems behave under failure.

28 min read10 sections
01

The Big Picture — Why Distributed Systems Are Hard

A single database on a single machine is simple. Every read sees the latest write. There's one copy of the data, one source of truth. But a single machine can fail, can't handle millions of requests, and is in one geographic location. So we distribute — we replicate data across multiple machines in multiple locations. And that's where everything gets hard.

🏦

The Bank Branches Analogy

Imagine a bank with 3 branches in different cities. Each branch has a copy of your account balance. You deposit $500 at the Mumbai branch. At the exact same moment, your spouse withdraws $300 at the Delhi branch. Both branches have the old balance ($1,000). Mumbai updates to $1,500. Delhi updates to $700. Which one is correct? Neither — the correct balance is $1,200. This is the fundamental problem of distributed systems: when multiple copies of data exist, and updates happen at different places at the same time, how do you keep everything consistent?

The core tension: we for reliability and performance, but replication introduces the possibility of conflicting updates, stale reads, and disagreement between nodes. Consistency and consensus are the tools we use to manage this tension.

🔥 Key Insight

Distributed systems are hard not because the algorithms are complex, but because the physical world is unreliable. Networks drop packets. Machines crash. Clocks drift. Any solution must work correctly despite these failures — and that's what makes it fundamentally different from single-machine programming.

1 / 10