Distributed Databases
A distributed database looks like one system but stores data across many sites. Transparency hides the network; CAP theory explains why it cannot hide everything.
In plain English
Many libraries, one catalog. You do not care which building holds the book.
The one idea
A distributed database spreads data and processing across sites while presenting one logical database to the application.
Locality, scale, and availability are real, but coordination is not free. A network partition forces a choice between consistency and availability.
By the end
- 01Define a distributed database.
- 02Explain location, fragmentation, and replication transparency.
- 03State the CAP trade-off.
- 04Know the challenges of distributed transactions.
Transparency
Location transparency means users do not need to know which site stores a row. Fragmentation transparency means they do not need to know how a table is split. Replication transparency means they do not need to know how many copies exist. The DBMS rewrites queries and coordinates updates across sites.
CAP theorem
A distributed system cannot guarantee consistency, availability, and partition tolerance all at once. When the network partitions, a system must choose between rejecting requests to stay consistent or serving stale data to stay available. Real systems choose different points on that spectrum.
C + A: no partition tolerance
C + P: reject requests during a partition
A + P: serve potentially stale dataDistributed transactions
A transaction may touch multiple sites. Two-phase commit coordinates the sites: a prepare phase and a commit phase. If a participant fails, the coordinator must decide whether to commit or abort. Distributed transactions are powerful but expensive and fragile under network failures.
Orders in two regions
Customers in Europe and Asia write orders. Each region has its own database site.
Fragment orders by region.
A European order is written locally; the common query still sees one Orders relation.
A global report joins European and Asian orders.
The optimizer must move data or ship partial aggregates across the network.
The link between regions fails.
Each site must decide whether to accept local writes or preserve a single consistent view.
ConclusionDistribution is a physical design choice with logical consequences. Transparency hides the location, not the trade-off.
The trade-off
No free correctness.
Gain
Local access, horizontal scale, and survival of a site failure.
Cost
Network latency, distributed commits, partial failure, and much harder debugging.
Verdict
Distribute only when locality, scale, or availability justifies the coordination cost.
Recap
What to keep.
Takeaways
- +A distributed database spreads data across sites but presents one logical system.
- +Transparency hides location, fragmentation, and replication.
- +CAP forces a trade-off during network partitions.
- +Two-phase commit coordinates distributed transactions.
- +Distribution adds latency and failure modes.
Traps
- !Assuming a distributed database is always more available.
- !Forgetting that transparency is a logical illusion, not a physical one.
- !Ignoring the cost of two-phase commit.
Focus
- →Explain the three transparencies.
- →State the CAP trade-off in one sentence.
- →Trace two-phase commit at a high level.
Check yourself
Before you turn the page.
What does location transparency hide?
What does CAP say a system must trade during a partition?