WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Coding Interview Essentials · Scaling, Data Partitioning, Load Balancing, Caching · question 110 of 120

What are the considerations when choosing between strong and eventual consistency?

📕 Buy this interview preparation book: 120 Coding Interview Essentials questions & answers — PDF + EPUB for $5

Choosing between strong and eventual consistency in a distributed system has significant implications for your application’s performance, functionality, and user experience. Here are some considerations:

1. **Data Integrity**: Strong consistency guarantees that every read receives the most recent write. This means that all clients see the same data at the same time, eliminating ambiguity. It’s essential in systems where you need a source of truth such as financial systems and OTT (Over The Top) applications. To contrast, eventual consistency allows temporary inconsistencies and guarantees that updates will propagate through the system given some time.

Use a banking application as an example. With strong consistency, if User A transfers money to User B, both of them see the transfer immediately. But with eventual consistency, User B may not see the transferred amount instantly.

2. **Latency**: Strong consistency often leads to higher latency as it may need to reach a consensus among nodes before it can return a result. Contrarily, eventual consistency can provide low-latency responses as it can return a result without having to write to all replicas. This is especially useful in systems where the speed of accessing data is more critical than seeing the most recent data.

For example, if you were designing a comments system for a busy blog site, eventual consistency may be preferred. It may not be a disaster if some users don’t see a new comment for a short while, but it is essential that the site can quickly serve many parallel requests.

3. **Availability**: According to the CAP theorem, it’s impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees: Consistency, Availability, and Partition Tolerance. In an event of a network partition, systems that choose to be consistent will have to refuse operations, whereas systems that choose eventual consistency can stay available and handle operations. Hence, if high availability is a high priority, then eventual consistency should be preferred like in social media applications.

4. **Operational Overhead and Complexity**: Implementing strong consistency requires a more complex algorithm, which adds to developmental and operational overhead. In return, it eases reasoning about the system behavior. Eventual consistency is operationally simpler but demands application design to handle inconsistent states.

To formalize the tradeoffs:

With strong consistency,
C > L, A
(C: Consistency, L: Latency, A: Availability)

With eventual consistency,
L, A > C

In conclusion, There is no "one size fits all". The choice between strong and eventual consistency depends on the type of application, the specific use case, and the tolerable trade-offs.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Coding Interview Essentials interview — then scores it.
📞 Practice Coding Interview Essentials — free 15 min
📕 Buy this interview preparation book: 120 Coding Interview Essentials questions & answers — PDF + EPUB for $5

All 120 Coding Interview Essentials questions · All topics