Transactions in Distributed Applications: ACID Properties

Priya Patidar
The Developer’s Diary
6 min readMay 19, 2024

Introduction

Ever wondered what happens in the split second after you click “confirm” on an order, or “send” on a message? Beneath the surface, a complex dance of transactions ensures that your digital world runs flawlessly. In this series, we’re diving into the heartbeat of every app and system: transactions. Starting with the solid foundation of ACID properties, through the subtleties of handling single vs. multi-object operations, and venturing into the realms of weak isolation and serializability, we’re unpacking the magic one layer at a time. Whether you’re a tech enthusiast or a developer looking to deepen your understanding, join us on this journey to discover how transactions make the digital world tick.

Concept Of Transaction

Think of transactions like the behind-the-scenes magic that makes sure everything you do online, from shopping to sending emails, works without a hitch. This magic started back in the 1970s with banks, making sure that when you put money in, it stayed safe and sound. But as the internet grew, so did the need for this magic to work faster and in more places at once, from websites to apps on your phone. The challenge? Keeping everything running smoothly without slowing down. Today, the tech wizards are finding clever ways to keep the magic alive, ensuring that even as the world’s online activities speed up, everything stays safe and in sync. This journey from bank vaults to global networks shows just how much technology has evolved, making transactions a key piece of the internet’s puzzle.

ACID Properties

Google Image

ACID stands for Atomicity, Consistency, Isolation, and Durability. These four properties ensure that database transactions are processed reliably. In simpler terms, ACID properties make sure that when you’re doing something with your data, everything goes exactly as planned — or doesn’t happen at all.

Atomicity:

Atomicity is about keeping transactions all-or-nothing. Imagine you’re buying a book online. The process involves two main steps: paying for the book and then the book being marked as sold to you. Atomicity ensures that both these steps either happen completely or not at all.

Example: Think of baking a cake. You need flour, sugar, eggs, and butter. If you find out halfway through that you’re missing eggs, you don’t partially bake the cake; you either have all ingredients and bake it or you don’t.

What Happens Without Atomicity? Without atomicity, things can get messy. Using the book-buying example, if the payment goes through but there’s an error marking the book as sold, you could be charged without getting the book. It’s like being charged for a cake you never got to eat because it was never fully baked. Atomicity prevents these partial outcomes, ensuring either the complete transaction occurs or nothing happens at all, keeping everything in order.

Consistency

Consistency ensures that every transaction brings the database from one valid state to another, maintaining all predefined rules, like unique identifiers and foreign keys. Essentially, consistency acts as a rulebook, making sure that all data actions are correct and permissible according to the database’s own regulations.

Example: Imagine playing a board game where you move a piece according to dice rolls. Consistency is like the game’s rulebook that you consult after every dice roll to make sure your move is allowed. If you roll a six and the rules say you can move forward, you do. But if there’s a rule that says “do not pass go” when you roll a six, then regardless of your roll, you follow that rule.

What Happens Without Consistency? Without consistency, databases can become like a game without rules: chaotic. For instance, if your bank allowed you to withdraw money without checking if your balance is sufficient, it would lead to negative balances, creating a financial mess. Just like a board game needs rules to function properly, databases need consistency to ensure that every transaction makes sense and follows the established rules, keeping the data reliable and orderly.

Consistency differs from other ACID properties because it’s about sticking to the application’s rules. Think of it as the app telling the database, “Here’s what I need you to check for me.”

Isolation

Isolation ensures that transactions are securely processed independently, even when they happen at the same time. It’s like ensuring no leaks between transactions, so one doesn’t affect or see the changes made by another until they’re complete.

Example: Think of taking an exam in a classroom where each student is shielded by a partition to prevent cheating. Isolation in database transactions works similarly. If two people are making transactions at the same time — say, one is transferring money to an account while another is withdrawing from it — the isolation property ensures that these transactions occur independently. Each transaction is unaware of the other, preventing any mix-up or interference.

What Happens Without Isolation? Without proper isolation, transactions could overlap and affect each other in unpredictable ways. For example, if two transactions attempt to update the same bank account simultaneously without isolation, one transaction could overwrite or disrupt the other. This could result in incorrect account balances, much like if students could see each other’s exam papers, the results would not accurately reflect their individual knowledge. Isolation ensures that each transaction is processed as if it were the only one happening, preserving the integrity and reliability of the database operations.

Durability

Durability is the assurance that once a transaction has been committed, it will remain so, even in the event of a power loss, crash, or other system failures. This ACID property guarantees that the database keeps all completed transactions safe and sound, no matter what happens.

Example: Consider writing a letter and putting it in a waterproof, fireproof safe. No matter what happens outside the safe — be it rain, fire, or anything else — the letter remains intact and unchanged. Durability in database transactions works similarly. Once a transaction, like a bank deposit, is completed, this property ensures that the deposit remains in your account, even if the bank’s system crashes or there’s a power outage immediately after.

What Happens Without Durability? Without durability, completed transactions could disappear or revert if a system crashes or loses power. Imagine if saving a document on your computer didn’t guarantee it would be there when you restarted after a crash. You could lose important work with no way to recover it. In databases, this would mean financial records, purchase confirmations, or other critical data could be lost, leading to confusion, inaccuracies, and potential financial loss. Durability ensures once transactions are done, they’re set in stone, providing reliability and trust in the system’s integrity.

Conclusion

Managing transactions in distributed applications requires a deep understanding of the ACID properties and the challenges specific to distributed systems. Techniques such as Two-Phase Commit and advanced concurrency control mechanisms are essential for ensuring data consistency and reliability.

To delve deeper into how isolation levels affect transaction management and how Serializable Snapshot Isolation can address many of these challenges, read our articles on weak isolation and serializability. Understanding these concepts will help you design robust and efficient distributed applications that maintain high levels of data integrity and performance.

Ref: This article was inspired by the book “Designing Data-Intensive Applications” by Martin Kleppmann, which provides in-depth insights into the complexities of database design and transaction management.

--

--