Part 10 of 12 · Databases

What does ACID actually promise, and what do you lose with BASE?

ACID is four separate promises, and most 'NoSQL vs SQL' arguments mix them up. Money transfers in PostgreSQL, MongoDB and DynamoDB, with and without transactions, with crashes: what each letter bought, measured, and why atomic writes still aren't enough if your reads aren't snapshots.

The round steel door of an old bank vault standing open, a picture of a database's promises to keep data safe

The verdict, which the experiment below will prove: ACID is four separate promises about a transaction:

  • Atomicity: all of it happens or none of it does.
  • Consistency: your rules (constraints) hold before and after.
  • Isolation: concurrent transactions don’t see each other half-done.
  • Durability: once committed, it survives a crash.

BASE (“basically available, soft state, eventually consistent”) describes systems that trade some of these for availability and scale, usually isolation across many items and immediate consistency across copies.

I’ve always liked that Theo Härder and Andreas Reuter packed so much into four letters back in 1983. The trouble is that the acronym makes them feel like one thing, and the fun starts when you pull them apart and watch each one fail on its own.

The usual suspect people name is the database itself: “SQL or NoSQL”. That’s a false lead today. MongoDB and DynamoDB both have multi-item transactions now. The question worth asking is: which of these promises does this operation need, and am I actually using the feature that gives it? In my tests, the most common culprit wasn’t a database lacking transactions. It was reads that weren’t snapshots.

So I set out to catch it in the act. I ran the same money-transfer workload on PostgreSQL 17, MongoDB 8.2 and DynamoDB Local, with and without transactions. The code is in database-tradeoffs-lab (make acid).

Case file

The case Money vanishes and readers see wrong totals
Suspects “SQL or NoSQL”, the database itself
Culprit Writes outside a transaction, and reads that weren’t snapshots
The fix Transactions for multi-record writes, snapshot reads for sums
Evidence PostgreSQL 17, MongoDB 8.2 and DynamoDB Local, make acid

The scene of the crime #

The setup is deliberately simple, so that any wrong number has nowhere to hide.

  • 100 accounts holding 1,000 each: 100,000 in total.
  • 8 workers make 8,000 random transfers of 1-100. A transfer only debits if the balance covers it.
  • 2% of transfers crash half-way, after the debit and before the credit, as if the process died.
  • Then, separately and without crashes, a reader adds up every balance over and over while transfers run.

The total should always be 100,000. Any other number is a body on the floor.

First clue: the total, and negative balances (atomicity and consistency) #

Store How a transfer is written Final total Negative balances
PostgreSQL two separate UPDATEs 93,731 0
PostgreSQL one transaction 100,000 0
MongoDB two separate updateOne 93,731 0
MongoDB session.withTransaction 100,000 0
DynamoDB two separate UpdateItem 93,731 0
DynamoDB TransactWriteItems 100,000 0
  • Without a transaction, every crash lost the money in flight. 128 crashes, 6,269 missing, identically in all three databases, because the workload was seeded. The database wasn’t the culprit; the application did two separate things, and stopped after one. That’s atomicity, and no database gives it to you unless you put both writes in one transaction.
  • With a transaction, the total held in every database. A crashed transfer rolled back (PostgreSQL, MongoDB), or was never sent (DynamoDB’s single TransactWriteItems request).
  • No balance went negative in any run, even without transactions, because each debit was a single conditional write: balance >= amount was checked and applied atomically on one row, one document or one item. Single-item atomicity exists in every one of these databases, BASE or not. Consistency of one record is cheap everywhere; consistency across records is what transactions are for.

That last point deserves a moment of admiration: one conditional write buys a lot of safety for free. The fix did leave two fingerprints, though:

  • MongoDB retried 831 write conflicts inside withTransaction. Concurrent transactions touching the same document conflict and retry, and the driver does it for you.
  • PostgreSQL deadlocked: two transfers between the same accounts in opposite directions lock the rows in opposite orders. My first run failed with deadlock detected. Retrying fixes it; locking the lower account ID first avoids it.

Second clue: what a reader sees (isolation) #

Isolation is the letter people tend to forget, and it’s where the real mystery hides. The second test has no crashes, so the real total is always 100,000. Any other total a reader sees is a transfer caught half-done.

Writers Reader Totals that weren’t 100,000
PostgreSQL, separate UPDATEs SELECT sum(balance) 2,932 of 3,050
PostgreSQL, transaction SELECT sum(balance) 0 of 2,362
MongoDB, separate updateOne snapshot read 312 of 317
MongoDB, transaction find() paged in batches of 10 418 of 467
MongoDB, transaction find() in a transaction, readConcern: "snapshot" 0 of 299
DynamoDB, separate UpdateItem TransactGetItems 162 of 165
DynamoDB, TransactWriteItems Scan, pages of 10 181 of 182
DynamoDB, TransactWriteItems TransactGetItems 0 of 42
Chart: Wrong totals a reader saw (MongoDB and DynamoDB)Chart: Wrong totals a reader saw (MongoDB and DynamoDB)
Diagram source
xychart-beta
  title "Wrong totals a reader saw (MongoDB and DynamoDB)"
  x-axis ["Mongo separate", "Mongo txn, paged", "Mongo txn, snapshot", "Dynamo separate", "Dynamo txn, Scan", "Dynamo txn, TransactGet"]
  y-axis "wrong totals"
  bar [312 , 418 , 0 , 162 , 181 , 0]

The evidence narrows the field in three steps:

  1. Without transactional writes, no reader can help. The half-done state is committed, so even a perfect snapshot reads it: 312 of 317, and 162 of 165.
  2. Transactional writes are not enough on their own. This is the twist. With every transfer atomic, a plain read that pages through the collection (MongoDB find in batches, DynamoDB Scan in pages) still saw wrong totals almost every time. Each page is read at a different moment, so the reader sees some transfers before and some after. That’s what “read committed, but not a snapshot” means.
  3. Snapshot reads close the case:
    • in PostgreSQL, any single statement is a snapshot, and so is a REPEATABLE READ transaction (the isolation levels post);
    • in MongoDB, a transaction with readConcern: "snapshot";
    • in DynamoDB, TransactGetItems (up to 100 items, and it can be refused if it conflicts with a write).

A red herring from my first run: with only 100 accounts, MongoDB returned them in one batch and DynamoDB in one page, and plain reads saw 0 wrong totals in about 1,900 tries each. That looked like an alibi. It was luck of size, not a guarantee. Neither store promises a snapshot across documents or items without the features above, and any real collection is bigger than one batch. A test that passes on a tiny dataset and fails in production is a classic way to learn this.

The quiet witness: durability #

The last letter is the one databases have worked hardest to make boring, which is a compliment. Not measured here: a committed write surviving a crash comes down to the write-ahead log and fsync, which the append-only log post measures. All three stores are durable on commit by default (PostgreSQL synchronous_commit = on; MongoDB writeConcern: majority since 5.0; DynamoDB replicates every write across multiple availability zones). Each lets you trade that away for speed (synchronous_commit = off, w: 1), and each says so in its docs.

The reveal: what you lose with BASE #

BASE systems were designed to stay available and scale out by not coordinating across items, and across copies. Concretely, what you give up (or must ask for explicitly):

Promise Typical BASE default How to get it back, and its cost
Atomicity across items Each item on its own Multi-item transactions (MongoDB, DynamoDB): conflicts, retries, limits (DynamoDB: 100 items per transaction)
Isolation across items No snapshot across a query Snapshot reads in a transaction; or design so one read touches one item
Consistency across copies Reads may be stale (eventual) Strongly consistent reads, majority read concern: more latency (the CAP/PACELC post)
Rules across records Enforced by your code Transactions, or model so a rule fits in one record
Flowchart: Does the rule fit in one record?, One conditional write, Transaction, with retries, Does a read add up several records?, Snapshot read, Plain read is fineFlowchart: Does the rule fit in one record?, One conditional write, Transaction, with retries, Does a read add up several records?, Snapshot read, Plain read is fine
Diagram source
flowchart TD
  A{"Does the rule fit in one record?"} -->|yes| B["One conditional write"]
  A -->|no| C["Transaction, with retries"]
  C --> D{"Does a read add up several records?"}
  B --> D
  D -->|yes| E["Snapshot read"]
  D -->|no| F["Plain read is fine"]

With the four promises separated, the real decisions almost make themselves. Here are three.

Case file 1: a money transfer #

What I’d use: a transaction, with conditional debits, a retry loop for conflicts and deadlocks, and an idempotency key on the transfer, so a retried request doesn’t move money twice. In PostgreSQL that’s routine. In DynamoDB, TransactWriteItems with a condition and a ClientRequestToken. Report balances with snapshot reads, never with a paged scan.

Case file 2: a social feed #

What I’d use: BASE without guilt. A post that appears in a follower’s feed a second late, or a like count that’s briefly off by one, harms no one. Single-item writes (a post, a like) are atomic anyway, and counters can use atomic increments. Spend the consistency budget elsewhere.

Case file 3: a shopping cart #

What I’d use: model the cart as one document or item per cart, so every change is a single atomic write without any transaction. That’s the “design so the rule fits in one record” move, and it’s lovely precisely because it makes the problem disappear rather than solving it. At checkout, where stock and payment are involved, switch to a transaction or a saga (the consistency post is the next case to read).

Remember this

  • ACID is four separate promises: ask for the one each operation needs.
  • Without a transaction, a crash between two writes loses money in every database.
  • Atomic writes aren’t enough: sums need snapshot reads.

What to do on Monday #

  1. Know which promise each operation needs: atomic across records? an isolated read? fresh across replicas?
  2. Prefer data models where the important rule fits in one record. Single-record atomic, conditional writes exist everywhere and are cheap.
  3. When it doesn’t fit, use the database’s transactions, with retries, and remember they cover writes: use snapshot reads for anything that adds up or compares several records.
  4. Test with realistic data sizes. Isolation bugs hide in small datasets.

What I enjoy most about this case is how kind the databases turned out to be: every promise was there, waiting to be asked for. Once you see ACID as four separate tools rather than one badge, you can pick exactly the ones each operation needs.

Measured Nov 2026: PostgreSQL 17.11, MongoDB 8.2.12 (one-node replica set, which multi-document transactions require), DynamoDB Local 3.3.2 (an emulator: it follows DynamoDB’s transaction semantics, not its latency or capacity), all in Docker on one laptop. Transfers and crashes from fixed seeds. Code and full results: database-tradeoffs-lab/13-acid.

Like (sign in first) 0 likes 💬 0

Written by

Vishal Kumar

Associate Director at CapGrid, running product and engineering in a CPTO capacity. 10+ years building distributed, multi-tenant SaaS and AI platforms. AWS Certified Solutions Architect - Professional. Based in Gurugram.

Comments

No comments yet.

Sign in to comment. We'll email you a link; no password needed.