Skip to content

ACID vs BASE Explained — Transactions, Consistency Models, When to Use Each

DodaTech Updated 2026-06-22 11 min read

In this tutorial, you'll learn about ACID vs BASE Explained. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

ACID and BASE are two database Consistency Models — ACID guarantees strict transaction reliability for systems like banking, while BASE prioritizes availability and partition tolerance for Distributed Systems where perfect consistency is impractical.

What You'll Learn

You'll understand ACID properties (Atomicity, Consistency, Isolation, Durability), BASE principles (Basically Available, Soft state, Eventual consistency), the CAP Theorem tradeoffs, when to choose each model, and how modern databases blend both approaches.

Why It Matters

Choosing the wrong consistency model causes either slow transactions (ACID on a high-traffic social feed) or inconsistent data (BASE on a banking ledger). Doda Browser maintains bookmarks and history; these need ACID for integrity but can tolerate BASE for syncing across devices.

Real-World Use

A payment processing system used a NoSQL database with eventual consistency. Two users transferred money simultaneously: the system deducted from both accounts but never completed the credit, losing $50,000. Switching to an ACID-compliant database with proper transaction isolation prevented this.

ACID vs BASE Learning Path

flowchart LR
  A[SQL Basics] --> B[Database Design]
  B --> C[ACID vs BASE]
  C --> D[Distributed Databases]
  C:::current
  classDef current fill:#f90,color:#fff,stroke:#333,stroke-width:2px
â„šī¸ Info

Prerequisites: Basic understanding of SQL Basics and Database Design. Familiarity with MySQL and MongoDB is helpful for context.

ACID Properties

ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties guarantee that database transactions are processed reliably.

Atomicity

A transaction is an atomic Unit of Work. Either all operations succeed, or none do (rollback).

-- Atomic transaction: transfer money between accounts
BEGIN TRANSACTION;

UPDATE accounts SET balance = balance - 100 WHERE account_id = 1;
-- If the server crashes here, the debit is rolled back
UPDATE accounts SET balance = balance + 100 WHERE account_id = 2;

COMMIT;
-- Either both updates commit, or neither does

Expected behavior: If the server crashes after the first UPDATE but before the second, the database automatically rolls back the debit. Account 1's balance is unchanged.

Consistency

Transactions only bring the database from one valid state to another. All defined rules (constraints, triggers, cascades) are enforced.

-- A CHECK constraint enforces consistency
CREATE TABLE accounts (
    account_id INT PRIMARY KEY,
    owner VARCHAR(100) NOT NULL,
    balance DECIMAL(10,2) CHECK (balance >= 0)  -- Balance cannot go negative
);

-- This transaction would violate the constraint
BEGIN;
UPDATE accounts SET balance = balance - 500 WHERE account_id = 1;
-- If balance was 100, this would make it -400 → violates CHECK (balance >= 0)
-- The transaction is ROLLED BACK automatically
COMMIT;  -- This never executes

Expected behavior: Any transaction that would leave the database in an inconsistent state (negative balance, duplicate primary key, violated foreign key) is rejected and rolled back.

Isolation

Concurrent transactions do not interfere with each other. The database provides different Isolation Levels to balance performance and correctness.

-- Transaction isolation levels in PostgreSQL

-- READ UNCOMMITTED: Dirty reads possible
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

-- READ COMMITTED (default): Only committed data is visible
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;

-- REPEATABLE READ: Same row read twice returns same result
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;

-- SERIALIZABLE: Transactions execute as if one after another
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;

-- Transaction A: Read the same row twice
BEGIN;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SELECT balance FROM accounts WHERE account_id = 1;  -- Returns 1000
-- Transaction B updates balance to 800 and commits
SELECT balance FROM accounts WHERE account_id = 1;  -- Still returns 1000 (repeatable read)
COMMIT;

Expected behavior: At REPEATABLE READ isolation, Transaction A sees a consistent snapshot of the database even if other transactions modify data concurrently.

Durability

Once a transaction is committed, its changes persist even if the database crashes immediately after.

-- Durability in PostgreSQL: Write-Ahead Log (WAL)
-- When COMMIT succeeds, the change is written to WAL on disk
-- Even if the database crashes, WAL replay restores the transaction
COMMIT;

-- Configure durability vs performance tradeoffs
-- postgresql.conf
synchronous_commit = on      -- Full durability (wait for WAL flush)
-- synchronous_commit = off  -- Faster but risk of data loss on crash

Expected behavior: After a successful COMMIT, the data survives power failures, crashes, and restarts. The database replays the WAL to recover any unflushed changes.

BASE Properties

BASE stands for Basically Available, Soft state, and Eventual consistency. It is the consistency model for distributed NoSQL databases.

Property Meaning
Basically Available The system guarantees availability (every request gets a response, even if it's stale data)
Soft state The system state changes over time without input (due to eventual consistency)
Eventual consistency Given enough time without updates, all replicas will converge to the same state

Example: Eventual Consistency in Action

# Simulating eventual consistency across replicas
import time

class DistributedKVStore:
    def __init__(self, nodes: list[str]):
        self.nodes = {node: {} for node in nodes}
        self.replication_delay = 2  # seconds

    def write(self, key: str, value: str) -> str:
        """Write to the leader, replicate to followers asynchronously."""
        leader = self.nodes["leader"]
        leader[key] = value
        # Async replication (simulated with a thread)
        self._async_replicate(key, value)
        return "OK"

    def _async_replicate(self, key: str, value: str):
        """Replicate to followers after a delay."""
        time.sleep(self.replication_delay)
        for node_name, store in self.nodes.items():
            if node_name != "leader":
                store[key] = value

    def read(self, key: str, node: str = "leader") -> str:
        """Read from any node."""
        return self.nodes[node].get(key, None)

# Usage
store = DistributedKVStore(["leader", "follower_1", "follower_2"])
store.write("theme", "dark")
print("Read from leader:", store.read("theme", "leader"))           # Immediate: dark
print("Read from follower:", store.read("theme", "follower_1"))     # Stale: None
time.sleep(3)
print("Read from follower after delay:", store.read("theme", "follower_1"))  # Eventually: dark

Expected output:

Read from leader: dark
Read from follower: None
Read from follower after delay: dark

CAP Theorem and Its Tradeoffs

The CAP Theorem states that a distributed data store can provide at most two of three guarantees: Consistency, Availability, and Partition tolerance.

flowchart TD
    CAP([CAP Theorem]) --> CP[CP Systems
Consistency + Partition Tolerance
Banking, RDBMS] CAP --> AP[AP Systems
Availability + Partition Tolerance
Social media, DNS] CAP --> CA[CA Systems
Consistency + Availability
Single-node databases] CP --> CPEx["Example: MongoDB (default), HBase"] AP --> APEx["Example: Cassandra, CouchDB, DynamoDB"] CA --> CAEx["Example: MySQL (single node), PostgreSQL"] style CP fill:#d4edda style AP fill:#fff3cd style CA fill:#cce5ff
System Type Consistency Availability Partition Tolerance Example
CP Strong Low High Banking system
AP Eventual High High Social media feed
CA Strong High None Single-node SQL

When to Use ACID vs BASE

Choose ACID When

  • Financial transactions (payments, accounting, ledgers)
  • Inventory management (prevent overselling)
  • Booking systems (hotel rooms, flights)
  • Any system where data integrity is more important than uptime

Choose BASE When

  • Social media feeds (eventual consistency for likes/comments is fine)
  • Content management systems (cached pages can be slightly stale)
  • IoT sensor data (missing one reading is acceptable)
  • Any system where availability and scale matter more than immediate consistency

Blending ACID and BASE (NewSQL)

Modern databases blend both approaches. For example, Google Spanner provides ACID transactions at global scale using atomic clocks and TrueTime.

-- CockroachDB (a NewSQL database): ACID transactions across distributed nodes
BEGIN;
UPDATE inventory SET quantity = quantity - 1 WHERE product_id = 100 AND quantity > 0;
INSERT INTO orders (user_id, product_id, quantity) VALUES (42, 100, 1);
COMMIT;
-- This transaction is ACID-compliant even in a globally distributed cluster

Expected behavior: CockroachDB guarantees ACID properties across multiple nodes in different data centers. If the inventory check fails (quantity < 0), the transaction is rolled back atomically.

Common ACID vs BASE Errors

1. Using BASE for Financial Transactions

Eventual consistency means two users could withdraw the same money. Financial systems require strict ACID guarantees.

2. Using ACID When You Only Need BASE

Running ACID transactions on a distributed social media feed causes unnecessary latency. A news feed doesn't need strict consistency.

3. Ignoring Isolation Level Impact

The default isolation level (READ COMMITTED) allows non-repeatable reads. Phantom reads, dirty reads, and write skew can occur at lower Isolation Levels.

4. Confusing Eventual Consistency with "No Consistency"

Eventual consistency guarantees that data will converge eventually. It does not mean data is ever lost. Cassandra and DynamoDB use Conflict Resolution (last-write-wins, CRDTs) to resolve inconsistencies.

5. Assuming NoSQL Means No Transactions

Many NoSQL databases support transactions for limited scopes. MongoDB supports multi-document ACID transactions. DynamoDB supports transactions within a partition.

6. Forgetting About Network Partitions

If the network splits, a CP system (like MongoDB default) chooses consistency and stops accepting writes on one side. An AP system (like Cassandra) accepts writes on both sides and resolves conflicts later.

7. Not Testing Consistency Under Failure

Your system might work perfectly during testing when everything is connected. Test what happens when network partitions occur, nodes crash, or latency spikes.

Practice Questions

1. What does the "I" in ACID stand for and why is it important?

Isolation — it ensures that concurrent transactions do not interfere with each other. Without isolation, one transaction could read uncommitted data (dirty read) or see inconsistent results from another transaction in progress.

2. What is the main tradeoff between ACID and BASE?

ACID guarantees consistency at the cost of availability during network partitions. BASE guarantees availability at the cost of immediate consistency. The choice depends on whether your application needs strict data integrity or high uptime.

3. Can a database provide both ACID and BASE?

Yes. NewSQL databases like Google Spanner and CockroachDB provide ACID transactions in a distributed environment. PostgreSQL can be configured with synchronous replication for ACID durability or async replication for BASE-like availability.

4. How does the CAP Theorem relate to ACID and BASE?

ACID systems typically prioritize Consistency and Partition tolerance (CP in CAP terms). BASE systems prioritize Availability and Partition tolerance (AP). Both make tradeoffs based on the CAP Theorem constraints.

5. Challenge: Design a hybrid ACID/BASE architecture.

Your e-commerce platform has product catalog (read-heavy, eventual consistency OK) and payment processing (must be ACID). Answer: Use PostgreSQL (ACID) for orders, payments, and inventory. Use Redis (BASE) for product catalog cache and session data. Use MongoDB (BASE) for product reviews and user activity logs. The payment flow uses ACID transactions in PostgreSQL. Product catalog reads hit Redis first, falling back to PostgreSQL. This gives you the best of both models.

FAQ

What is a dirty read in database isolation?

A dirty read occurs when a transaction reads data that another transaction has modified but not yet committed. If the other transaction rolls back, the first transaction has read invalid data. SERIALIZABLE isolation prevents dirty reads.

Is MongoDB ACID-compliant?

Yes, since MongoDB 4.0, multi-document ACID transactions are supported. However, in a distributed (sharded) deployment, the performance cost is significant. Many applications use MongoDB with weaker consistency for better performance.

What is write skew?

Write skew occurs when two concurrent transactions read overlapping data sets and make conflicting decisions. For example, two doctors both check if they are on-call (each sees they are), then both go off-call, leaving no one on-call. SERIALIZABLE isolation prevents this.

Does eventual consistency mean weak consistency?

No. Eventual consistency guarantees that if no new updates are made, all replicas will eventually return the last updated value. It is one type of weak consistency, but there are stronger forms like read-your-writes consistency and monotonic reads.

Try It Yourself

Compare ACID and BASE behavior:

  1. Start two PostgreSQL sessions and test transaction Isolation Levels
  2. Run concurrent transactions at READ COMMITTED vs SERIALIZABLE
  3. Observe dirty reads, non-repeatable reads, and phantom reads
  4. Set up a simple DynamoDB table (or use local DynamoDB)
  5. Write to one node and immediately read from another — observe stale data
  6. Wait for consistency and verify the data eventually converges

What's Next

Database Design Guide
NoSQL Data Modeling
Database Sharding

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro