ACID and BASE

Two promises about data · Part of Databases

Key idea

Practice

7 questions · about 4 min

Explained step by step

ACID

ACID is 4 properties that protect data during a transaction: Atomicity (all or nothing), Consistency (the database stays sound), Isolation (transactions don't step on each other) and Durability (what's confirmed isn't lost). Relational databases follow them so data is correct before and after each transaction. It's like a notary: the paperwork is signed in full, follows the rules, nobody cuts in and it's filed away.

Atomicity

Atomicity means all operations in a transaction succeed, or all are undone. There's no middle ground. A $100 transfer has 2 steps: subtract from your account and add to the other. If the second fails, the first is undone. It's like a handoff: either the other person catches the ball, or you still have it; it's never left in the air.

Isolation

Isolation means transactions don't step on each other. If 2 run at the same time on the same data, the database orders them so it looks like one ran after the other. It's like 2 tellers serving the same account: the bank makes one wait for the other so the balance doesn't go wrong. If you have $100 and 2 purchases of $80 arrive together, only 1 can go through.

Durability

Durability means that once the transaction is confirmed and written to disk, it stays saved even if the power then goes out or the system crashes. It's like a signed receipt: even if the cash register burns, the receipt proves you paid. If the database confirms your transfer and the server shuts down 1 second later, the transfer is still there when it comes back.

BASE

BASE is a looser model than ACID, common in NoSQL: it gives up immediate consistency in exchange for scaling and always being available. It stands for Basically Available (the database almost always answers), Soft state (copies don't have to match all the time) and Eventual consistency (data catches up over time). It's like a group of friends passing gossip around: in a while everyone knows, but not in the same second.

There's no right answer between ACID and BASE: each fits different requirements. With BASE, developers must know well how the database behaves and code carefully to handle data that may be behind. ACID is simpler to use and ideal when reliability and consistency are essential. It's like choosing between a train with a fixed timetable (ACID) and a taxi (BASE): one is predictable, the other flexible.

Eventual consistency

Eventual consistency means data may not match across all copies right away, but over time it will. Meanwhile, you can still read, though the answer may be old. It's like changing your profile photo: your friends in another country see it 2 seconds later. It works for likes, comments or views, not for bank balances.

Terms in this lesson

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.

Key idea

Two promises about data