Course map

Part 08

Distributed Systems

Reason precisely about failures, consistency and coordination across machines.

Prerequisites Part 7.
Part context

Cross-references: replication and replication lag → 72; consistent hashing → 74; optimistic concurrency → 71.

Reading track

8.1 The Nature of Distribution

Chapter outcomes and context

Topics covered: 125 Distributed systems fundamentals (Core) · 126 Partial failures and network partitions (Core) · 127 Failure detection: heartbeats and gossip (Advanced)

Learning outcomes

  • State what makes distribution hard: partial failure (some nodes and links fail while others work) and unbounded delay (slow is indistinguishable from dead); timeouts are guesses, not facts.
  • Treat network partitions as a fact of networks, not an edge case; use the fallacies of distributed computing as a design checklist.
  • (Advanced) Detect failure without certainty: heartbeats with timeouts (false positives under load) and gossip protocols (epidemic dissemination of membership and state — scalable, eventually consistent; used in the Capstone).
125Distributed systems fundamentalsCore126Partial failures and network partitionsCore127Failure detection: heartbeats and gossipAdvanced

8.2 Consistency Theory

Chapter outcomes and context

Topics covered: 128 CAP theorem and PACELC (Core) · 129 Consistency models: linearizability, sequential, causal, eventual; read-your-writes, monotonic reads, consistent prefix, stale reads (Core) · 130 Quorums (Advanced) · 131 Anti-entropy: Merkle trees, read repair, hinted handoff (Specialist)

Learning outcomes

  • State CAP correctly: during a partition, choose availability or consistency (linearizability). PACELC adds the everyday trade-off: else, latency vs. consistency.
  • Place the consistency models — linearizability → sequential → causal → eventual — and the session guarantees that make eventual consistency livable: read-your-writes, monotonic reads, consistent prefix; name where stale reads are acceptable and for how long. Choose per data item, not per system: account balance ≠ like count.
  • (Advanced) Apply quorums: with N replicas, W + R > N gives read–write overlap; sloppy quorums trade that overlap for availability.
  • (Specialist) Repair divergent replicas: read repair (fix on read), hinted handoff (hold writes for a down node), Merkle trees (find differing key ranges efficiently for background sync) — the Dynamo-style toolkit, exercised in the Capstone.
128CAP theorem and PACELCCore129Consistency models: linearizability, sequential, causal, eventual; read-your-writes, monotonic reads, consistent prefix, stale readsCore130QuorumsAdvanced131Anti-entropy: Merkle trees, read repair, hinted handoffSpecialist

8.3 Consensus and Coordination

Chapter outcomes and context

Topics covered: 132 Consensus: Raft and Paxos (Advanced) · 133 Leader election (Advanced) · 136 Coordination services: ZooKeeper and etcd as examples (Advanced)

Learning outcomes (all Advanced)

  • Explain why consensus is needed: nodes must agree on one value, leader, or log despite failures.
  • Walk through Raft in working detail — leader election, log replication, terms, commit rules — and know Paxos at concept level. Context: consensus requires timing assumptions (the FLP result, at awareness level).
  • Apply leader election as the canonical consensus use, with fencing tokens against zombie leaders (Project 11).
  • Use coordination services — small, strongly consistent stores for configuration, locks, membership, and elections — rather than reimplementing consensus.
132Consensus: Raft and PaxosAdvanced133Leader electionAdvanced136Coordination services (ZooKeeper and etcd as examples)Advanced

8.4 Time, Ordering, and Conflicts

Chapter outcomes and context

Topics covered: 134 Logical clocks and version vectors: concurrent updates, conflict resolution (Advanced) · 135 Clock synchronization and clock drift (Advanced)

Learning outcomes (all Advanced)

  • Never order events across machines by wall clock: physical clocks drift; NTP bounds the error but does not eliminate it.
  • Order with Lamport clocks (happens-before, total order without detecting concurrency) and detect concurrent updates with version vectors; resolve conflicts by policy — last-write-wins (data loss risk), surfacing siblings, or domain-specific merge (conflict copies in Project 17; sibling values in the Capstone).
  • Know the industrial refinements at awareness level: hybrid logical clocks; TrueTime (Spanner) buying external consistency with bounded clock uncertainty.
134Logical clocks and version vectors: concurrent updates, conflict resolutionAdvanced135Clock synchronization and clock driftAdvanced

8.5 Locks, Transactions, and Sagas

Chapter outcomes and context

Topics covered: 137 Distributed locks and leases (Advanced) · 138 Distributed transactions and two-phase commit (Advanced) · 139 Saga pattern and compensating transactions (Advanced)

Learning outcomes (all Advanced)

  • Treat every distributed lock as a lease (it expires); explain why lock + GC pause + expiry yields two holders, and why fencing tokens fix it. Know Redis- and etcd-based locking and their limits. Simpler alternative: a database row lock when all contenders share one database. (Leases drive reservation expiry in Projects 7, 14, 16 and duplicate-run prevention in Project 11.)
  • Explain two-phase commit: prepare then commit, with the coordinator as a blocking single point of failure — why it is avoided across services.
  • Apply the Saga pattern (primary home): a sequence of local transactions, each with a compensating action for rollback; choreography (event-driven, decentralized) vs. orchestration (a coordinator → 122). Sagas are not ACID: intermediate states are visible, and compensations are business operations (refund, release, cancel) designed with the forward path. When not to use: everything fits one database — use a local transaction (→ 70). Applied in Projects 8 and 15.
137Distributed locks and leasesAdvanced138Distributed transactions and two-phase commitAdvanced139Saga pattern and compensating transactionsAdvanced

8.6 State at Scale

Chapter outcomes and context

Topics covered: 140 Distributed state management (Advanced) · 141 Probabilistic data structures: Bloom filter, HyperLogLog (Advanced) · 142 Multi-region data architecture (Advanced)

Learning outcomes (all Advanced)

  • Place state deliberately: partitioned (→ 73), replicated (→ 72), or derived (caches, indexes, read models) — and name how each copy is kept correct (→ 81).
  • Use probabilistic structures where exactness is a bad trade: Bloom filters (definite no / probable yes — LSM read paths, seen-URL checks) and HyperLogLog (cardinality estimation — e.g., counting unique visitors) with stated error bounds.
  • Design multi-region data: active–passive vs. active–active (conflict handling or region-pinned data), data residency, and the speed of light as a hard bound on cross-region synchronous writes. Boundary: this topic is where data lives and how it stays consistent; steady-state routing mechanics are topic 94; failover orchestration is topic 196.
140Distributed state managementAdvanced141Probabilistic data structures: Bloom filter, HyperLogLogAdvanced142Multi-region data architectureAdvanced

Done when you can

  • Explain CAP/PACELC with a concrete example and pick consistency per data item.
  • Whiteboard a Raft election and a log replication round.
  • Detect and resolve a concurrent update with version vectors.
  • Design a cross-service transaction as a saga with correct compensations.
  • Choose quorum parameters (N, W, R) for a stated durability and latency goal.
Open revision sheet and self-quiz

Projects after Part 8

Search the guide