---
# System prepended metadata

title: CAP Theorem

---

# CAP Theorem

### Definition:
**Consistency**  
or **Availability**  
when dealing with **Partition Tolerance**.  

## Partition: 
A break in the network (eg, server can't reach DB, local terminal can't reach mainframe, or your local client is offline.) This is the event where you must now choose what to do with the data at the systems architecture level.


## Consistency:
All nodes share one source of truth, no new information can be written to the system when the source of truth is unreachable (no queueing of updates either).

vs

## Availability:
You can always reach one part of the system, it's more important than consistency, so new data can be written even if some information is not available.



## Examples of when to choose one over the other:

### Consistency
* **payments processing** - no debits allowed when the card processing unit is not connected to the internet
* **rentals or reservations of anything** - no reservations allowed when the availability database is not available


### Availability
* **media serving websites** - eg youtube - it's more important users can watch videos than having accurate view counts, if some part of the network is down, allow writes to the database anyway. It's ok if it takes some time (maybe a day) to get an accurate view count- until then, just guess.
* **analytics services** - it's more important to capture as many data points as possible, so queue them in some buffer for writing as soon as resources come online
* **static documents and images on CDNs** - it's more important to be able to view at least some version of these elements than to be able to be sure all of then are completely up to date with the current version, so still serve assets while waiting for asset update functions run in the background



## In-Class (let's argue)

1. The New York Stock Exchange. Which is more important, availability or consistency?
2. Eventbrite Ticket sales. Which is more important, availability or consistency?
3. A patient intake portal in the emergency room at a hospital. Which is more important, availability or consistency?
4. An ATM. Which is more important, availability or consistency?
5.  Slack. Which is more important, availability or consistency?
6.  Shein - the clothing store. Which is more important, availability or consistency?
7.  TikTok. Which is more important, availability or consistency?
8.  Fortnite. Which is more important, availability or consistency?
9.  An airline ticketing system. Which is more important, availability or consistency?
10. DuckDuckGo. Which is more important, availability or consistency?
11. A Content Delivery Network. Which is more important, availability or consistency?
12. A Non-Fungible Token Representing a Profile Photo. Which is more important, availability or consistency?
13. A database for session storage. Which is more important, availability or consistency?
14. Ebay. Which is more important, availability or consistency?
15. An auctioneer node for an ad network. Which is more important, availability or consistency?
16. An automatic IV drip (a medicine dispensing system that dispenses medicine according to a schedule or set levels within the blood). Which is more important, availability or consistency?