Overview

6 Distributed Systems

Distributed systems are presented as a discipline of explicit trade-offs. The chapter begins by showing how databases make promises about reliability and correctness through ACID: transactions should be all-or-nothing, preserve valid data states, avoid unsafe interference, and survive crashes once committed. It then expands from single-node reliability to distributed behavior, where CAP explains the unavoidable choice between consistency and availability during network partitions, while PACELC adds the everyday trade-off between consistency and latency even when the network is healthy. The chapter also introduces safety and liveness as a precise vocabulary for reasoning about correctness and progress.

A major focus is how distributed databases coordinate and expose data. Consensus is described as the mechanism that lets nodes agree on values, leaders, replication state, recovery decisions, and query results despite failures. Consistency models define what clients can observe across replicas, while isolation levels define how concurrent transactions interact inside a database. The chapter walks through the anomalies that weaker isolation can allow, including dirty writes, dirty reads, fuzzy reads, lost updates, read skew, write skew, and phantom reads, emphasizing that stronger isolation improves correctness but can reduce throughput. It also clarifies that “high availability” can mean different things, such as majority availability, total availability, or sticky availability, each with different implications for consistency, latency, and fault tolerance.

The second half shifts from database theory to practical system design patterns. Probabilistic increment reduces hot-row contention by trading exact counts for scalable approximations, while latency techniques focus on making systems faster, anticipating user actions, or improving perceived speed. Bloom filters show another useful trade-off: memory-efficient set membership checks with no false negatives but possible false positives. The chapter closes by distinguishing complicated systems, which can often be solved with repeatable methods, from complex systems, which require adaptation, experimentation, observability, controlled rollouts, simulation, collaboration, and sometimes machine learning. Overall, the chapter’s central lesson is that good distributed-system design depends on understanding which guarantees matter, what they cost, and when relaxing them is acceptable.

A bloom filter can return all the options except for false negatives.
Index 2 is set.
Index 0 is set.
Index 2 was already set.
Checking index 4.
Checking index 2.
Setting index 1 and 3.
Setting index 1 and 2.
Checking index 3 and 4.

Summary

  • Databases — guarantees and trade-offs
    • ACID defines the strongest reliability contract a single-node database typically offers: atomicity, consistency, isolation, and durability. Many distributed systems deliberately relax some of these properties for scalability or performance.
    • CAP shows that under network partition, a distributed system must choose between consistency and availability — both is impossible. PACELC extends this with a second trade-off: even when there's no partition, the system must choose between latency and consistency.
    • Safety properties guarantee that something bad won't happen; liveness properties guarantee that something good eventually will. Both are required in consensus algorithms, and they sometimes conflict.
    • Consensus — getting distributed nodes to agree on a value despite failures — is the foundation underlying strong consistency, leader election, and reliable replication. Paxos and Raft are the canonical algorithms.
    • Consistency models describe what clients can expect to observe across replicas. Isolation levels describe how concurrent transactions interact within a database. Both come in tiers, and stronger guarantees in either dimension cost performance.
    • The seven canonical isolation anomalies — dirty writes, dirty reads, fuzzy reads, lost updates, read skew, write skew, and phantom reads — define the isolation hierarchy. Each level prevents a specific subset; serializability prevents all of them but at significant performance cost.
    • Highly available is a vague term. The three precise availability models — majority available, totally available, and sticky available — each support different consistency trade-offs and suit different use cases.
  • System design — patterns for distributed systems
    • Probabilistic increment trades exactness for scalability: by incrementing by N with probability 1/N, we eliminate hot-row contention while keeping the count statistically accurate at scale.
    • User-perceived latency can be reduced through three strategies: making the system faster, anticipating user actions and preloading work, and giving the illusion of speed. The last is often available even when the first two are exhausted.
    • Bloom filters are memory-efficient probabilistic set-membership data structures. They guarantee no false negatives but allow false positives at a tunable rate. They're widely used in databases, CDNs, and blockchains to avoid expensive lookups for absent data.
    • Complicated systems have repeatable solutions; complex systems require adaptive ones. Working effectively in complex environments calls for reversible decisions, careful metric choice, observability, simulation, and strong team collaboration.

FAQ

What are the ACID properties in databases?

ACID stands for Atomicity, Consistency, Isolation, and Durability. Atomicity means a transaction is all-or-nothing. Consistency means the database moves from one valid state to another. Isolation means concurrent transactions should not interfere with each other. Durability means committed changes survive crashes or failures.

How is ACID consistency different from eventual consistency?

The C in ACID is about data integrity: transactions must respect rules such as constraints, valid states, and application invariants. Eventual consistency, in contrast, is a distributed systems consistency model about replica convergence: if updates stop, replicas should eventually agree.

What does the CAP theorem say?

The CAP theorem says that a distributed data store cannot fully guarantee Consistency, Availability, and Partition Tolerance at the same time. During a network partition, a system must choose between being CP, prioritizing consistency but possibly rejecting requests, or AP, prioritizing availability but possibly returning stale data.

How does PACELC extend CAP?

PACELC extends CAP by adding the latency trade-off during normal operation. It says: if there is a partition, choose between Availability and Consistency; else, when there is no partition, choose between Latency and Consistency. This matters because a system that responds correctly after 30 minutes is technically available under CAP, but not practically useful.

What is the difference between safety and liveness?

Safety means “something bad will not happen.” For example, two nodes should not both think they are the leader. Liveness means “something good will eventually happen.” For example, a leader election should eventually complete. Distributed systems often trade one against the other: safer systems may stall, while more live systems may risk incorrect states.

Why is consensus important in distributed databases?

Consensus lets multiple nodes agree on a value or decision despite failures or network partitions. It is essential for leader election, replication, recovery, distributed query execution, and strong consistency. Common consensus algorithms include Paxos and Raft.

What is the difference between a consistency model and an isolation level?

A consistency model describes what clients observe across replicas: which writes are visible, in what order, and how quickly. A strong consistency model is often called linearizability. An isolation level describes how concurrent transactions interact inside a database. The strongest isolation level is serializability, where transactions appear to run one at a time.

What anomalies do database isolation levels try to prevent?

Isolation levels are defined by which anomalies they prevent. Common anomalies include dirty writes, dirty reads, fuzzy or non-repeatable reads, lost updates, read skew, write skew, and phantom reads. Higher isolation levels prevent more anomalies but usually reduce throughput and increase latency.

What is probabilistic increment and when is it useful?

Probabilistic increment is a technique for reducing write contention on hot rows, such as a popular post’s like counter. Instead of incrementing by 1 on every request, the system increments by N only with probability 1/N. Over many requests, the count approximates the true value while greatly reducing database writes and lock contention.

What is a Bloom filter?

A Bloom filter is a space-efficient probabilistic data structure for set membership checks. It can say an element is definitely not present or may be present. It has no false negatives, but it can have false positives. Bloom filters are useful in databases, CDNs, blockchains, and security systems when memory efficiency matters and occasional false positives are acceptable.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • The Coder Cafe ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • The Coder Cafe ebook for free