Back to all questions

What is the CAP Theorem?

SeniorSystem designMicroservices
Seen on interview:1 user

This is one of the must-know questions in Senior interviews for projects involving distributed systems. It’s a theoretical question, but it shows how deeply you’ve gone into system design and microservices architecture.

CAP theorem describes a fundamental trade-off in distributed data storage systems where data is replicated across multiple nodes. It states that in the presence of a network partition, a system cannot simultaneously guarantee all three properties: Consistency, Availability, and Partition Tolerance.

  1. Consistency: every read request returns the most up-to-date value, meaning all nodes behave as a single source of truth.
  2. Availability: every request receives a response - the system remains available and doesn’t completely block.
  3. Partition tolerance: the system continues to operate even if communication between cluster components is lost or significantly delayed.

The practical point of the theorem is that in a distributed system, network failures are inevitable, so we treat partition tolerance as a given. Under these conditions, we have to choose between prioritizing Partition Tolerance + Consistency (PC) or Partition Tolerance + Availability (PA).

CP: system preserves data correctness and freshness, but it may temporarily block operations to avoid returning inconsistent data. As a result, the system may sometimes be unavailable and return an error or a timeout in order to maintain data consistency.

AP: the system continues to respond at all times, but it allows that during a partition, different nodes may return stale values. With this approach, consistency is achieved later - this is also known as Eventual Consistency.

It’s important to understand that CAP forces a trade-off only when problems occur. Under normal conditions, a system should have both high availability and acceptable data consistency.

Seen on interview?

Comments (0)

Sign in to leave a comment

No comments yet. Be the first!