Before going into details of Availability v/s Partition tolerance lets recap what does C,A and P stands for in CAP theorem.
- Consistency – all clients of a data store get responses to requests that ‘make sense’. For example, if Client A writes 1 then 2 to location X, Client B cannot read 2 followed by 1.In other words, all the clients will see the most recent copy of data.
- Availability – all operations on a data store eventually return successfully. Means data store is available for querying or carrying out the read/write operations.
- Partition tolerance – if the network stops delivering messages between two sets of servers, will the system continue to work correctly?
Availability v/s Partition tolerance
Let’s consider the case of a single resource and three nodes interested in that resource when a network partition occurs, according to the following diagram –
Quorum is said to be achieved when number of nodes = (N+1)/2 i.e. majority is achieved.
- In an available but not partition-tolerant system, Y would be allowed to process its request because it can reach X to obtain the lock. Z’s request would be blocked because X is unreachable.
- In a partition-tolerant but not available system, Z would be allowed to process its request because it is part of the quorum group (X’s lock will be broken). Y’s request would be blocked because it is not part of the quorum group.
- In a system that is both available and partition-tolerant, both requests would be allowed to progress. Y would return current data as possibly modified by X, while Z would return possibly stale data. Stale data could possibly mean no data in cases where there is no replica available with Quorum nodes. Consistency is obviously sacrificed in this case.