Catalog My learning Blog
System Design Roadmap: 100-Day Course for Engineers · Phase 3 · Lesson 27 · 4 min read

ACID vs BASE Explained

On this page
  1. Checkout used to be one transaction
  2. What ACID means: atomicity, consistency, isolation, durability
  3. Isolation levels and write skew
  4. What BASE means in distributed systems
  5. Why not use a distributed transaction (2PC)?
  6. Sagas: local transactions with compensation
  7. ACID vs BASE in practice
  8. Check yourself

Checkout used to be one transaction

In the monolith, checkout was easy: begin a transaction, reserve stock, record the payment, create the order, commit. If anything failed, roll back and nothing happened. Then checkout was split into Order, Payment and Inventory services, each with its own database. There's no longer one place to say COMMIT.

What ACID means: atomicity, consistency, isolation, durability

  • Atomicity: all the changes happen, or none do.
  • Consistency: constraints hold before and after (unique keys, foreign keys, checks).
  • Isolation: concurrent transactions don't see each other's half-finished work.
  • Durability: once committed, it survives a crash.

Isolation levels and write skew

Isolation comes in levels, and the default is usually weaker than people assume. PostgreSQL and SQL Server default to read committed; MySQL InnoDB to repeatable read. Higher levels, up to serializable, prevent more anomalies at the cost of more blocking or retries. Know your database's default before relying on "it's in a transaction".

Here's what read committed lets through. A hospital rule says at least one doctor must stay on call. Two doctors on call each request leave at the same moment. Each transaction checks "is anyone else on call?", sees yes, and removes itself. Both commit, and nobody is on call. Neither transaction saw anything wrong. This is write skew, and even snapshot-based repeatable read doesn't stop it.

The fixes: lock the rows you checked (SELECT ... FOR UPDATE), encode the rule as a constraint, or run at serializable. At serializable, PostgreSQL aborts one of the two transactions with a serialization error (SQLSTATE 40001), and your code must retry it. Using serializable without a retry loop just turns a silent bug into user-visible errors.

One SQL Server detail: plain read committed uses locks, so readers can block writers. Many teams turn on READ_COMMITTED_SNAPSHOT, where readers see the last committed version instead, and Azure SQL Database has it on by default. Behavior under load differs between the two, so check which one your database uses.

What BASE means in distributed systems

BASE stands for Basically Available, Soft state, Eventually consistent. The system stays up and accepts work, data may be temporarily out of sync between components, and it converges over time. It's the trade from Days 5 and 6 applied to transactions: give up immediate all-or-nothing across components in exchange for availability and independence.

Why not use a distributed transaction (2PC)?

Two-phase commit (2PC, Day 66) coordinates a commit across several databases: everyone prepares, then everyone commits. It works, but a stuck coordinator can leave participants holding locks, every participant must support it, and many modern stores and message brokers don't. Between independently deployed services, it's rarely used.

Sagas: local transactions with compensation

A saga splits the work into a sequence of local ACID transactions, one per service. Each step has a compensating action that undoes its effect if a later step fails.

A single-database ACID transaction compared with a saga: a sequence of local transactions with compensating actions.
A single-database ACID transaction compared with a saga: a sequence of local transactions with compensating actions.

Checkout as a saga:

StepServiceLocal transactionCompensation if a later step fails
1InventoryReserve itemsRelease the reservation
2PaymentCharge the cardRefund the charge
3OrderMark confirmed, request shipmentMark failed, notify the customer

If payment fails at step 2, the saga runs step 1's compensation: release the items. The order is marked failed. Each service only ever commits to its own database.

What sagas give up: in between steps, other users can see intermediate states, such as reserved stock that will be released a second later. Compensations aren't rollbacks; a refund is a new action that customers can see on their statement. And every step must be safe to retry (Day 65), because messages get redelivered. Day 49 covers how to run sagas with orchestration or choreography.

ACID vs BASE in practice

Keep work that must be atomic inside one database whenever you can. That's often a reason to draw service boundaries around data that changes together (Day 52). Use sagas only for workflows that span services, and design the intermediate states so users understand them ("Payment processing").

Check yourself

Write skew: each check was true when it ran, but neither saw the other's insert. Add a unique or exclusion constraint on room and time, or run at serializable and retry on serialization errors.

The saga runs compensating actions for the steps that already completed, in reverse order: it releases the reserved inventory, then marks the order as failed and tells the customer. Compensations must be idempotent, because a crash can cause them to run more than once.

Read committed. Two transactions can read the same row and both act on it, so patterns like "check stock then decrement" need explicit locking, constraints or a stricter level.

Two-phase commit locks resources across services until everyone agrees, so one slow or failed participant blocks the others, and the coordinator itself can fail mid-protocol. It couples services tightly and hurts availability, which is why sagas with compensation are usually preferred.