DEV Community

Tomer Ben David
Tomer Ben David

Posted on

Consistency isn’t consistent at all!

Introduction

In the intricate realm of databases, the term "consistency" wears many hats, leaving developers puzzled. Fear not, fellow coders! Let's unravel the enigma of consistency in databases.

The Dual Nature of Consistency

You're navigating a SQL relational database, and the word "consistency" echoes through the corridors. What does it signify? Traditionally, it's part of the ACID (Atomicity, Consistency, Isolation, Durability) package. But hold on—there's more to this story!

The SQL Standard Consistency

Let's delve into the SQL standard's take on consistency. Let's say we have a table tracking attendees at a church walk. It proudly proclaims that five people wore red shirts. Sounds good, right? But wait! Each user's shirt color resides separately. Uh-oh! User one experiences a virtual resurrection, while everyone else dons blue. Now we have an inconsistency—two places, divergent data. Welcome to the world of inconsistency.

Eventual Consistency: The Wild Card

Enter "eventual consistency." In the vast expanse of databases, especially at scale, read replicas come into play. The burning question: Is data synchronized from the primary (where you write) to the replicas? Well, it's a nuanced dance. If synchronization occurs, it takes time, but everything aligns. If not, brace yourself for old data. It's "eventual" because it promises, "You'll get the new data eventually, just not right now."

The Clash of Consistencies

These two consistencies are like distant cousins. When you read from an inconsistent replica (hello, eventual consistency), you might encounter outdated data, but it's lightning-fast! But beware—the ripple effect can lead to inconsistencies elsewhere. Sometimes harmless (300 likes instead of 299), other times catastrophic - bank account mismatches.

☄️YouTube Channel: https://www.youtube.com/@TomerBenDavid

💥Podcast: https://podcasts.apple.com/us/podcast/programmers-quickie/id1281345843

🔥Blog: https://blog.code-code-code.com/

Top comments (0)