System Design: CAP theorem
This course covers the CAP theorem using a Rails application that runs on one PostgreSQL node. It starts with why CAP does not apply to a single node and how unique indexes provide the guarantees. It then reads the theorem's definitions and proof, corrects five common misreadings, and separates CAP availability from operational availability. Later lessons show PostgreSQL replication settings as a dial, compare real systems by conflict cost, and end with a per-operation table of partition behavior recorded in an ADR.
What you'll learn
- ✓Why a single PostgreSQL node falls outside CAP
- ✓The precise definitions of consistency, availability and partition tolerance
- ✓Five common misreadings of the theorem and their corrections
- ✓CAP availability versus operational availability, and where latency fits
- ✓PostgreSQL synchronous replication settings as a consistency dial
- ✓Choosing partition behavior per operation by conflict cost
CAP does not apply here
The CAP theorem is about distributed systems. This application isn't one, and understanding why takes you most of the way to understanding the theorem.
Read the full lesson free →Curriculum
7 lessonsCAP does not apply here
Why one PostgreSQL node cannot be partitioned, and how unique indexes provide guarantees the Ruby validations cannot.
The actual theorem
The definitions of consistency, availability and partition tolerance, the two-node proof, and why partition tolerance is not a choice.
The misreadings
Five wrong claims about CAP, from "pick two of three" to "partitions are rare", and the damage each causes.
What availability means
How CAP availability differs from operational availability, shown with a quorum cluster, and why latency is absent from the theorem.
Where real systems sit
PostgreSQL replication settings as a dial, a comparison of real systems, and choosing by what a conflict costs.
Using it without invoking it
Four design questions applied to seven operations of this application, with the results recorded in an ADR.
Putting it together: seven rows
A recap of the theorem, the application's current state, the seven-row table, and the habits for using it.