Distributed Systems
How do I design a system that stays correct, available, understandable and recoverable when computation and data are spread across machines that talk over a network which loses, delays, reorders and duplicates their messages?
Your path through Distributed Systems
Start with these 5 lessons
Then follow the stages in order
Each stage builds on the ones before it. Labs and simulators sit right after the lessons they exercise. Open a stage to see its lessons. Full roadmap with goals →
Remote Calls and Partial Failure0 of 18 lessons done
- What Actually Makes a System DistributedFoundation≈ 15 min
- A Remote Call Is Not a Function CallFoundation≈ 15 min
- The Network Changes EverythingFoundation≈ 15 min
- No Shared Memory: Every Node Sees a CopyFoundation≈ 15 min
- There Is No Global ClockFoundation≈ 15 min
- Why Distribute At AllFoundation≈ 15 min
- When Not to DistributeFoundation≈ 15 min
- Where the Boundary GoesFoundation≈ 15 min
- Name the Invariant Before You Choose the ProtocolFoundation≈ 15 min
- Partial Failure: The Founding ConditionFoundation≈ 15 min
- A Timeout Tells You Nothing About Whether It HappenedFoundation≈ 10 min
- Failure Models: What You Are Allowed to AssumeFoundation≈ 15 min
- No Heartbeat Does Not Mean DeadFoundation≈ 15 min
- Crashed or Just Slow: The Distinction You Cannot MakeFoundation≈ 15 min
- Byzantine Failures, and Why You Probably Do Not Assume ThemFoundation≈ 15 min
- Fault Domains: What Fails TogetherFoundation≈ 15 min
- Correlated Failure: The Independence Assumption Is Usually FalseFoundation≈ 15 min
- Redundancy Is Not ResilienceFoundation≈ 15 min
Replication and Consistency0 of 18 lessons done
- Why Replicate: What a Second Copy Buys YouFoundation≈ 15 min
- Leader-Based Replication: Buying Order With a Single WriterFoundation≈ 15 min
- Synchronous Replication: Paying Latency for a Durability GuaranteeFoundation≈ 15 min
- Asynchronous Replication: The Loss Window You ChoseFoundation≈ 15 min
- Multi-Leader Replication: Accepting Writes in More Than One PlaceFoundation≈ 15 min
- Read-After-Write: Letting a User See Their Own ChangeFoundation≈ 15 min
- Monotonic Reads: Never Let Time Run BackwardsFoundation≈ 15 min
- Quorums: What R + W > N Does and Does Not BuyFoundation≈ 15 min
- Leaderless Replication: Every Replica Accepts WritesFoundation≈ 15 min
- Consistency Models: What "Consistent" Has To MeanFoundation≈ 15 min
- Linearizability: An Operation Is an Interval, Not a PointFoundation≈ 15 min
- Serializability vs Linearizability: Two Different PropertiesFoundation≈ 15 min
- Eventual Consistency: If Updates Stop, Replicas ConvergeFoundation≈ 15 min
- Causal Consistency: Never Show an Effect Before Its CauseFoundation≈ 15 min
- Session Guarantees: The Underrated Middle GroundFoundation≈ 15 min
- CAP: What the Theorem Actually SaysFoundation≈ 15 min
- PACELC: The Trade-off That Exists When Nothing Is BrokenFoundation≈ 15 min
- Choosing a Consistency Model: Start From the InvariantFoundation≈ 15 min
Time, Ordering and Conflict0 of 14 lessons done
- Two Timestamps Are Not an OrderingFoundation≈ 15 min
- Clock Skew: The Gap You Cannot Measure From InsideFoundation≈ 15 min
- Never Measure a Duration With the Wall ClockFoundation≈ 15 min
- Happens-Before: The Only Ordering You Actually HaveFoundation≈ 20 min
- Lamport Clocks: Consistent With Causality, Blind to ConcurrencyFoundation≈ 15 min
- Vector Clocks: Buying Concurrency Detection at O(N)Foundation≈ 15 min
- Four Orderings, Four PricesFoundation≈ 15 min
- Total Order Broadcast Is Consensus Wearing a Different HatFoundation≈ 20 min
- Two Writes, No Order, One Answer RequiredFoundation≈ 15 min
- Last Write Wins Is Data Loss You Chose by DefaultFoundation≈ 20 min
- Version Vectors: Making the Conflict VisibleFoundation≈ 20 min
- Only the Application Knows What the Merge MeansFoundation≈ 20 min
- CRDTs: Deterministic Merge, Not Correct MergeFoundation≈ 20 min
- What "Eventually Converges" Actually RequiresFoundation≈ 20 min
Consensus and Coordination0 of 18 lessons done
- What Consensus Actually SolvesFoundation≈ 15 min
- Consensus Is Not Magic: The Assumptions It Runs OnFoundation≈ 15 min
- Leader Election: Choosing One, and Knowing You Were ChosenFoundation≈ 15 min
- Terms and Epochs: Making Stale Leaders HarmlessFoundation≈ 15 min
- Split-Brain: Two Nodes, Both Certain They Are In ChargeFoundation≈ 15 min
- Fencing Tokens: Making the Stale Actor Safe, Not Just UnlikelyFoundation≈ 15 min
- Raft: Elections, Terms and Three StatesFoundation≈ 15 min
- The Raft Log: Commit Index, Divergence and ReconciliationFoundation≈ 20 min
- Paxos and the Other Protocols: What They Share and Where They DifferFoundation≈ 10 min
- Do You Actually Need Consensus?Foundation≈ 15 min
- Coordination Couples AvailabilityFoundation≈ 15 min
- Coordination Avoidance: Restructuring the Problem Instead of Paying for ItFoundation≈ 15 min
- Start From the Invariant, Not From the ArchitectureFoundation≈ 15 min
- Distributed Locks: What They Are Actually ForFoundation≈ 15 min
- Leases: Authority With an Expiry DateFoundation≈ 15 min
- The Stale Lock Holder: A Paused Process Does Not Know It Was PausedFoundation≈ 15 min
- Coordination Services: The Primitives, Not the ProductFoundation≈ 15 min
- Distributed Uniqueness: One Name, Many ShardsFoundation≈ 15 min
Messaging and Streams0 of 16 lessons done
- What a Broker Actually Buys YouIntermediate≈ 15 min
- Work Queues: One Task, One Worker, Competing ConsumersIntermediate≈ 15 min
- Publish/Subscribe: One Event, Many Independent ReadersIntermediate≈ 15 min
- Queue or Pub/Sub: Answer the Question in One SentenceIntermediate≈ 15 min
- Acknowledgement: The Two-Line Protocol That Decides Your Delivery SemanticsIntermediate≈ 15 min
- Visibility Timeout: The Message Is Hidden, Not YoursIntermediate≈ 20 min
- Poison Messages: The One That Fails Every Time, ForeverIntermediate≈ 20 min
- A Dead-Letter Queue Is a Workflow, Not a BinIntermediate≈ 20 min
- The Log Is Not a QueueIntermediate≈ 20 min
- A Topic Is Not One Log: Ordering Lives Inside a PartitionIntermediate≈ 15 min
- Consumer Groups: Queue Semantics Inside, Pub/Sub Semantics AcrossIntermediate≈ 15 min
- Rebalancing: Everyone Stops So the Partitions Can MoveIntermediate≈ 15 min
- Commit Before or After: There Is No Third OptionIntermediate≈ 15 min
- Two Clocks: When It Happened and When You Saw ItIntermediate≈ 15 min
- Late Events: The Window Already FiredIntermediate≈ 15 min
- Watermarks: A Guess About Time, Made Precise Enough to Act OnIntermediate≈ 20 min
Partitioning and Membership0 of 14 lessons done
- Why Partition: Four Ceilings, Four Different AnswersIntermediate≈ 15 min
- Hash Partitioning and the Modulo TrapIntermediate≈ 15 min
- Range Partitioning: Scans You Keep, Hotspots You InheritIntermediate≈ 20 min
- The Ring: Keeping the Mapping Stable When Membership ChangesIntermediate≈ 20 min
- Virtual Nodes: Many Positions per Machine, and Why It Is Not OptionalIntermediate≈ 20 min
- Hot Partitions: The Skew Hashing Cannot FixIntermediate≈ 20 min
- Rebalancing: A Load Spike You Schedule for YourselfIntermediate≈ 20 min
- Cross-Partition Operations: Paying for What the Split Took AwayIntermediate≈ 20 min
- Discovering Services: The Registry Is a Distributed System TooIntermediate≈ 20 min
- Cluster Membership: A Belief, Not a FactIntermediate≈ 20 min
- Gossip: Epidemic Spread Instead of Everyone Telling EveryoneIntermediate≈ 20 min
- Anti-Entropy: Repairing Divergence Nobody ReportedIntermediate≈ 20 min
- Merkle Trees: Finding the Difference Without Reading the DataIntermediate≈ 20 min
- From Alive-or-Dead to a Suspicion LevelIntermediate≈ 20 min
Workflows and Idempotency0 of 13 lessons done
- Atomicity Stops at the Process BoundaryIntermediate≈ 15 min
- Two-Phase Commit: Buying Atomicity With a PromiseIntermediate≈ 20 min
- The Blocking Window: When 2PC Stops and WaitsIntermediate≈ 20 min
- Sagas: Trading Isolation for AvailabilityIntermediate≈ 20 min
- A Refund Is Not a RollbackIntermediate≈ 25 min
- Orchestration: One Component Owns the WorkflowIntermediate≈ 20 min
- Choreography: The Workflow Nobody Wrote DownIntermediate≈ 20 min
- The Retry Is a Decision, Not a ReflexIntermediate≈ 20 min
- Idempotent Is a Property of the Whole Effect, Not the WriteIntermediate≈ 20 min
- What Counts as the Same Operation?Intermediate≈ 25 min
- Where You Put the Acknowledgement Decides EverythingIntermediate≈ 20 min
- Exactly-Once Is a Scope, Not a GuaranteeIntermediate≈ 20 min
- Deduplication: Bounded Memory Against an Unbounded StreamIntermediate≈ 20 min
Overload, Deadlines and Caching0 of 18 lessons done
- Backpressure Is a Signal That Has to Travel — and Reach Someone Who Can Slow DownAdvanced≈ 15 min
- Rejecting Work on Purpose — and Rejecting It Cheaply Enough to HelpAdvanced≈ 15 min
- Decide at the Door Whether the Capacity ExistsAdvanced≈ 15 min
- One Retry per Tier Is Not One Retry — It MultipliesAdvanced≈ 15 min
- Cap Retries as a Fraction of Traffic, Not as a Count per RequestAdvanced≈ 15 min
- Without Jitter, Every Client That Failed Together Retries TogetherAdvanced≈ 15 min
- Containment Is Decided by What Is Shared, Not by Where the Service Boundaries AreAdvanced≈ 15 min
- Bulkheads: Buying Independence by Giving Up UtilisationAdvanced≈ 15 min
- A Deadline Is Divided Across the Call Chain, Not Repeated at Every HopAdvanced≈ 15 min
- Pass the Remaining Budget Down, Not a Fresh OneAdvanced≈ 15 min
- The Caller Is Gone — Stopping Is Usually Right and Sometimes UnsafeAdvanced≈ 15 min
- Send a Second Request After p95 and Take Whichever Answers FirstAdvanced≈ 15 min
- Fan Out to 100 and the Component’s Tail Becomes the System’s MedianAdvanced≈ 15 min
- A Cache Across Machines Is a Replica With No Replication ProtocolAdvanced≈ 15 min
- Invalidation Is a Messaging Problem, Which Is Why Cache Bugs Are HardAdvanced≈ 15 min
- One Key Expires and Five Hundred Instances Miss at the Same MillisecondAdvanced≈ 15 min
- You Cannot Enumerate the Caches, So TTL Is the Bound and Invalidation Is the OptimisationAdvanced≈ 15 min
- Sharding Does Not Help a Single KeyAdvanced≈ 15 min
Storage, Compute and Geography0 of 19 lessons done
- A Distributed Database Is a Stack, Not a BoxAdvanced≈ 15 min
- Distributed File Systems: Chunks, a Metadata Service, and Where the Copies GoAdvanced≈ 20 min
- Object Storage: A Flat Namespace With a Hash Behind ItAdvanced≈ 20 min
- Acknowledged, Durable, Replicated: Three Different ThingsAdvanced≈ 20 min
- Recovered State Is a Checkpoint Plus the Log After ItAdvanced≈ 15 min
- A Consistent Cut, Without Stopping the WorldAdvanced≈ 20 min
- Splitting a Computation Across MachinesAdvanced≈ 15 min
- MapReduce: The Model That Made the Trade-offs VisibleAdvanced≈ 15 min
- The Shuffle Is the JobAdvanced≈ 20 min
- Move the Computation to the DataAdvanced≈ 20 min
- Who Runs What, and What Happens When a Worker Goes QuietAdvanced≈ 20 min
- One Slow Task Sets the Pace for EverythingAdvanced≈ 20 min
- A Region Boundary Is a Consistency DecisionAdvanced≈ 15 min
- The One Number You Cannot OptimiseAdvanced≈ 20 min
- Three Ways to Accept a Write in More Than One PlaceAdvanced≈ 20 min
- Active-Passive: Simple to Reason About, Rarely TestedAdvanced≈ 20 min
- Active-Active: Every Conflict Scenario Becomes RealAdvanced≈ 20 min
- EU and US Are Partitioned. Can Both Keep Accepting Writes?Advanced≈ 20 min
- When the Data Is Not Allowed to LeaveAdvanced≈ 20 min
Operating Distributed Systems0 of 22 lessons done
- Detect, Contain, Recover, Reconcile, VerifyAdvanced≈ 15 min
- Graceful Degradation: Which Dependency Is Actually CriticalAdvanced≈ 15 min
- The Steady-State Hypothesis and the Abort ConditionAdvanced≈ 20 min
- Cascading Failure: When the Response to Failure Causes More FailureAdvanced≈ 20 min
- Dependency Blast Radius: What Dies If This Node DiesAdvanced≈ 15 min
- Chaos Engineering Is Not Randomly Breaking ProductionAdvanced≈ 15 min
- Fault Injection: The Catalogue, and Which Faults Are HardAdvanced≈ 20 min
- Distributed Debugging: The Question LadderAdvanced≈ 15 min
- Three Nodes, Three Logs, and You Cannot Sort by TimestampAdvanced≈ 20 min
- Microservices Are a Distribution Decision, Not a Scaling TechniqueAdvanced≈ 15 min
- The Distributed Monolith: All of the Cost, None of the AutonomyAdvanced≈ 15 min
- Four Questions That Test a Proposed BoundaryAdvanced≈ 20 min
- The Shared Database: An Honest Trade, Not a ProhibitionAdvanced≈ 20 min
- Exactly One Component Owns Each Piece of StateAdvanced≈ 15 min
- Source of Truth: The Question Every Inconsistency Incident Is Really AskingAdvanced≈ 15 min
- Materialized Views: A Read Model That LagsAdvanced≈ 20 min
- Reconciliation Is a Component, Not a Cleanup ScriptAdvanced≈ 20 min
- An Agent System Is a Distributed SystemAdvanced≈ 20 min
- The Model Retries Because It Cannot See the ResultAdvanced≈ 20 min
- Agents Do Not Negotiate. Processes Contend for State.Advanced≈ 20 min
- Resuming a Workflow That Died Halfway ThroughAdvanced≈ 20 min
- The Failures That Produce No ErrorsAdvanced≈ 25 min
Everything here is a consequence of two sentences
A local call returns or throws. A remote call has a third outcome — no answer — and the syntax hides it. Every retry, every idempotency key, every saga and every timeout budget in this domain exists because of that third outcome.
The request may never have arrived, arrived and been dropped, executed and had its reply lost, or still be running. Three of those four mean the work did happen. Code that treats a timeout as a failure is wrong more often than it is right.
The rest of the domain is the work of getting back, in protocol and at a price, the four things a machine boundary takes away: shared memory, one clock, instant communication, and any reliable way to know who is alive.
Start from what you are actually seeing
Nobody arrives asking which consistency model they want. They arrive with a duplicate charge, a queue that will not drain, or two nodes that both think they are the leader. Pick the symptom and the answer is what to think about — never a product to install.
The outcome is unknown, not failed
Three of the five realities behind a timeout involve the work having completed. Treating it as failure is wrong more often than it is right.
- 1A Timeout Tells You Nothing About Whether It HappenedService A calls Service B and the call times out. The single most common mistake in distributed systems is treating that as "it failed". It is not a failure result — it is the absence of a result, and five different realities produce it.
- 2Partial Failure: The Founding ConditionA single machine fails all at once — the process is running or it is not. A distributed system fails in pieces, at different times, and each surviving piece has a different and incomplete picture of which pieces those were. Every other idea in this domain is a response to that.
- 3The Retry Is a Decision, Not a ReflexA timeout leaves the outcome unknown. Retrying and not retrying are both guesses, with different costs — and the moment you retry, the receiver has no way to tell your second attempt from a genuine second request unless you gave it one before the first attempt left.
The chain every lesson answers
Two of these fields are required and are what make this a domain rather than a pattern catalogue: the guarantee — the property claimed and its scope — and what a node can actually know, as opposed to what it is inferring.
Tools
Every module, every lesson, each one naming the guarantee it claims and how it fails.
Answer questions about your workload and land on a design — with what it actually promises, and explicitly what it does not.
A symptom, then what each party observed and concluded. Commit to a cause before the reveal; the reasonable reading is usually the wrong one.
Evidence you have to interpret, with the revealing item withheld until you commit.
What a strong answer contains, the green flags, the red flags, and a concrete failure to reason about.
Every simulator in the domain in one place: spacetime diagrams, quorum overlap, replicated logs, linearizability checks, partition drills.
Load a system until it breaks and watch why: real queueing, measured percentiles, chaos controls. A third-party discrete-event simulator, vendored and credited.
Where to start and what each stage needs first, from the machine boundary to running the system in production.
Symptom on the left, what to think about on the right — never symptom to product.
Learning modules
What a machine boundary actually changes
Partial failure, ambiguity, and what a node can know
Clocks lie; causality is what you can trust
Copies buy availability and cost you agreement
Naming the guarantee precisely enough to build on
Two writes, no order, one answer required
Agreement under failure, and its price
Atomicity across services you do not control
Retries are unavoidable; duplicates are the tax
Brokers, queues, logs and what each guarantees
Time is two different things at once
Splitting data without splitting correctness
When nodes must agree before acting — and when they need not
Who is in the cluster, and who is merely quiet
Bounded behaviour when demand exceeds capacity
Time budgets across a call graph
Copies of copies, and when they go stale
Layers beneath a distributed database
Moving work to data, and paying for the shuffle
Physics sets a floor on coordination
Detect, contain, recover, reconcile, verify
Where to cut, and what the cut costs
Agent workflows are distributed systems
What this domain is not
Not a glossary of CAP, Raft, Kafka and microservices, and not a product tour.
Architecture tells you which pattern to pick; Database tells you how replication works; Networking tells you how machines communicate. This domain tells you what the pattern actually guarantees, what the replication cost you in agreement, and what unreliable communication does to correctness. Where a lesson touches a mechanism that another domain owns — a saga, a consistent hash ring, a Kafka partition, an idempotency key — it links that lesson and moves straight on to the reasoning. Nothing here asks you to memorize a product; every lesson asks what guarantee is claimed, what each node can know, what fails, where agreement is unavoidable, and what it costs.
It is a system whose correctness depends on a component that fails independently and whose state you can only learn about through messages that may be lost, delayed, reordered or duplicated. One app plus one managed database already qualifies. Forty services that share a database and die as a unit are distributed in the worst way and coordinated in none of the good ways.
A guarantee names a property and its scope: *linearizable for single-key operations*, *read-your-writes for the session that wrote*, *at-least-once within a partition*. Strip the scope and you have marketing. Every lesson here is required to state one, which is why none of them can end at "it is consistent".
In an asynchronous network a crashed node and a slow node produce byte-for-byte identical evidence at every observer: silence. You do not detect failure, you decide to treat a node as failed, get agreement on the decision, and fence the old one so being wrong is survivable rather than catastrophic.
Concurrency has shared memory and shared fate: when the process dies, both threads die, and neither is left holding half a decision. Take away shared memory, a common clock, and any reliable oracle for "is the other party alive", and the reasoning changes shape rather than scale.
Every lesson carries required coordination, failureModes and alternatives fields. A design that cannot name what an operator sees when it breaks, or the simpler thing to try first, is a default being taught rather than a decision being made — and in this domain the price is paid in availability, not only in latency.
Simulated clusters, quorum arguments and consensus claims are labelled protocol, assumption, typical or simplified. "R + W > N means you read your write" is true by arithmetic and false under a sloppy quorum; the label is where that difference lives.