Module 5 · Distributed systemsLesson 45 of 888 minAdvanced
Distributed systems fundamentals
Once your system runs on many machines, messages get lost, machines pause, and clocks disagree. Good designs assume all three.
Play all three tabs. In each one, ask yourself what Node A actually knows, compared to what really happened.
A distributed system is several computers working together over a network to look like one system. Every big app is one. They give you scale and survival, but they bring problems a single machine never has.
The fallacies
Engineers at Sun Microsystems listed beliefs that newcomers wrongly hold. The most important:
- The network is reliable.
- Latency is zero.
- Bandwidth is infinite.
- The network is secure.
- Nothing ever changes.
Every one of these is false, and designs that rely on them break.
Partial failure
On one machine, things either work or crash. In a distributed system, some parts fail while others keep running. A request might reach the database but its reply might not reach you. That's partial failure, and it's the heart of the difficulty.
You can't tell slow from dead
When a node doesn't answer, it might be crashed, overloaded, paused for garbage collection, or simply cut off by the network. The only tool is a timeout, and a timeout is a guess. Guess too short and you declare healthy nodes dead; too long and users wait.
Clocks lie
Each machine's clock drifts and is corrected by NTP, sometimes jumping. Two events stamped 10:00:03 and 10:00:05 on different machines may really have happened in the other order. For ordering, systems use logical clocks (counters that increase with every event), version numbers, or carefully bounded clocks like Google's TrueTime.
What this module covers
The rest of this module is the toolkit for living with these facts:
- Consistency models: what readers are allowed to see.
- Consensus and leader election: getting machines to agree.
- Locks, idempotency and delivery guarantees: doing things safely despite retries.
- Distributed transactions and sagas: keeping several services in step.
- Fault tolerance and availability: staying up while parts fail.