Horje
Strong vs. Eventual Consistency in System Design

Strong consistency and Eventual consistency are two basic principles that are being used in the creation of systems, especially distributed databases and systems.

  • Strong consistency means that all nodes in a distributed system reflect the same data at once after any update, which gives immediate consistency.
  • Eventual consistency, on the other hand, permits temporary instability of nodes, however, it promises that all nodes will eventually be updated.

These consistency models affect system performance, availability, and user experience, and therefore, choosing them or implementing them in a solution directly affects system architecture.

Strong-vs-Eventual-Consistency-

Strong vs. Eventual Consistency

What is Strong Consistency?

The strong consistency makes it possible for any read operation on a distributed data system to result in the most up-to-date data. This means that once a write operation is confirmed, every subsequent read operation will always reflect the said change, even if operations are carried out in different nodes in the system. It ensures that all copies of the data are consistent and up to date in the entire system and all replicas are also good. This consistency model is useful for application development since it gives predictable and reliable results from the data. Below are some features of strong consistency:

  • Linearizability: A process seems to happen in a series of steps, and as a result, real-time data is accessed in order and continuously updated.
  • Read-after-Write Consistency: Makes sure that if a write is accepted, the next read will include that write.
  • Single Copy Consistency: It acts as if there is only a copy of data, which avoids the copies’ inconsistencies.
  • Global Ordering of Operations: All the operations are made under a global order thus presenting a clear and ordered sequence of operations.
  • Atomicity: Consistent data updates are achieved because all parts of a write operation are made in one atomic transaction to all replicas.

What is Eventual Consistency?

Eventual consistency in system design is a consistency model that stipulates that if the nodes of a distributed system are allowed enough time wherein no new updates are performed, then, all the replicas of a materialization of a data item will eventually be the same. It does not ensure the consistency of views after writing, as strong consistency does, but has the advantage of being able to cope better in certain cases. Below are some features if eventual consistency:

  • Convergence: If there are no new updates for a sufficient amount of time, all replicas will be equal to each other.
  • High Availability: High availability of the system where reads and writes can go on even in the event of network splits.
  • Scalability: It can easily scale out to multiple nodes because it is fine with being a little inconsistent.
  • Temporary Inconsistency: This makes it possible to have temporary time differences between replicas through synchronization.
  • Asynchronous Updates: Changes are made to replicas asynchronously which in turn, eliminates latency by returning utmost results promptly.

Strong vs. Eventual Consistency in System Design

Below are the differences between strong and eventual consistency in system design:

Parameters

Strong Consistency

Eventual Consistency

Definition

Guarantees that all reads reflect the most recent write

Ensures that all replicas converge to the same value eventually

Data Freshness

Immediate consistency after a write

Temporary inconsistencies allowed, and eventual consistency

Latency

Higher latency due to synchronization

Lower latency due to asynchronous updates

Availability

Lower availability during network partitions (CAP theorem)

Higher availability even during network partitions (CAP theorem)

Partition Tolerance

Can be compromised for consistency

Prioritized alongside availability

Complexity

More complex to implement due to synchronization

Simpler implementation, fewer synchronization requirements

Use Cases

Financial transactions, inventory management, session management

Social media feeds, DNS, caching systems

Performance

Potentially slower due to synchronization overhead

Generally faster due to relaxed consistency

Consistency Guarantees

Provides strong guarantees with linearizability

Provides weak guarantees, eventual convergence

Conflict Resolution

Minimal conflicts due to immediate consistency

Requires conflict resolution mechanisms

User Experience

Predictable, always up-to-date data

Can show stale data temporarily, but eventually consistent

Scalability

More challenging to scale due to synchronization needs

Easier to scale across multiple nodes

Read/Write Operations

Synchronous, ensuring the latest data is read

Asynchronous, allowing for faster operations but with potential delays in consistency

Applications of Strong Consistency

Below are the applications of Strong Consistency:

  • Financial Systems: To protect account balances and historical records against problems like double spending or overdrafts, for instance.
  • Inventory Management: Ensuring that available stock information is up-to-date in all the systems used in a business so as not to sell out-of-stock products or conversely, sell products, that the business does not have.
  • Online Booking Systems: This can mean assuring that there are fewer surprises for guests (e.g., reservations for a flight or a hotel) and that they do not overlap in the different systems.
  • Distributed Databases: Applications that demand strict data availability everywhere the data is spread out, such as Google Spanner.
  • Session Management: Important for security parameters and the correct functioning of the services offered to the user and for their proper functioning, there is a necessity to have the correct and up-to-date user-session information.

Applications of Eventual Consistency

Below are the applications of eventual consistency:

  • Social Media Platforms: Enabling high availability and fast updates although some data (likes, comments) may be temporarily out of sync.
  • Content Delivery Networks (CDNs): Adapting content and making copies of it in different locations so that there may be inconsistency for some time to give out the content without much delay.
  • Domain Name System (DNS): High availability combined with high response time knowing that DNS record will eventually replicate.
  • Caching Systems: When fast access to the data is needed and some inconsistency after a certain time is incurable, such as web caching (for example, Memcached).
  • E-commerce Product Catalogs: Enabling quick changes at the edges, and with eventual consistency of product info acceptable over time, the use of the microservice architecture would be preferable.




Reffered: https://www.geeksforgeeks.org


System Design

Related
Hotstar's Project Hulk Hotstar's Project Hulk
Introduction to Docker for System Design Introduction to Docker for System Design
Decomposition of Microservices Architecture Decomposition of Microservices Architecture
How to Design a Microservices Architecture with Docker containers? How to Design a Microservices Architecture with Docker containers?
How Disney+ Hotstar Managed (5 Cr)+ Live Viewers During India's T20 World Cup Win[2024] How Disney+ Hotstar Managed (5 Cr)+ Live Viewers During India's T20 World Cup Win[2024]

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
15