Home›Learn›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.

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?

Part 1 of 4 · Learn · 23 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.