12.1 · The 8 fallacies (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.
12.2 · CAP & PACELC
PACELC extends CAP: in the absence of partitions, you still trade Latency against Consistency. Spanner is CP/EC; Dynamo is AP/EL.
12.3 · Consistency models — strongest → weakest
| Model | Guarantee | Example |
|---|---|---|
| Linearizable | Real-time global order. | Spanner, etcd, Zookeeper. |
| Sequential | Single global order, not necessarily real-time. | Kafka per partition. |
| Causal | "Happens-before" preserved everywhere. | Bayou, Riak. |
| Read-your-writes | See your own writes. | Sticky-session systems. |
| Monotonic reads | Never see older data after newer. | Many caches. |
| Eventual | Replicas converge if writes stop. | DynamoDB default, Cassandra. |
12.4 · Time & clocks
| Clock | Notes |
|---|---|
| Physical (wall) | Drifts, skews, can jump backwards. Never trust for ordering. |
| Lamport logical | Counter incremented on send/receive; gives happens-before. |
| Vector clock | Per-node counters; can detect concurrency. |
| HLC (Hybrid Logical Clock) | Physical + logical; CockroachDB, YugabyteDB. |
| TrueTime | Spanner's bounded uncertainty via atomic clocks + GPS. |
12.5 · Replication topologies
| Topology | Trade-off |
|---|---|
| Single-leader | Easy reasoning; write bottleneck; failover needed. |
| Multi-leader | Higher write availability; conflict resolution (LWW, CRDTs). |
| Leaderless (Dynamo) | Quorum reads/writes; tunable; eventual. |
| Sync vs async | Sync = durable, slower; async = fast, possible loss on failover. |
12.6 · Consensus — Raft & Paxos
- Paxos — the original; famously hard to implement.
- Raft — designed for understandability. etcd, Consul, TiKV, RethinkDB.
- Multi-Paxos / EPaxos / Raft variants for throughput.
- ZAB — Zookeeper's atomic broadcast.
- You usually don't implement consensus; you delegate to etcd / Zookeeper / Consul.
12.7 · Sharding strategies
- Hash:
shard = hash(key) % N. Uniform; painful to reshard. - Range: contiguous keys per shard. Range scans easy; hotspots if skewed.
- Geo: per region. Low latency; cross-region queries slow.
- Consistent hashing + virtual nodes: minimal data movement on scale changes.
- Live resharding: dual-write → backfill → switch reads → drop. Days of careful work.
12.8 · Distributed transactions — and why we mostly avoid them
- 2PC / 3PC — coordinator + participants; blocking on failure.
- XA — JTA / JDBC distributed transactions; legacy enterprise.
- Modern stacks prefer sagas, the outbox pattern, idempotency, and at-least-once + dedup.
12.9 · Sagas
| Style | How |
|---|---|
| Choreography | Each service reacts to events; decoupled, harder to debug. |
| Orchestration | A coordinator (Temporal, Workflow) drives steps; easier to reason about. |
Every step has a compensating action. Booking → payment fails → cancel booking.
12.10 · CDC & event-driven
- Change Data Capture (Debezium, Postgres logical replication) emits DB row changes as events.
- Enables outbox without polling, data warehouses, cache invalidation, search indexes.
- Pairs with Kafka for replay.
12.11 · "Exactly-once" — what it really means
- Producer attaches a stable message ID.
- Broker supports idempotent producer + transactions (Kafka, Pub/Sub).
- Consumer records processed IDs to drop duplicates.
The effect happens once even when the network re-delivers many times. Networks don't actually deliver exactly once.
12.12 · Patterns to recognise
Leader election
etcd/Consul/Zookeeper; never DIY.
Quorum R/W
R + W > N for strong reads.
CRDTs
Mergeable types for offline-first / multi-leader.
Gossip
Epidemic-style membership & failure detection.
Vector clocks
Concurrency vs causality detection.
Hinted handoff
Survive transient failures of a replica.
Read repair
Fix stale replicas during reads.
Anti-entropy / Merkle trees
Background reconciliation.