liveBook · Manning

CAP theorem

As explained in Grokking Software Architecture

The CAP theorem states that a distributed system cannot simultaneously guarantee consistency, availability, and partition tolerance under network partition conditions.

The CAP theorem describes a tradeoff in distributed systems: during a network partition, a system cannot guarantee both consistency and availability. Consistency means users see the same, up-to-date data; availability means requests still receive a response. The familiar “pick two of three” shorthand can mislead: when a partition occurs, the choice is between consistency and availability. section 2.9 section 7.3.5

The last ticket

If New York and London lose contact, each may try to sell the same last ticket. Waiting for London’s confirmation protects consistency but leaves the New York buyer waiting. Selling immediately keeps the service available but risks selling the ticket twice. section 2.9

The business context guides the decision. A bank transfer should favor consistent balances; a social feed may favor availability even if a new post or connection appears late. In a multi-region system, partitions cannot simply be ruled out, and even excessive latency can force a similar choice. Ask which failure is more acceptable: delayed or unavailable service, or temporarily stale data. section 2.9.1 section 7.3.5

How Grokking Software Architecture covers it

How deep it goes
Defines the guarantees and explains tradeoffs with scenarios, while stopping short of expecting readers to design distributed databases.
Examples
Uses a cross-region ticket sale, bank transfers, social feeds, and Friendster’s slow page loads to illustrate tradeoffs.
What it assumes
Requires no distributed-database design experience; asks readers to recognize the tradeoff and ask informed questions.
What you can do after
Evaluate tradeoffs by asking whether a use case can tolerate stale data in exchange for better availability.
How it connects
Connects distributed systems, consistency, availability, network partitions, latency, and the PACELC theorem.

Also explained in

Compare how 7 books explain CAP theorem →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.