Skip to content

Distributed Systems

These notes explain why the options in the system design hubs behave as they do. The hubs decide which pattern to use; these notes cover what the pattern assumes, what it can promise, and how to check that it keeps the promise.

    flowchart LR
  M[System models: what can fail] --> T[Time and order]
  M --> G[Guarantees: what can be promised]
  T --> C[Broadcast and consensus: agreeing]
  G --> C
  G --> A[Coordination avoidance: not agreeing]
  C --> D[Distributed computation]
  A --> D
  V[Verification] -.checks.-> C
  V -.checks.-> A
  

Notes

NoteQuestion it answers
System models and failuresWhat can go wrong, and what does an algorithm assume about it?
Time and orderHow do nodes agree on the order of events without a shared clock?
Consistency guaranteesWhat can a replicated system promise, and what does each promise cost? Includes CAP and PACELC.
Broadcast and consensusHow do nodes agree on a value or an order of operations when some may fail?
Coordination avoidanceWhen can replicas proceed without agreeing, and what do they give up?
Distributed computationHow is a computation split across machines, and how is the result kept correct when parts fail?
VerificationHow do you gain confidence that a distributed protocol or system is correct?

Mechanism notes:

NoteWhat it covers
ReplicationSingle-leader replication (synchronous, semi-synchronous, asynchronous, chain), failover, replication logs and change data capture, multi-leader topologies, leaderless quorums and anti-entropy, and choosing a strategy
PartitioningKey-range, hash, and compound partition keys, skew and hot keys, local and global secondary indexes, rebalancing, request routing, multitenancy and cells, and cross-partition operations
TransactionsACID, isolation mechanisms by anomaly, serializability, two-phase commit and XA, Spanner and Calvin, exactly-once processing, and sagas with the outbox
HashingWhy hash mod N fails, consistent hashing with virtual nodes, rendezvous and jump hashing

The reading list has courses, books, papers, and verification resources.

Reading order

  1. System models first: every later guarantee holds only under a stated fault and timing model.
  2. Time and order, then guarantees: what order and visibility a client can be promised.
  3. Consensus and coordination avoidance together: the two answers to “must the replicas agree before acting?”
  4. Distributed computation applies these to work spread over many machines.
  5. Verification last, as the way to check a protocol built from the rest.

How it connects

  • Data at scale: replication, partitioning, hashing, coordination services, and Dynamo-style stores appear as options in data at scale. The coordination section is the short version of the consensus and time notes.
  • Consistency requirements: the requirement side, deciding what each operation needs, is in consistency. It links back here for the models and theorems.
  • Across services: sagas and the transactional outbox in data across services are what replaces distributed transactions between services.
  • Messaging: consumer-group rebalancing and task scheduling in messaging rely on leases, idempotency, and at-least-once delivery.
  • Failure handling: containing failure covers timeouts and retries in callers; system models covers why a timeout cannot tell a slow node from a dead one.
  • Control planes: Kubernetes keeps its state in etcd, a consensus store; see the control plane.

Library sources

Further reading:

  • Petrov 2019, Database Internals – part II, distributed systems
  • Wattenhofer 2016, Principles of Distributed Computing – lecture notes on consensus, Byzantine agreement, and quorum systems

Explore this section

  • Broadcast from best-effort to total order, consensus and its equivalence with total-order broadcast, the FLP result and how systems escape it, quorums, Paxos, Raft, Viewstamped Replication and Zab, Byzantine consensus, and coordination …

  • What a replicated system can promise about the values clients read: consistency models and their latency cost, session guarantees, transaction isolation levels, what CAP proves, PACELC, delay sensitivity, and choosing consistency per …

  • Why hash mod N remaps almost every key, consistent hashing on a ring with virtual nodes and replication, rendezvous hashing and its weighting, a comparison of key movement and lookup cost, and how DDIA 2e uses the term consistent hashing.

  • When replicas can accept operations without agreeing first: the cost of coordination, strong eventual consistency, last-write-wins, siblings and merges, OT and CRDTs, the CALM theorem and invariant confluence, and local-first sync engines.

  • How work is split across machines: partitioning and data locality, Burns's sharding, scatter/gather and work-queue patterns, MapReduce and dataflow engines, distributed joins, stream processing, consistent checkpoints, and durable …

  • Courses, books, papers, articles, and verification resources for studying distributed systems, with the books and papers in the library.

  • How data is split across machines and found again: key-range, hash and compound partition keys, skew and hot keys, local and global secondary indexes, rebalancing, request routing, sharding for multitenancy and cells, and cross-partition …

  • How copies of the same data stay in step across machines: single-leader replication and failover, replication logs and change data capture, replication lag, multi-leader conflicts, leaderless quorums and anti-entropy, and a comparison of …

  • What can go wrong in a distributed system and what an algorithm assumes about it: partial failure, node, link and timing models, safety and liveness, failure detectors, gray failure, and how to state fault assumptions in a design.

  • How nodes order events without a shared clock: time-of-day and monotonic clocks, drift and NTP, happens-before and Lamport clocks, vector clocks and version vectors, hybrid logical clocks, causal versus total order, leases, and fencing …

  • What transactions guarantee and how they are built: ACID defined precisely, isolation anomalies and the mechanisms that prevent them, serializability, two-phase commit and its failure modes, Spanner and Calvin, exactly-once processing, and …

  • How to gain confidence that a distributed system is correct: why ordinary tests miss distributed bugs, randomized testing, fault injection and Jepsen checks, deterministic simulation testing, TLA+ model checking, proofs, and how to combine …