System Design
Cap Theorem
Consistency and Partition Tolerance
Distributed Networks
System Architecture

How a system can be CP?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

In distributed systems, managing data consistency and availability in the presence of network partitions is a critical challenge. The CAP theorem, established by Eric Brewer, provides a framework for understanding these trade-offs. It posits that a distributed system can only simultaneously guarantee two out of the following three properties: Consistency (C), Availability (A), and Partition Tolerance (P). This article explores systems characterized primarily by Consistency and Partition Tolerance (CP).

Understanding CP Systems

CP systems prioritize consistency and partition tolerance over availability. This means that in case of a network partition, these systems will maintain data consistency at the expense of fully servicing all requests.

  • Consistency in this context refers to every node in the network agreeing on the most recent state or version of the data. In formal terms, this means the system adheres to linearizability, which ensures that global operations appear instantaneous.
  • Partition Tolerance means that the system continues to operate despite arbitrary message loss or failure of part of the system. This is crucial because networks are inherently unreliable and partitions are unavoidable.

In CP systems, when a partition occurs, some parts of the system might become unavailable to ensure no conflicting data is written, thereby maintaining consistency. A famous example of CP systems is Google Spanner. It uses synchronized real-time clocks (TrueTime API) to enforce global constraints on transactions, ensuring linearizability across distributed data.

Examples of CP Systems

  1. Google Spanner: As mentioned, it uses timestamps to handle global consistency. This is unique, as it combines features typically associated with both SQL (ACID properties) and NoSQL systems (scalability and distribution).
  2. Apache HBase: Designed for big data, HBase provides consistent reads and writes. If a region server goes down, access to the data managed by that server is temporarily unavailable until recovery occurs, showing preference for consistency over availability.
  3. MongoDB (with "write concern" set for majority): In this configuration, MongoDB ensures that writes are acknowledged by a majority before they are considered successful, catering to consistency even if it affects availability.

Technical Explanation of CP Operations

Consider a distributed data store consisting of three nodes: Node A, Node B, and Node C. In normal operations, a user's request to write data goes to all three nodes, and it's not considered successful until all nodes acknowledge the write. If a network partition isolates Node C, the system can either:

  • Choose to allow operations to continue on Nodes A and B, risking that Node C will have outdated or conflicting data (prioritizing availability).
  • Stop the operation on all nodes until Node C can synchronize again, ensuring consistency (CP behavior).

Trade-offs and Considerations

While CP systems ensure data accuracy and consistency, they do so at the cost of availability. During partitions, part of the system may be inaccessible, which could lead to delays in processing user requests. This trade-off must be carefully considered based on the application's requirements for data integrity and user experience.

Summary Table

PropertyPriority in CP SystemsImpact on System Behavior
ConsistencyHighEnsures all nodes have the same data at all times.
AvailabilityLowSome parts of the system may be unavailable during partitions.
Partition ToleranceHighSystem is designed to continue operation albeit potentially at reduced capacity.

Conclusions

CP systems are ideal for applications where maintaining data correctness and consistency outweighs the need for constant availability. Financial systems, health records management, and other domains where data integrity is paramount benefit from CP configurations. However, for applications where availability is crucial — such as consumer-facing applications that require constant uptime — alternative CA or AP systems might be more appropriate.

Understanding the requirements and limitations of your specific application will guide you toward the appropriate system configuration, be it CP, CA, AP, or a hybrid approach adapting to different scenarios.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.