AdvancedTopic 80 of 104Software & Computing

CAP theorem

A distributed store can guarantee only two of consistency, availability and partition tolerance.

In depth

Brewer's CAP theorem: when a network partition occurs, a distributed system must choose between consistency and availability. PACELC adds the latency/consistency trade-off in normal operation. CP systems (e.g. HBase) reject requests; AP systems (e.g. Cassandra) serve possibly stale data.

Key points

  • Partition tolerance is mandatory
  • Eventual consistency
  • Quorums
Example

During a network split, a bank prefers consistency over availability.

Why it matters

The CAP theorem explains the trade-offs a distributed database must make when the network fails, so it guides system design choices.

Where this is used

  • Choosing a store for a shopping cart that must stay available during network splits.
  • Deciding whether a banking ledger must favour consistency over availability.
  • Explaining why a global service may return slightly old data.

Frequently asked questions

What is CAP theorem?

A distributed store can guarantee only two of consistency, availability and partition tolerance.

Why is it important to understand CAP theorem?

The CAP theorem explains the trade-offs a distributed database must make when the network fails, so it guides system design choices.

What do the letters C, A and P mean?

Consistency means every read sees the latest write, availability means every request gets a response, and partition tolerance means the system keeps working despite network splits.

Does CAP mean you must drop one property?

During a partition you must choose between consistency and availability, but when the network is healthy both can be provided.

How is CAP theorem used in practice?

Typical applications include choosing a store for a shopping cart that must stay available during network splits, deciding whether a banking ledger must favour consistency over availability and explaining why a global service may return slightly old data.

What should I learn before CAP theorem?

Study "NoSQL databases" first (topic 79 of 104 in Software & Computing). It covers the groundwork this topic builds on.

What are the key points of CAP theorem?

Partition tolerance is mandatory. Eventual consistency. Quorums.

Can you give an example of CAP theorem?

During a network split, a bank prefers consistency over availability.

What comes after CAP theorem?

The next topic is "Distributed systems", which builds directly on this one.

How difficult is CAP theorem?

It is classed as Advanced in Software & Computing (topic 80 of 104). It is an advanced topic. It assumes you are comfortable with the intermediate topics in Software & Computing.

Learning path

Want to practise? Open the interactive course for quick checks, quizzes, simulations and progress tracking.

Related topics