DEV Community

Cover image for High Availability - Consistency 🏋️
Avinashd
Avinashd

Posted on

High Availability - Consistency 🏋️

This post is a continuation to my previous post HighAvailability
You might have got an idea of high-availability and why is it important, we will see what else we can do to achieve high availability.

2. Consistency
The moment I heard this word, my thoughts are filled with
motivation videos saying "consistency is root of success."
So, is it same in System Design as well?
Let's see....

system design high availability

Story:
Let's say you are running a famous restaurant, and it is very successful, and you open 2 more in the same city.
You plan to run coupons to increase sales and started with only 1 of your popular restaurants. The word spread via online and people nearby other 2 restaurants started to complain that there is no coupon offer. This not only affects your customers & sales but also the reputation of your business.

There is no consistency (Weak Consistency) here. If the coupons were introduced in all the restaurants, It would have improved the sales, satisfied customers & increase in popularity (Strong Consistency)

Twist:
Maybe you don't know if the coupons can increase the sales right away and you prefer not to take risk. So initially the coupons were introduced in 1 restaurant and based on the results you started the strategy in the other 2 (Eventual Consistency)

Story to Solution in System Design:
Same story applies in case of High Availability.
In Distributed Systems, it is pretty common to have more than 1 database (more on dbs later).
With each API call, you will make some transactions in database. With increased traffic you might need more than 1 db to handle the load.

More dbs more problems 🫤

1st api call is updating user A's address in database db1
2nd api call is getting user A's details from database db2
In this case 2nd api may receive old address bcoz data in d2 is old...

Solution:
You either choose

Strong Consistency: Change in db1 should also be made in db2 at that instant. Downside of this would be decrease in performance as the api call may take more time to update all the db replicas

Weak Consistency: Allowing the inconsistency at that instant, upside is that api calls are fast which increases the performance.

Eventual Consistency: Allows the inconsistency for a while and updates the replicas eventually. Balance in both consistency & performance.

PS: This post is a part of SillySystemDesign in which each post gives very silly way to understand a complicated concept.

Meet u again with another complex topic with a silly example🫡

Top comments (0)