> For the complete documentation index, see [llms.txt](https://isubasinghe.gitbook.io/isithas-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://isubasinghe.gitbook.io/isithas-wiki/computer_science/distributed_systems/cap.md).

# CAP (or more accurately PACELC) theorem

## Basic idea

Under a network partition, a distributed system must sacrifice either consistency or availability — it cannot keep both. PACELC adds: even when there's no partition, you still trade latency for consistency.

## Key formulas

* CAP: $P \Rightarrow \lnot(C \land A)$ (must drop one of C, A during a partition)
* PACELC: if Partition then choose A or C; Else choose L (latency) or C
* Quorum consistency: $R + W > N$
* PBS: probabilistic bound on staleness for $k$ replicas, $W$ acks: $P(\text{stale}) = f(k, W, \Delta t)$

CAP Theorem asserts that you can only have two of the three, Consistency, Availability or Partition tolerance. However, Partition tolerance must be in place, we do not have the choice to drop Partition tolerance.

PACELC states that in the absence of partitions, you will still have to choose between latency and consistency.

Probabilistic Bounded Staleness (PBS) helps us here, it can emperically give a probability to the staleness of our data!.

But interestingly, we dont always have to choose one of CAP, if you drop support for update operations, it is possible to have all three!!

## Resources

* <http://nathanmarz.com/blog/how-to-beat-the-cap-theorem.html>
* <https://codahale.com/you-cant-sacrifice-partition-tolerance/>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://isubasinghe.gitbook.io/isithas-wiki/computer_science/distributed_systems/cap.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
