Home›Learn›Many servers 3: CAP as settings
Course · Stay upLesson 22 of 330 read

CAP as settings you choose

When the network splits, does my database refuse writes or lose them?

One network split, two choices, animated.

Press Play, or step with the arrows. Switch engines to see the other choice.

The CAP theorem says that during a network partition, a distributed database must choose between answering every request and keeping every answer consistent. In practice that choice is not made by the product, it is made by a setting you pick, often per query.

CAP is a setting, per write

Go deeper

No real database is "a CP database" or "an AP database". Each one gives you a setting, often per query, that decides what happens on the minority side of a split.

EngineConsistent choiceAvailable choice
PostgreSQLsynchronous_commit on with synchronous_standby_names, for example ANY 1 (s1, s2)Asynchronous replicas, the default
MySQLGroup Replication, or semi-sync with AFTER_SYNCAsynchronous replication, the default
MongoDBw: "majority" and readConcern "majority" (w: "majority" is the default since 5.0, except in replica sets with arbiters, where the default can fall back to w: 1)w: 1
CassandraQUORUM for reads and writes (R + W > RF)ONE
RedisWAIT narrows the window, but failover can still lose writesPlain replication

Even with no split, the same setting trades latency for safety: every majority write waits for a second server, across racks or regions if that is where the members are placed. That is the other half of the trade-off, often called PACELC: if Partitioned, Availability or Consistency; Else, Latency or Consistency.

Measured: Notebook 9 lost 2,217 acknowledged Redis writes on a failover to a lagging replica, and Cassandra at ALL failed as soon as one node of three stopped. See Notebook 9 and What a commit waits for.

Next · chapter 4Unique IDsIDs that never collide across servers← Chapter 2: Who is the leader
Connected

Where this shows up

The same mechanism, replication and failover, what a commit promises, elsewhere on the site: in real incidents, in measurements, and in designs.

Check yourself · 3 questions

Check yourself

Pick an answer. You will see whether it is right, and why.

1. During the split, what did client 1 get from node 1 with w: "majority"?

2. With Cassandra at ONE on both sides, two clients write different values to one row. What happens after the split heals?

3. Replication factor 3 in Cassandra. Which choice keeps reads and writes consistent?

One database decision a weekA short email each week: one real decision, the trade-off, and the command to check it. Unsubscribe in one click.

Part 1 of 4 · Learn · 56 pagesAll pages

How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.

Start 1: the basicsStart 2: ten conceptsStart 3: how a query travelsStart 4: napkin mathThe courseShort videosPostgreSQL 1: why PostgreSQLPostgreSQL 2: how it stores your dataPostgreSQL 3: what happens on every writePostgreSQL 4: high availability with PatroniPostgreSQL 5: running it as a DBREPostgreSQL 6: when it breaksPostgreSQL on Kubernetes: CloudNativePGMySQL 1: why MySQLMySQL 2: how it stores your dataMySQL 3: what happens on every writeMySQL 4: high availability with InnoDB ClusterMySQL 5: running it as a DBREMySQL 6: when it breaksMySQL failover with OrchestratorMySQL on Kubernetes: the Percona operatorsMongoDB 1: why MongoDBMongoDB 2: how it stores your dataMongoDB 3: what happens on every writeMongoDB 4: high availability with replica setsMongoDB 5: running it as a DBREMongoDB 6: when it breaksMongoDB on Kubernetes: the Percona operatorB-tree and LSM treeRedis 1: why RedisRedis 2: how it stores your dataRedis 3: high availabilityRedis 4: running it as a DBRERedis 5: when it breaksCassandra 1: why CassandraCassandra 2: how it stores your dataCassandra 3: high availabilityCassandra 4: running it as a DBRECassandra 5: when it breaksVector databases 1: why vector searchVector databases 2: how it stores your dataVector databases 3: high availabilityVector databases 4: running it as a DBREVector databases 5: when it breaksDatabase familiesEngines side by sideQueries that look fine and are notLost updates and write skewMany servers 1: keep a copy runningMany servers 2: who is the leaderMany servers 3: CAP as settingsMany servers 4: unique IDsMany servers 5: split the dataMany servers 6: across servicesMany servers 7: a thousand databasesStaff path, zero to architect