A ground-up walkthrough of the concepts that matter most when building systems that run across multiple machines — from CAP theorem to consensus protocols.
Building software that runs on a single machine is hard. Building software that runs reliably across dozens of machines—while each can fail independently—is a different kind of hard.
This post is a ground-up introduction to the ideas that matter most.
A distributed system is a collection of independent computers that work together to appear as a single coherent system. The challenge is that:
Eric Brewer's CAP theorem states that a distributed system can guarantee at most two of three properties:
Important nuance: CAP is often misapplied. It only applies during network partitions. When the network is healthy, you can have both consistency and availability.
A more useful framework is PACELC:
When multiple nodes need to agree on a value (e.g., "who is the leader?"), you need a consensus protocol. The key insight is:
A consensus algorithm must be safe (never returns wrong result) and live (eventually terminates).
Paxos was the first practical consensus algorithm, but it's notoriously hard to understand. Raft was designed specifically to be understandable — and it is.
Raft decomposes consensus into:
This primer barely scratches the surface. The real complexity is in the details:
If you found this useful, I'd love to hear what you're building — reach out on Twitter.