Like many terms in software engineering, the term consistency has a few different meanings. Let’s go over two of them. The first one is data consistency, which is when the data in a system is accurate, valid, and meets all desired constraints.
For example, if you have a table of users, you might have a constraint that “every user in this table must have a first name longer than two characters”. Or, if you have a table of profiles, that “every row in the profile table must have a unique user_id that refers to a valid user.” Or, for this table of sales, “all the counts in this table must sum to 100.” The data in a database is considered consistent if all desired constraints are met, and the database is said to provide data consistency if it enforces such constraints for you. For example, some databases will forbid you from modifying data in a way that breaks a constraint, like inserting a row with a first name shorter than 2 characters.
The second definition of consistency is freshness consistency, which is when reading from a database always retrieves the latest value.
In a simple case like a single database, when I perform an operation like writing a counter value, then reading the counter value, I will always get the most recent value. When you write something, then read it, the read is always fresh and picks up the value of the write. This system has freshness consistency, which seems pretty easy..
However, everything changes at scale. Large-scale databases are often composed of multiple mini databases or nodes, each handling reads and/or writes while constantly synchronizing data with each other. This is done so that each node shares a fraction of the load, so the overall system can support more traffic than a single node. When one node receives a write, it propagates that info to the other nodes so that they can update themselves to reflect the latest change. In the ideal case, I can write to one node, then it propagates the data to the other nodes, and then I can read from that node and pick up the updated value. But, that means there’s a case where I could write to one node, then read the same value from another node before the synchronization happens, and get a stale value. Because of this, the database does not have freshness consistency.
Some large-scale database technologies offer full freshness consistency, known as strong consistency, while others only offer a limited kind of freshness consistency called eventual consistency, which means that reading from a database will give the freshest value if you wait long enough before reading. There’s a tradeoff between consistency and reliability + performance, because providing strong consistency creates a huge coordination bottleneck where all databases in a system have to always be on the same page. Relaxing this makes each database more independent, so each database can handle more traffic and be more resilient when its siblings have problems. Which one is good for you depends on the kind of application that you’re building. Strong consistency is critical for many areas like payments and logistics, because inconsistency can lead to huge problems, like losing money or corrupting transactions. On the other hand, eventual consistency would be more than enough for a blog or social network, where like or status update not showing up immediately is likely not a big deal.
I’ll finish this video by saying that many terms like consistency are overloaded in the software engineering community. Therefore, whenever discussing anything using these terms, you should always share the definition you intend to use before plunging into the details. For example, “API 1 isn’t always consistent with API 2, because API 1 can sometimes return stale values.” This will avoid any confusion or disagreement from different definitions rather than the actual topic at hand.
00:00 Intro
00:14 Data Consistency
00:55 Freshness Consistency
02:11 Consistency vs Performance
03:13 Alert: Many Terms Are Overloaded
Смотрите видео Consistency, the C of ACID | Software Engineering Dictionary онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Studying With Alex 27 Октябрь 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 3,442 раз и оно понравилось 161 людям.