HELM
Ch 10 · Distributed Systems
Chapter 10 · The hard part

Distributed Systems — the things that bite after the first 10× of traffic

Distributed systems are not "monolith but more". They're a different beast: partial failure is the default, time is unreliable, and your intuitions lie. This chapter is the survival kit.

10.1 · The 8 fallacies of distributed computing (Deutsch / Gosling)

  1. The network is reliable.
  2. Latency is zero.
  3. Bandwidth is infinite.
  4. The network is secure.
  5. Topology doesn't change.
  6. There is one administrator.
  7. Transport cost is zero.
  8. The network is homogeneous.

Every one of these will burn you. Memorise; design against.

10.2 · Time, clocks, and ordering

ConceptDefinition
Physical clockWall-clock time. Drifts, skews, can jump backwards. Never trust for ordering.
Logical clock (Lamport)Counter incremented on send/receive; gives "happens-before" order.
Vector clockOne counter per node; can detect concurrency vs causality.
HLC (Hybrid Logical Clock)Physical + logical hybrid; used in CockroachDB, YugabyteDB.
TrueTime (Spanner)Bounded uncertainty interval using atomic clocks + GPS.

10.3 · Replication topologies

TopologyTrade-off
Single-leaderEasy reasoning; writes bottleneck; failover needed.
Multi-leaderHigher write availability; conflict resolution required (LWW, CRDTs).
Leaderless (Dynamo-style)Quorum reads/writes; tunable consistency; eventual.
Sync vs async replicationSync = durable + slow + possible stalls. Async = fast + possible data loss on failover.

10.4 · Consensus — Paxos, Raft, ZAB

  • Paxos — the original; famously hard to implement correctly.
  • Raft — designed to be understandable. Used by etcd, Consul, TiKV.
  • ZAB — Zookeeper's atomic broadcast.
  • You don't usually implement consensus yourself — you delegate to a coordinator (etcd, Zookeeper, Consul) or a database that already runs it.

10.5 · Partitioning & resharding

Strategies (see Ch 3). The hard bit is moving data when N changes:

  • Consistent hashing minimises movement (O(K/N) keys move).
  • Virtual nodes smooth load across uneven physical nodes.
  • Resharding live: dual-write → backfill → switch reads → drop old shard. Days of careful work.
  • Hot keys: salt the key, split into shards-of-one, route via specialised hot-key service.

10.6 · Distributed transactions — and why to avoid them

  • 2PC — coordinator + participants; blocks on coordinator failure; rarely used in modern stacks.
  • 3PC — adds an extra phase; still has edge cases.
  • XA — JTA / JDBC distributed transactions; legacy enterprise.
  • Modern stacks prefer sagas, the outbox pattern, and idempotency — see 10.7–10.9.

10.7 · Sagas — long-running distributed transactions

StyleHow
ChoreographyEach service reacts to events; no central brain. Decoupled but harder to reason about.
OrchestrationA coordinator (Temporal, custom) drives steps. Easier to debug.

Each step has a compensating action. Booking flight → on payment failure → cancel booking.

10.8 · CDC & event-driven architecture

  • Change Data Capture (Debezium, Postgres logical replication) emits DB row changes as events.
  • Enables outbox without poll-the-DB; data warehouses; cache invalidation; search indexes.
  • Pairs with Kafka for replayable history.

10.9 · "Exactly-once" — what it really means

Networks don't deliver exactly once. The trick is effectively once:

  1. Producers attach a stable message id.
  2. Brokers support idempotent producers + transactions (Kafka, Pub/Sub).
  3. Consumers track processed ids and drop duplicates.

Result: the effect happens once, even though the network may deliver many times.

10.10 · Patterns to memorise

Leader election

Use etcd/Consul/Zookeeper; never DIY.

Quorum read/write

R + W > N for strong consistency on replicated stores.

CRDTs

Mergeable data types for offline-first / multi-leader.

Bloom filter

Compact set membership; speeds negative lookups.

HyperLogLog

Count distinct in tiny memory.

Gossip protocol

Epidemic-style membership and failure detection.

10.11 · Self-check

Q1 · "Exactly-once delivery" in a distributed broker means…
Each message is sent on the network exactly once
The effect occurs once, via dedup + idempotency
Magical guarantee from the broker
Only possible with TCP