Topic 076 / Advanced
Distributed database fundamentals
Chapter 5.5 · Distributing Data
What and why
A distributed database combines replication (→ 72) and partitioning (→ 73) under one system, aiming to let application code keep writing mostly ordinary SQL and transactions even though the data spans many nodes. What it cannot do is dodge the underlying cost: coordinating across nodes takes time. Builds on: → 73 (partitioning and sharding).
Diagram
single node ──► + read replicas ──► + sharding ──► distributed SQL
(simple) (scales reads) (scales writes) (global transactions,
latency cost)
How it works
- Combine replication and partitioning so the application mostly keeps its familiar transactional model.
- A transaction touching data on more than one node generally needs a coordination protocol — two-phase commit (→ 138) or a consensus protocol (→ 132, taught later) — to agree on commit or abort across nodes.
- That coordination adds latency to every cross-node transaction and can reduce availability during the coordination itself.
- "Distributed SQL" systems (Spanner and CockroachDB as examples) preserve familiar SQL and transactional guarantees across nodes by paying this coordination cost on each transaction, rather than pushing the complexity into application code.
- The CAP-style trade-off (→ 128, taught later) applies at the architecture level — no distributed database escapes the consistency/availability trade-off during a partition.
Practical example
(illustrative). A cross-node transaction that must reach consensus before committing adds a fixed latency floor to every such transaction that a single-node database simply does not pay — a cost "SQL-compatible" marketing doesn't make disappear.
When to use it
- Use when: the application genuinely needs global transactional consistency across a sharded or multi-region dataset and can accept the latency cost.
- Avoid when: reaching for distributed SQL to solve a problem that sharding with an eventual-consistency-tolerant design would solve more cheaply.
- Failure scenarios: assuming cross-shard transactions are "free" because the system presents a familiar SQL interface — they still pay a coordination cost on the critical path.
- Simpler alternative: shard with application-level awareness of shard boundaries and avoid cross-shard transactions by design.
Practice
(20 min, no lab needed). Compare, on paper, the request flow and failure handling for "move money between account A and account B" implemented as (a) one transaction on a single-node database and (b) an operation that must coordinate across two shards. Name what changes operationally — latency, failure modes, and what "partial failure" even means in each case. Done when the two lists differ on at least latency, failure modes, and partial failure.
Key takeaway
A distributed database buys back a familiar transactional model across nodes, but never the coordination cost itself. Done when you can: name the latency and failure-mode cost a cross-node transaction pays that a single-node one doesn't. Used next in → 142 (multi-region data architecture); CAP theorem → 128; two-phase commit → 138.
References
Kleppmann and Riccomini, Designing Data-Intensive Applications — see
references.md.