Database Transactions — In a very simple language

Mayur SSoni
3 min readDec 24, 2023

Understanding a topic through intuition is key to learning.

Transactions

In simple language, Is a recipe in cooking, where all ingredients need to be added and cooked together to produce a complete dish.

Let me give you some more concrete examples:

  1. The act of transferring money between two bank accounts
  2. Booking a ticket online, etc.

The key thing to notice in the above examples is those use cases are sequences of actions, that can be either complete or incomplete.

Problem Statement

I want to ensure that either my set of actions succeeds or fails.

How this can be addressed?

By RELIABILITY | CONSISTENCY | INTEGRITY

Reliability — Imagine ordering a pizza for delivery. Reliability is like trusting that the pizza will arrive within the promised time, hot and fresh.

In a database, reliability means ensuring that when you request information (like ordering a pizza), the system consistently delivers the correct and expected results without errors or delays.

Consistency — Think of baking cookies where each cookie should have the same shape and taste.

Similarly, in a database, for instance, if you update your address in one place, the change should reflect everywhere else in the system immediately.

Integrity — Just as a librarian ensures no torn pages or missing chapters in a book, database integrity ensures there are no incorrect or missing pieces of data.

Some of the above terms are nothing but foundational principles of the Databases and its termed ACID properties.

ACID

In essence, ACID properties in database management systems guarantee that transactions are executed reliably, maintain consistency, and safeguard the integrity of the data, thereby ensuring the overall correctness and reliability of the database operations.

A — Atomicity

Think of buying a combo meal at a fast-food restaurant. Just like a combo meal, where all items (burger, fries, drink) are served together or not at all.

In a database transaction, atomicity ensures that if a part of the transaction fails (like adding money from one account and deducting from another in a fund transfer), the entire transaction is rolled back, keeping the database in its original state.

C — Consistency

Imagine assembling a puzzle where every piece fits perfectly into place, forming a complete picture.

Each data entry or modification must align correctly with the predefined rules and constraints, ensuring that the overall database structure remains coherent and accurate.

I — Isolation

Imagine multiple chefs cooking in the same kitchen but working independently on different recipes without interfering with each other’s ingredients or cooking methods

In Database — Isolation ensures that multiple transactions can occur simultaneously without affecting each other.

D — Durability

Think of saving important files on a sturdy external hard drive. Even if the computer crashes, the files remain safe and accessible when the system restarts.

Durability ensures that once a transaction is committed, its changes are permanent and survive system failures. Committed changes are stored in a way that they can be recovered even in the event of a power outage or system crash.

In Part 2 — Database Transactions, we will cover Concurrency Control and Isolation Levels. Stay tuned.

Thanks for reading :)

To learn more about me — https://www.linkedin.com/in/mayurssoni2456/

--

--