What is the difference between Weak Consistency and Eventual Consistency?

Free Coding Questions Catalog
Boost your coding skills with our essential coding questions catalog. Take a step towards a better tech career now!

Weak Consistency:

  1. Basic Idea:

    • Think of weak consistency as a casual agreement among friends to meet up "sometime next week" without setting a specific time. In databases, it means that there's no guarantee when the changes made in one part of the system will be visible in another.
  2. Characteristics:

    • After a write operation, there’s no immediate assurance that subsequent read operations will see that write.
    • The system does not guarantee when the changes will be reflected across all nodes.
    • Suitable for applications where immediate consistency is not critical.
  3. Use Case:

    • An example might be a system logging non-critical data, where it's not crucial for all users to see the same data at the same time.

Eventual Consistency:

  1. Basic Idea:

    • Eventual consistency is like sending out invitations with a specific RSVP date. Everyone will eventually get the information, but not necessarily at the same time. In database terms, it means that all nodes will eventually become consistent given enough time.
  2. Characteristics:

    • Updates will propagate through the system, and eventually, all accesses will return the last updated value.
    • There’s a delay (which could vary) between a write and all nodes reflecting that write.
    • It ensures that if no new updates are made, eventually, all reads will return the same value.
  3. Use Case:

    • Common in large-scale distributed systems, like DNS and some types of NoSQL databases. For instance, a user's social media feed might show slightly different content on different devices immediately after an update, but it will eventually be the same.

Key Differences:

  • Guarantee of Consistency:

    • Weak consistency offers no guarantees about when the changes will be visible across the system.
    • Eventual consistency promises that the changes will be visible at some point in the future, assuming no new updates are made.
  • Application Suitability:

    • Weak consistency is used in scenarios where immediate consistency is not a priority, and temporary discrepancies are acceptable.
    • Eventual consistency is used in systems where it’s important that all nodes eventually agree, but immediate consistency is not required.
  • Consistency Window:

    • Weak consistency has an indefinite consistency window.
    • Eventual consistency has a finite but undefined consistency window.

In distributed systems, choosing between weak and eventual consistency models depends on the specific requirements of your application, particularly regarding how critical immediate data consistency is to your system's functionality.

TAGS
System Design Interview
System Design Fundamentals
CONTRIBUTOR
Design Gurus Team

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
What is floor division?
Why should we hire you IBM?
How do I start preparing for a coding interview?
Related Courses
Image
Grokking the Coding Interview: Patterns for Coding Questions
Image
Grokking Data Structures & Algorithms for Coding Interviews
Image
Grokking Advanced Coding Patterns for Interviews
Image
One-Stop Portal For Tech Interviews.
Copyright © 2024 Designgurus, Inc. All rights reserved.