Home/Learn/System Design/ACID vs BASE

ACID vs BASE

Intermediate
Data Management

ACID (Atomicity, Consistency, Isolation, Durability) guarantees strict transactional correctness in relational databases. BASE (Basically Available, Soft state, Eventually consistent) trades strict consistency for availability and scalability in distributed systems.

Overview

ACID properties define the gold standard for database transactions. Atomicity ensures all-or-nothing execution. Consistency ensures transactions move the database from one valid state to another. Isolation ensures concurrent transactions do not interfere. Durability ensures committed data survives crashes. ACID is natural for single-node relational databases but becomes expensive to enforce across distributed nodes (requires distributed transactions like 2PC). BASE emerged as a pragmatic alternative for distributed systems. "Basically Available" means the system responds to every request (possibly stale data). "Soft state" means the system state may change over time without input (due to background reconciliation). "Eventually consistent" means all replicas converge to the same value given enough time. Most NoSQL databases and microservice architectures use BASE semantics to achieve horizontal scalability.

ACID in Depth

ACID properties are enforced by the database engine using write-ahead logging (durability), locking or MVCC (isolation), constraint checks (consistency), and undo logs (atomicity).

SQL — ACID properties demonstrated
// ACID transaction example — bank transfer
BEGIN;
  -- Atomicity: both succeed or both roll back
  UPDATE accounts SET balance = balance - 500 WHERE id = 1;
  UPDATE accounts SET balance = balance + 500 WHERE id = 2;

  -- Consistency: CHECK constraint prevents negative balance
  -- ALTER TABLE accounts ADD CONSTRAINT positive_balance CHECK (balance >= 0);

  -- Isolation: other transactions see either the old or new state, not partial
  -- SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

  -- Durability: once COMMIT returns, data survives power failure
COMMIT;

// Isolation levels (weakest → strongest):
// READ UNCOMMITTED → dirty reads possible
// READ COMMITTED   → no dirty reads (PostgreSQL default)
// REPEATABLE READ  → no non-repeatable reads (MySQL InnoDB default)
// SERIALIZABLE     → full isolation (slowest)

BASE in Distributed Systems

BASE accepts that consistency is not immediate. The system prioritises availability and partition tolerance, allowing temporary inconsistencies that resolve over time through background processes.

Conceptual + CQL — BASE in action
// BASE example — e-commerce order flow
//
// 1. Order placed → write to Orders DB (committed)
// 2. Inventory decremented → async event to Inventory service
// 3. Payment charged → async event to Payment service
//
// Window of inconsistency:
//   Between step 1 and step 3, the order exists but payment
//   is not yet confirmed. The system is in a "soft state."
//
// Eventually consistent:
//   If payment fails, a compensating action cancels the order.
//   Given enough time, all services converge to a consistent state.

// Cassandra — BASE with tunable consistency
// Write with QUORUM (majority) for stronger consistency
// Read with ONE for availability
INSERT INTO orders (id, user_id, total)
VALUES ('ord-1', 'u-42', 99.99)
USING CONSISTENCY QUORUM;

SELECT * FROM orders WHERE id = 'ord-1'
USING CONSISTENCY ONE;  -- fast, might be stale

When to Use Which

Use ACID when correctness is non-negotiable (financial transactions, inventory). Use BASE when availability and scale matter more than instant consistency (social feeds, analytics, activity logs).

Conceptual — ACID vs BASE decision guide
// Decision guide
//
// Use ACID when:
//  ✅ Financial transactions (transfers, payments)
//  ✅ Inventory management (prevent overselling)
//  ✅ User registration (unique constraints)
//  ✅ Any operation where partial state = data corruption
//
// Use BASE when:
//  ✅ Social media feeds (eventual delivery is fine)
//  ✅ Analytics / counters (approximate counts acceptable)
//  ✅ Notification delivery (retry until delivered)
//  ✅ Shopping cart (last-write-wins is acceptable)
//  ✅ Geo-distributed reads (stale-by-seconds is tolerable)
//
// Hybrid approach:
//  Payment service → PostgreSQL (ACID)
//  Recommendation engine → Cassandra (BASE)
//  Order service → ACID locally, BASE across services (Saga pattern)

Key Points to Remember

  • 1ACID: strict transactional guarantees — Atomicity, Consistency, Isolation, Durability.
  • 2BASE: relaxed consistency for scalability — Basically Available, Soft state, Eventually consistent.
  • 3ACID is expensive in distributed systems (2PC, coordination overhead); BASE scales naturally.
  • 4Use ACID for financial/critical data; BASE for social feeds, analytics, and high-scale reads.
  • 5Most microservice architectures use ACID within a service and BASE between services.

Interview Questions

Sign in to ask Aria
1

What do ACID and BASE stand for?

EasyWipro
2

Why is ACID hard to achieve in distributed systems?

MediumAmazon
3

Give an example where BASE is preferable over ACID.

MediumFlipkart
4

How does Cassandra achieve tunable consistency between ACID and BASE?

HardNetflix
5

Design the consistency model for a distributed e-commerce checkout system.

HardGoogle

Ask Aria about ACID vs BASE

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…