What if your app showed different data to different users at the same time--how confusing would that be?
Why Consistency models (strong, eventual) in HLD? - Purpose & Use Cases
Imagine you and your friends are editing a shared document by passing around a printed copy. Each person writes changes on their copy and then tries to update others by calling or texting. Sometimes, you see different versions of the document, and it's hard to know which one is the latest or correct.
This manual way is slow and confusing. You waste time checking which version is newest. Mistakes happen because changes don't appear everywhere at once. You might overwrite someone else's work or work on outdated info. It's frustrating and error-prone.
Consistency models like strong and eventual consistency help computers keep data in sync automatically. Strong consistency means everyone always sees the same latest data instantly, like a live shared screen. Eventual consistency means updates spread out over time, so data becomes the same eventually, like waiting for all friends to get the updated document.
updateLocalCopy(); notifyFriends(); waitForReplies(); resolveConflictsManually();
writeToDatabase(); // system ensures data sync based on chosen consistency model
It enables systems to handle data updates smoothly and reliably, so users get correct information without confusion or delay.
Online shopping sites use strong consistency for your payment info to avoid errors, but use eventual consistency for product reviews so they appear quickly even if not instantly synced everywhere.
Manual syncing of data is slow and error-prone.
Consistency models automate data synchronization with clear guarantees.
Choosing the right model balances speed and accuracy for better user experience.
Practice
strong consistency in distributed systems?Solution
Step 1: Understand strong consistency definition
Strong consistency means every read returns the most recent write, so all users see the same data instantly.Step 2: Compare options with definition
All users see the same data immediately after an update. matches this definition exactly, while others describe delayed or inconsistent views.Final Answer:
All users see the same data immediately after an update. -> Option AQuick Check:
Strong consistency = immediate data sync [OK]
- Confusing strong consistency with eventual consistency
- Thinking data can be permanently inconsistent
- Assuming delays are allowed in strong consistency
eventual consistency?Solution
Step 1: Recall eventual consistency meaning
Eventual consistency means updates may take time to reach all nodes, but eventually all nodes will have the same data.Step 2: Match options to definition
Data updates propagate over time and become consistent eventually. correctly states that data updates propagate over time and become consistent eventually.Final Answer:
Data updates propagate over time and become consistent eventually. -> Option DQuick Check:
Eventual consistency = delayed but eventual sync [OK]
- Assuming immediate synchronization in eventual consistency
- Confusing no synchronization with eventual consistency
- Thinking eventual consistency means permanent inconsistency
Solution
Step 1: Analyze eventual consistency update behavior
In eventual consistency, updates propagate asynchronously, so other nodes may temporarily have stale data.Step 2: Evaluate options against this behavior
Other nodes may temporarily show the old record until synchronization completes. correctly states that other nodes may show old data until synchronization finishes.Final Answer:
Other nodes may temporarily show the old record until synchronization completes. -> Option AQuick Check:
Eventual consistency = temporary stale reads [OK]
- Expecting instant update on all nodes
- Confusing update rejection with consistency model
- Assuming data deletion on other nodes
Solution
Step 1: Understand strong consistency guarantees
Strong consistency guarantees all users see the latest data immediately after update.Step 2: Analyze why outdated data appears
If users see outdated data, the system likely does not enforce strong consistency, possibly using eventual consistency instead.Final Answer:
The system is actually using eventual consistency under the hood. -> Option BQuick Check:
Outdated data means no strong consistency [OK]
- Blaming network speed for outdated data
- Assuming user refresh frequency causes inconsistency
- Confusing synchronous replication with eventual consistency
Solution
Step 1: Identify critical data requirements
Inventory stock count must be accurate to prevent overselling, requiring immediate data correctness.Step 2: Choose consistency model based on requirements
Strong consistency ensures all users see the latest stock count instantly, preventing overselling.Final Answer:
Strong consistency, because it guarantees all users see the latest stock count immediately. -> Option CQuick Check:
Critical data needs strong consistency [OK]
- Choosing eventual consistency for critical stock data
- Ignoring consistency needs for inventory
- Assuming no consistency is acceptable
Ready to prove it?
Pass the test and this pattern moves unknown
