Skip to the page

Transactions and locking · Concept

ACID with a wallet transfer

The interviewer asks

Explain ACID using a transfer of ₹500 from one user's wallet to another user's wallet in our app. What does each letter protect you from?

Then

Follow-ups the interviewer asks next

  1. The server crashes after the debit but before the credit. What does the database do when it restarts?
  2. How does the database make a commit durable?
  3. Is the C in ACID the same as the C in CAP?
  4. A real UPI payment moves money between two banks. Can one database transaction cover that? What happens instead?
  5. What do synchronous_commit = off in PostgreSQL or innodb_flush_log_at_trx_commit = 2 in MySQL give up?

The answer

What a strong answer covers

  • Atomicity: the debit and the credit both happen or neither does. After a crash, uncommitted work is undone (PostgreSQL ignores it through MVCC and the WAL; InnoDB uses its undo log).
  • Consistency: declared rules hold after every transaction (CHECK (balance >= 0), foreign keys, unique keys). The database enforces only what you declare; other business rules are the app's job.
  • Isolation: concurrent transfers don't see each other's half-done state; the isolation level decides which anomalies can still happen.
  • Durability: once COMMIT returns, the change survives a crash because the log (WAL, or InnoDB's redo log) was flushed to disk. The two settings in follow-up 5 risk losing the last moments of commits on a crash, in exchange for speed.
  • The C in CAP means every reader sees the latest write across replicas, a different idea.
  • UPI: two banks and the NPCI switch, so no single transaction. Each bank does a local transaction; failures are fixed by reversals, timeouts and daily reconciliation, which is a saga.

The red pen

Common traps

Avoid:"consistency means the data is correct"; not knowing how durability is achieved; thinking a distributed payment is one transaction.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview