CAP Theorem

Last updated

What is CAP Theorem?

According to CAP theorem, in a distributed system, you can only support two of the following guarantees:

  • Consistency - Every read receives the most recent write or an error
  • Availability - Every request receives a response, without guarantee that it contains the most recent version of the information
  • Partition Tolerance - The system continues to operate despite arbitrary partitioning due to network failures

Networks aren't reliable, so you'll need to support partition tolerance. You'll need to make a software tradeoff between consistency and availability.

CP - consistency and partition tolerance

Waiting for a response from the partitioned node might result in a timeout error. CP is a good choice if your business needs require atomic reads and writes.

AP - availability and partition tolerance

Responses return the most readily available version of the data available on any node, which might not be the latest. Writes might take some time to propagate when the partition is resolved.

AP is a good choice if the business needs to allow for eventual consistency or when the system needs to continue working despite external errors.

Free resources to learn CAP Theorem

More in stage 4: Availability vs Consistency

CAP Theorem: common questions

Can I learn CAP Theorem in Hindi?

This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain CAP Theorem in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.

Is this CAP Theorem tutorial for beginners?

It is lesson 7 of 147 in the free System Design roadmap, in stage 4, Availability vs Consistency. If you are new to System Design, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.

Still confused? Ask me