Brain Dump

CAP

Tags
sys-design
TermMeaning
ConsistencyEvery read receives the most recent write or a timeout error.
AvailabilityEvery request receives a response which may be stale.
Partition ToleranceThe system continues to operate despite arbitrary partitions.

Note: By stale I mean there's no guarantee that the response contains the most recent version of the information

Note: A partition is blockage due to network failures. Consider a pipe connecting 2 computers. A partition is a momentary disconnection of the pipe causing a failure in communication.

CAP theorem states:

You can only ever support 2 of these. To put it another way when a partition occurs you can either be consistent or available but not both. Assuming there's never a partition you can be both consistent and available, however this isn't an assumption you can make in real world systems.

Example

Consider an ATM system with two ATMs kept in sync with each other.

If a partition occurs the system can either be:

  • Consistent - I can't tell whether somethings happened on the other machine so I timeout waiting for the most up-to-date info. The other system may keep working or also wait.
  • Available - Well let's just go with my records. If you did something on the other machine, I don't care. Warn: This allows double spending.

Note: You can have degrees of availability. Say a partition occurs, we could allow transactions on one machine but not on any others. This means the system isn't completely unavailable.

Links to this note