What is "eventual consistency"? How does it compare to "transactional consistency"? When does it happen?
Consistency models describe how a system (nominally a distributed system) responds to change.
- In an eventually-consistent system, all nodes will eventually have a consistent view of the overall system state. However, there will be a period of time after the initial change in which different nodes will have different views of the state.
- In a transactionally-consistent system, the point at which all nodes have a consistent view of state is defined by applying transactional boundaries to the change. Either the transaction completes or it fails, and the thing that initiated the change will know which has happened. All nodes will see the same state both before and after the transaction completes.
Here's a real-world example: you go to your bank and deposit a check. You have initiated a change to two accounts: your account and the account of the person who wrote (issued) the check.
- In a transactionally-consistent system, the addition of funds to your account happens at the same time as the removal of funds from the issuing account. At no point will the funds appear in both accounts (or in neither).
- In an eventually-consistent system, the funds might be added to your account before they are debited from the issuing account. During some window of time, both accounts may show the added funds.
That latter scenario sounds very scary to most people. But it was exactly how the US financial system worked throughout the 20th century: you deposited a check, and that check was physically transported to the issuing bank, which then debited the money from the customer's account.
When you design your system to be eventually consistent, you need to be aware of problems that can arise from different nodes having different views of the world, and take steps to compensate. However, this compensation can lead you down a rat hole if you're not careful; it's easy to spend exorbitant amounts of effort to prepare for the case where the airliner carrying the not-yet-cleared checks crashes and burns.
On the other hand, with a transactionally-consistent system, you have to be ready for the failure of any node (or communications channel) to mean the failure of the entire system (or at least of every attempted transaction).