ACID and BASE are two sets of promises a database can make about your data. ACID says every transaction is all-or-nothing and the data is always in a valid state. BASE says the system stays available and the data will agree everywhere eventually. Neither is better in general. They answer different questions, and most real systems use both in different places.
ACID: the transaction promise
ACID describes how a transaction behaves. It is what you get from PostgreSQL, MySQL with InnoDB, SQLite, SQL Server and Oracle, and also from several distributed databases.
- Atomicity. All the statements in a transaction take effect, or none do. If a transfer debits one account and the server crashes before crediting the other, the debit is rolled back.
-
Consistency. A transaction moves the database from one valid state to another. Constraints such as foreign keys,
UNIQUEandCHECKare never left broken after a commit. - Isolation. Concurrent transactions do not see each other's half-done work. How strict this is depends on the isolation level (read committed, repeatable read, serializable).
- Durability. Once a commit returns, the change survives a crash, usually because it was written to a log on disk first.
A classic example:
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
Either both rows change or neither does, and no other transaction ever sees the money missing from both accounts.
BASE: the availability promise
BASE was coined as a contrast to ACID for large distributed systems that replicate data across many nodes, often across data centers.
- Basically Available. The system answers requests even when some nodes fail or the network splits. You may get a stale answer rather than an error.
- Soft state. The state of the system can change over time without new input, as replicas exchange updates.
- Eventually consistent. If writes stop, all replicas converge to the same value. Until then, two readers may see different values.
Example: a user updates their profile photo. The write lands on one replica, and a friend reading from another replica still sees the old photo for a moment. Nobody loses money over this, and the service never had to refuse the write.
Systems often described this way include Cassandra, DynamoDB in its default read mode, Riak, and DNS. Many of them let you choose stronger consistency per request (for example quorum reads and writes, or strongly consistent reads), at the cost of latency or availability.
Side by side
| ACID | BASE | |
|---|---|---|
| Main goal | Correctness of each transaction | Availability and scale |
| Consistency | Strong, immediate | Eventual |
| Under a network partition | May refuse or delay requests | Keeps answering, may be stale |
| Multi-row updates | Atomic transactions | Often single-item, or app-level |
| Scaling writes | Harder across many nodes | Designed for many nodes |
| Who handles conflicts | The database (locks, MVCC) | Often the app or merge rules |
| Typical systems | PostgreSQL, MySQL, SQLite | Cassandra, DynamoDB, Riak |
How this links to CAP
The CAP theorem says that when the network partitions, a distributed system must choose between consistency and availability. ACID-style distributed databases lean toward consistency: a node that cannot reach the others may refuse writes. BASE systems lean toward availability: every node keeps accepting work and they reconcile later. On a single machine there is no partition to worry about, which is why single-node databases give you full ACID cheaply.
Common misunderstandings
- "NoSQL means no transactions." Not true anymore. MongoDB supports multi-document ACID transactions, and DynamoDB has transactional APIs. The labels describe defaults and design goals, not hard limits.
- "ACID means serializable." Many ACID databases default to a weaker isolation level, such as read committed. Read your database's defaults before relying on them.
- "Eventual means soon." Eventual consistency gives no time bound. Usually replicas converge quickly, but under failure it can take much longer.
- "The C in ACID is the C in CAP." They are different. ACID consistency is about constraints and valid states; CAP consistency is about all nodes returning the latest write.
When to pick which
Pick ACID when:
- money, stock, bookings or anything that must not be double-counted is involved;
- one business action touches several rows or tables that must change together;
- you need constraints the database enforces for you;
- your data fits on one primary node, or a distributed SQL database, without strain.
Pick BASE when:
- staying available matters more than every reader seeing the latest value (feeds, likes, view counters, sessions, telemetry);
- you write very high volumes across regions and must accept writes everywhere;
- your data model is mostly single-key reads and writes;
- your application can merge conflicts or tolerate a short delay.
Mix them when the system has both kinds of data, which is common. Orders and payments sit in an ACID database. The product catalog cache, activity feed and analytics events go to an eventually consistent store. Choose per piece of data, not per company.
In short
ACID protects each transaction: all-or-nothing, valid, isolated and durable. BASE protects availability: always answer, converge later. Start with ACID by default because it is easier to reason about, and move specific data to a BASE-style store when scale or availability needs prove it.
Watch the animated version: https://youtu.be/Prq2zS7j-7c
Originally published at abdeldjalilchougui.biz.
Top comments (0)