mitchell vitez

dark mode

blog about music art media

resume email github

The CAP Theorem Misconception

When I google “CAP Theorem” the little featured snippet starts with “CAP Theorem is a concept that a distributed database system can only have 2 of the 3: Consistency, Availability and Partition Tolerance.”1

As written this isn’t quite true (and unfortunately the article that snippet comes from never directly addresses it). This representation is something of a common misconception, and it was what I believed the CAP theorem meant for an embarrassingly long time. Wikipedia gets it right when it says the CAP theorem “states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees:…”.

We can have consistency, availability, and partition tolerance in the same system. The distinction is that we can’t be guaranteed all three at all times. When something goes wrong, we can still have two out of three, but we can’t have all three (when we try to introduce the third, we inevitably sacrifice one of the others).

This makes a slight difference in the decisions system designers have to make. Obviously, during normal operation we’d usually like all three. The really hard choice is which one to sacrifice when things go wrong.

Usually the one we sacrifice is not going to be partition tolerance. Because of the way networks work (or fail to work), partitions are essentially inevitable. Servers go down from the network, cables get severed or overrun with traffic, gamma rays hit wires disrupting transmission. Things go wrong all the time, and we almost definitely want to keep around a tolerance for that.

So the real choice, in practice, boils down from the misconceived “you must choose only two of three of consistency, availability, and partition tolerance at all times” to “you must choose either consistency or availability when failures occur”.

Choosing consistency means that users of your system get the most updated information, or they get an error. Choosing availability means users of your system get responses from your system without errors, but they might not get the most updated information.

This choice isn’t nearly as hard to make, given knowledge of the desired properties of the system!