10.1 · The 8 fallacies of distributed computing (Deutsch / Gosling)
- The network is reliable.
- Latency is zero.
- Bandwidth is infinite.
- The network is secure.
- Topology doesn't change.
- There is one administrator.
- Transport cost is zero.
- The network is homogeneous.
Every one of these will burn you. Memorise; design against.
10.2 · Time, clocks, and ordering
| Concept | Definition |
|---|---|
| Physical clock | Wall-clock time. Drifts, skews, can jump backwards. Never trust for ordering. |
| Logical clock (Lamport) | Counter incremented on send/receive; gives "happens-before" order. |
| Vector clock | One 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
| Topology | Trade-off |
|---|---|
| Single-leader | Easy reasoning; writes bottleneck; failover needed. |
| Multi-leader | Higher write availability; conflict resolution required (LWW, CRDTs). |
| Leaderless (Dynamo-style) | Quorum reads/writes; tunable consistency; eventual. |
| Sync vs async replication | Sync = 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
| Style | How |
|---|---|
| Choreography | Each service reacts to events; no central brain. Decoupled but harder to reason about. |
| Orchestration | A 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:
- Producers attach a stable message id.
- Brokers support idempotent producers + transactions (Kafka, Pub/Sub).
- 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.