Welcome to the first lesson in your journey into AI Infrastructure Engineering. This initial module is designed to build a solid foundation in the principles of distributed systems, which are the bedrock upon which all large-scale AI services are built. As a senior engineer, you're already an expert at building robust software, and this module will extend that expertise into the domain of massive, resilient, and scalable systems.
In this lesson, we will start with one of the most fundamental concepts in distributed computing: the CAP theorem. We'll explore what Consistency, Availability, and Partition Tolerance mean and why you are forced to make a trade-off between them. Understanding this theorem is crucial because nearly every design decision in distributed databases, model serving clusters, and other AI infrastructure components involves navigating the trade-offs it describes. We'll look at real-world examples to make these abstract concepts concrete and set the stage for our upcoming discussions on data consistency and system architecture.
The Three Guarantees: Consistency, Availability, and Partition Tolerance
The CAP theorem, first conjectured by Eric Brewer in 2000, states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees:
- Consistency (C): Every read operation receives the most recent write or an error. In a consistent system, once a write completes, all subsequent reads from any node in the system will see that new value.
- Availability (A): Every request receives a (non-error) response, without the guarantee that it contains the most recent write. An available system remains operational for all requests, even if some nodes are down.
- Partition Tolerance (P): The system continues to operate despite an arbitrary number of messages being dropped or delayed by the network between nodes. A "network partition" is a communication break between two sets of nodes in the system.
To get a clear overview of these three concepts, let's start with a short video from IBM Technology.
This video provides a concise introduction to the CAP theorem, its origins, and a clear breakdown of each component.
Please watch the first part of the video, which covers the introduction and then the definitions of Consistency, Availability, and Partition Tolerance. The narrator also explains the core "pick two" constraint.
The Inevitable Trade-off: CP vs. AP
In any real-world distributed system that communicates over a network, partitions are a fact of life. Networks can and do fail. Therefore, Partition Tolerance (P) is not really optional. A system that isn't partition-tolerant would be a single-site system, not a distributed one.
This means the actual trade-off for any distributed system is between Consistency and Availability. When a network partition occurs, the system architect must decide:
- Do we sacrifice Consistency to maintain Availability? (This is an AP system).
- Do we sacrifice Availability to maintain Consistency? (This is a CP system).
Let's examine what these two choices mean in practice. The second half of the IBM video provides excellent, concrete examples of systems that fall into each category.
This part of the video illustrates the CP and AP trade-offs using two popular NoSQL databases, MongoDB and Cassandra.
First, watch the explanation of a CP system using MongoDB as an example, from this section. Pay close attention to how the primary-secondary architecture enforces consistency but leads to a brief period of unavailability during a failover. Next, watch the explanation of an AP system using Apache Cassandra from this timestamp. Notice how the "masterless" design ensures availability but introduces the concept of "eventual consistency," where data may be temporarily stale across nodes.
To summarize the video's examples:
- CP (Consistent & Partition-Tolerant): Systems like MongoDB, etcd, and ZooKeeper prioritize data correctness. During a partition, they might make a portion of the system read-only or entirely unavailable to prevent inconsistent data from being written or read. This is critical for systems managing configuration, service discovery, or financial transactions, where incorrect data is worse than temporary downtime.
- AP (Available & Partition-Tolerant): Systems like Cassandra, DynamoDB, and CouchDB prioritize uptime. During a partition, all nodes remain available for reads and writes. This can lead to conflicts or stale reads, which the system must resolve later. This model is well-suited for use cases where high availability is paramount and temporary inconsistency is acceptable, like a shopping cart or social media feed.
Your background with SQL databases provides a useful reference point. Traditional single-node relational databases (like PostgreSQL or MySQL) are often described as "CA" systems. They offer strong Consistency and Availability but are not inherently Partition-Tolerant. When you start distributing them across multiple nodes (e.g., through sharding or clustering), you are immediately forced to confront the CAP theorem's trade-offs.
Beyond CAP: The PACELC Framework
The CAP theorem is a powerful mental model, but it primarily describes how a system behaves during a network failure. It doesn't say anything about behavior during normal operation. This is where the PACELC framework, an extension to CAP, becomes very useful.
PACELC states:
If there is a Partition, a system must choose between Availability and Consistency. Else (during normal operation), a system must choose between Latency and Consistency.

This "Else" part is critical for system design. Even when the network is healthy, there's a trade-off:
- EC (Else, Consistency): To ensure strong consistency on every write, a system might need to wait for acknowledgment from a quorum of replicas before confirming the write. This process adds latency. Systems like Zookeeper and etcd fit here.
- EL (Else, Latency): To provide the lowest possible latency, a system might respond from the closest or fastest replica, accepting that the data may be slightly stale. This is the choice made by systems like Cassandra or DynamoDB when configured for eventual consistency.
PACELC gives us a more nuanced lens. A system isn't just "CP" or "AP"; it's often better described by its choices in both failure and normal modes (e.g., PA/EL for Cassandra, PC/EC for etcd).
Application to AI Systems
The principles of CAP and PACELC are directly applicable to the infrastructure you'll be working with. For example, consider vector databases, which are critical for similarity search in many LLM applications. An article from Forbes makes an interesting analogy, framing the trade-offs in vector databases as a "new CAP theorem."
First, let's use the article to quickly review the standard CAP definitions.
Trilemma Trade-Offs: A New CAP Theorem For Vector Databases Has Emerged
This article from Forbes Council provides a clear, high-level summary of the CAP theorem before applying the trilemma concept to vector databases.
Please read the section under the heading "In computing, the unconquerable trilemma is embodied in the well-known CAP theorem for distributed systems." Focus on the definitions and the contrasting examples of a bank versus an e-commerce retailer.
The article goes on to propose a different trilemma for vector databases: Cost-effectiveness, Accuracy, and Performance. While this uses the "CAP" acronym, it's an analogy that highlights a different set of engineering trade-offs specific to Approximate Nearest Neighbor (ANN) search:
- You can have high Accuracy and high Performance (fast, precise search), but it will require expensive hardware, sacrificing Cost-effectiveness. (Use case: real-time fraud detection).
- You can have Cost-effectiveness and high Accuracy, but you may need to sacrifice query Performance. (Use case: scientific research, like molecular search).
- You can have Cost-effectiveness and Performance, but you might sacrifice Accuracy by using a less precise search index. (Use case: product recommendations).
This shows how the foundational concept of a design trilemma, exemplified by the CAP theorem, reappears in specialized domains within AI infrastructure.
Conclusion
In this lesson, we established a cornerstone of distributed systems design. Here are the key takeaways:
- The CAP Theorem: A distributed system can only guarantee two of three properties: Consistency, Availability, and Partition Tolerance.
- The Real-World Trade-off: Since network Partition Tolerance (P) is mandatory for any distributed system, the practical choice is between Consistency (CP) and Availability (AP).
- CP vs. AP: CP systems (like etcd) sacrifice availability to ensure correctness during a partition. AP systems (like Cassandra) sacrifice immediate consistency to ensure uptime.
- PACELC Extends CAP: The PACELC framework provides a more complete picture by adding the trade-off between Latency (L) and Consistency (C) during normal operation.
This discussion of consistency has been at a high level. We've seen that AP systems rely on "eventual consistency," but what does that really mean? Are there other models between "strong" and "eventual"?
In our next lesson, we will dive deep into that exact topic. We will compare strong versus eventual consistency models, explore variations in between, and analyze how these choices impact the behavior and performance of real-world AI systems, from metadata stores to large-scale serving caches.