-
Notifications
You must be signed in to change notification settings - Fork 9
CAP THEOREM
The CAP theorem, or Brewer’s theorem, is a fundamental theorem within the field of system design that states a distributed can only provide two of three properties simultaneously: consistency, availability, and partition tolerance. The theorem formalizes the tradeoff between consistency and availability when there’s a partition.
In a consistent system, all nodes see the same data simultaneously.Every read receives the most recent write or an error. If we perform a read operation on a consistent system, it should return the value of the most recent write operation.
Every request receives a (non-error) response, without the guarantee that it contains the most recent write.When availability is present in a distributed system, it means that the system remains operational all of the time.Unlike a consistent system, there’s no guarantee that the response will be the most recent write operation.
When a distributed system encounters a partition, it means that there’s a break in communication between nodes.The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes.
Imagine a distributed system consisting of two nodes:
The distributed system acts as a plain register with the value of variable X. There’s a network failure that results in a network partition between the two nodes.An end-user performs a write request, and then a read request.Let’s examine a case where a different node of the system processes each request. In our case; *It can fail at one of the requests, breaking the system’s availability *It can execute both requests, returning a stale value from the read request and breaking the system’s consistency
NoSQL databases are great for distributed networks. They allow for horizontal scaling, and they can quickly scale across multiple nodes. When deciding which NoSQL database to use, it’s important to keep the CAP theorem in mind. NoSQL databases can be classified based on the two CAP features they support: