⚖️

Transaction Mastery Interview Questions

ACID, isolation levels, locking & MVCC, Spring @Transactional internals, distributed transactions (2PC, Saga, Outbox/CDC), and Kafka transactions — from the bank-counter story to production incident response.

← Learn this topic from scratch first

What Is a Transaction?

Q

Is a single INSERT statement a transaction?

beginner

Yes — most databases wrap every individual statement in an implicit transaction if you haven't started one explicitly (this is called "autocommit mode," covered in Chapter 06). A transaction can contain exactly one operation or hundreds; the concept doesn't require multiple statements.

Q

In your own words, what is a database transaction?

beginner

A group of operations treated as one unit — either all of them succeed, or none of them do.

Q

Give a real-world (non-technical) example of a transaction.

beginner

A bank transfer: debit one account, credit another — both must happen, or neither should.

Q

Why isn't "just do the operations one after another in application code" sufficient?

intermediate

Without a transaction boundary, a crash or concurrent access between steps can leave the system in a partially-updated, inconsistent state that no single step's own error handling can detect or fix.

Q

Can a transaction consist of read-only operations?

advanced

Yes — a multi-step read that needs a consistent view across several queries (e.g. a financial report reading several tables) also needs a transaction, specifically for isolation guarantees (Chapter 04), even though nothing is being written.

Q

When does the "single transaction" mental model stop being applicable at all?

expert

Once a logical business operation spans more than one independently-deployed database or service — at that point you need Saga, Outbox, or 2PC (Chapters 16–18), not a bigger local transaction.

Q

What are the only two possible endings of a transaction?

beginner

COMMIT (all changes take effect) or ROLLBACK (all changes are discarded) — never a partial outcome.

Q

What's the shared shape across the ATM, flight, and shopping examples?

beginner

Multiple steps that must either all succeed together, or leave the system completely unchanged if any one fails.

Atomicity

Isolation & Anomalies

Q

What does isolation control?

beginner

How much of another concurrently running transaction's work is visible to you before it commits.

Q

Order the four isolation levels from weakest to strongest.

intermediate

Read Uncommitted → Read Committed → Repeatable Read → Serializable.

Q

Why does PostgreSQL's Repeatable Read prevent phantom reads, when the SQL standard doesn't require it to?

advanced

PostgreSQL implements Repeatable Read using a single consistent MVCC snapshot taken at the start of the transaction — new rows committed by other transactions simply aren't visible in that snapshot, which incidentally also blocks phantoms, stronger than the standard's minimum requirement.

Q

How would you decide isolation level on a per-operation, not per-application, basis?

expert

Default the application to Read Committed, and explicitly elevate to Repeatable Read/Serializable only for specific operations (financial reports, multi-step invariant checks) where the extra correctness is worth the concurrency cost — isolation level is a per-transaction decision, not a single glob

Q

What's the difference between a dirty read and a non-repeatable read?

beginner

A dirty read sees uncommitted data; a non-repeatable read sees committed data that changed between two reads of the same row within one transaction.

Q

Which isolation level is the default in PostgreSQL?

beginner

Read Committed.

Q

Which isolation level is the default in MySQL/InnoDB?

beginner

Repeatable Read.

Q

Which anomaly does Serializable prevent that Repeatable Read (per the SQL standard) does not?

beginner

Phantom reads.

Locking, MVCC & Deadlocks

Propagation & Isolation in Spring

Transaction Manager Internals

Persistence Context & Dirty Checking

Entity Lifecycle, Caching & Transaction Boundaries

MongoDB Transactions

Why Local Transactions Fail

Two-Phase Commit (2PC)

Saga Pattern

Outbox, Inbox & CDC

Kafka Transactions & Exactly-Once Semantics

System Design with Transactions

Production Engineering

Capstone — A Fault-Tolerant Order-Payment System