Senior
Tell me about the CAP theorem.
sobes.tech AI
Answer from AI
The CAP theorem states that a distributed system cannot simultaneously guarantee all three properties:
- Consistency — all nodes see the same data at the same time.
- Availability — every request receives a response (successful or with an error) without long waiting.
- Partition tolerance — the system continues to operate despite network splits between nodes.
Under network partition conditions, the system must choose between consistency and availability:
- If consistency is chosen, some parts of the system may become unavailable to prevent data inconsistency.
- If availability is chosen, data may temporarily become inconsistent.
Example: In a distributed database, when the connection between nodes is lost, either some nodes stop responding (maintaining consistency), or they respond with outdated data (maintaining availability).
The CAP theorem helps in designing systems by understanding the trade-offs among these three properties.