Transactions, ACID and Isolation Levels Interview Questions

261 multiple-choice tech interview questions on Transactions, ACID and Isolation Levels: atomicity, consistency, isolation, durability, read anomalies, locking and MVCC, deadlocks. Written for technical phone screens and interview prep, organized by subtopic, with a short explanation for every answer. Learn the 155 key terms with the flashcards first, then test yourself.

Take the practice test · Flashcards · All study tools

What it covers

  1. 4.1 ACID fundamentals
  2. 4.2 Transaction control in SQL
  3. 4.3 Read phenomena and isolation levels
  4. 4.4 Write anomalies and serializability
  5. 4.5 MVCC and snapshot isolation
  6. 4.6 Locking and lock modes
  7. 4.7 Deadlocks, blocking and contention
  8. 4.8 Durability, logging and recovery
  9. 4.9 Transactions in applications and distributed systems

Key terms

4.1 ACID fundamentals

Atomicity
All of a transaction's changes are applied, or none are
Durability
Committed changes survive crashes, usually via a write-ahead log
Two-phase commit
A protocol where a coordinator asks all participants to prepare, then to commit
Transaction
Unit of work
Consistency (ACID)
Declared rules hold
Strict serializability
Serial order plus real time
Serializability
Equivalent to some serial order
Deferred constraint
Checked at commit
Statement atomicity
Each statement all-or-nothing
MyISAM
Non-transactional MySQL engine
Write cache
Can fake durability
Atomic visibility
All or none seen

4.2 Transaction control in SQL

START TRANSACTION
Begins an explicit transaction
Aborted transaction
Further statements fail until ROLLBACK
XACT_ABORT
Roll back on runtime errors
@@TRANCOUNT
Nesting depth of transactions
RELEASE SAVEPOINT
Drop a savepoint, keep its work
Transactional DDL
Schema changes can roll back
Implicit commit
DDL commits open work
XACT_STATE
Committable, uncommittable or none
Idle in transaction
Open transaction doing nothing
Sequence gaps
Values aren't rolled back
COMMIT AND CHAIN
Commit and start a new transaction
Procedure COMMIT
Commit inside CALL
IMPLICIT_TRANSACTIONS
Statements open transactions
SET LOCAL
Transaction-scoped setting
Connection reset
Clean session for next borrower
statement_timeout
Cancel long statements

4.3 Read phenomena and isolation levels

Dirty read
Reading another transaction's uncommitted changes
Non-repeatable read
Rereading a row and getting a different committed value
Phantom read
Rerunning a range query and seeing rows inserted by another transaction
Write skew
Two transactions update different rows based on the same stale read, breaking a rule together
REPEATABLE READ (InnoDB)
MySQL's default level
Oracle SERIALIZABLE
Snapshot isolation
ANSI critique
1995 isolation paper
Read skew
Related rows read at different times
EvalPlanQual
Re-check of updated rows
Locking read
Reads latest rows with locks
Key-range lock
Locks a range of keys
ALLOW_SNAPSHOT_ISOLATION
Enables SNAPSHOT level
Isolation.DEFAULT
Use the database's level
Dirty write
Overwriting uncommitted data
CockroachDB isolation
SERIALIZABLE by default
SQLite isolation
Serializable via single writer

4.4 Write anomalies and serializability

Lost update detection
Concurrent update error
Write skew vs lost update
Different rows vs same row
Materialized conflict
Rows created to lock on
Exclusion constraint
No overlapping values
SSI
Serializable Snapshot Isolation
SQLSTATE 40001
Serialization failure
Two-phase locking
Grow then shrink locks
Actual serial execution
One transaction at a time
Precedence graph
Cycle means not serializable
First-committer-wins
Later writer aborts
ON CONFLICT
Atomic upsert
MERGE HOLDLOCK
Race-free upsert
Hot row
One row every writer needs
Predicate lock
Lock on a search condition

4.5 MVCC and snapshot isolation

xmin / xmax
Creating and replacing transaction IDs
Dead tuple
Row version no snapshot needs
VACUUM
Reclaims dead row versions
Autovacuum
Automatic vacuum daemon
Bloat
Wasted space from dead rows
XID wraparound
32-bit transaction IDs run out
VACUUM FULL
Rewrites the table, exclusive lock
HOT update
No new index entries needed
Undo log
Old row versions
Version store
Row versions for snapshots
ADR
Persistent version store
RCSI vs SNAPSHOT
Statement vs transaction snapshot
ORA-01555
Snapshot too old
Consistent snapshot
Snapshot taken now
Hot standby conflict
Replica query canceled
pg_export_snapshot
Share a snapshot across sessions
Replication slot
Retains WAL for a consumer
AS OF SYSTEM TIME
Time-travel reads
Update conflict
Error 3960

4.6 Locking and lock modes

MVCC
Multiversion concurrency control: readers see a snapshot while writers create new versions
Deadlock
Transactions waiting on each other's locks in a cycle; the engine kills one
Optimistic concurrency
Detecting conflicts at write time with a version check instead of holding locks
Shared lock
Compatible with other shared locks
Exclusive lock
Conflicts with everything
Intent lock
Table-level signal of row locks
Update lock
Prevents conversion deadlocks
FOR SHARE
Blocks changes, allows sharing
FOR KEY SHARE
Foreign key check lock
NOWAIT
Fail instead of waiting
Next-key lock
Record plus gap
Lock queue
Waiters block later requests
lock_timeout
Limit lock waits
Advisory lock
App-defined lock
Latch
Short in-memory protection
pg_locks
Current locks
ALGORITHM=INSTANT
Metadata-only ALTER
ACCESS SHARE
Lock taken by SELECT
Pessimistic offline lock
App-level checkout

4.7 Deadlocks, blocking and contention

Deadlock victim
Transaction rolled back to break a cycle
DEADLOCK_PRIORITY
Choose who loses
deadlock_timeout
Wait before deadlock check
innodb_deadlock_detect
Toggle detection
system_health
Built-in deadlock capture
LATEST DETECTED DEADLOCK
InnoDB status section
log_lock_waits
Log long lock waits
Head blocker
Root of a blocking chain
pg_blocking_pids
Who blocks a session
Key lookup deadlock
Index access order conflict
Last-page insert contention
Hot page with sequential keys
pg_terminate_backend
End a session
KILL rollback
Locks held until undone
innodb_lock_wait_timeout
Lock wait limit
Batched deletes
Short transactions for purges
Partition drop
Fast bulk removal
Orphaned transaction
Left open after a client timeout

4.8 Durability, logging and recovery

Steal / no-force
Buffer policy needing undo and redo
ARIES
Analysis, redo, undo
Checkpoint
Bounds recovery work
Full-page writes
Torn page protection
Group commit
One flush for many commits
synchronous_commit
Commit durability trade-off
innodb_flush_log_at_trx_commit
Redo flush policy
sync_binlog
Binlog durability
Redo log
Reapply changes
LSN
Log position
Page LSN
Makes redo idempotent
CLR
Compensation log record
fsyncgate
Panic on fsync failure
Data checksums
Detect page corruption
Error 9002
Transaction log full
Delayed durability
Early commit acknowledgment
SQLite WAL mode
Readers continue during writes
Physical vs logical logging
Pages vs rows
UNLOGGED table
No WAL, emptied after crash
Doublewrite buffer
Torn page protection
Copy-on-write B-tree
Crash safety by new pages
Commit record
The durable commit point
VLF
Virtual log file
innodb_force_recovery
Emergency startup

4.9 Transactions in applications and distributed systems

Prepare vote
Durable promise to commit
XA
Standard 2PC interface
Prepared transaction
Survives restarts, holds locks
Replicated coordinator
Non-blocking 2PC
REQUIRES_NEW
Suspend and start a new transaction
rollbackFor
Roll back on checked exceptions
TransactionScope
Ambient transaction
Async flow option
Transaction across awaits
Unknown commit outcome
Connection lost after COMMIT
Semantic lock
Status flag for saga isolation
Pivot transaction
Point of no return
TCC
Try, confirm, cancel
Reservation
Time-limited hold
Transaction pooling
Connection per transaction
Chunked commits
Restartable batch jobs
Heuristic outcome
Participant decides alone
defer tx.Rollback
Always clean up
After-commit hook
Side effects after commit

Sample practice questions

  1. A bank transfer debits one account and credits another. The server crashes after the debit. Which ACID property guarantees the debit is rolled back?

    1. Consistency
    2. Isolation
    3. Atomicity
    4. Durability

    Answer: C. Atomicity Atomicity means all of a transaction's changes are applied, or none are.

  2. What does SAVEPOINT allow inside a transaction?

    1. Committing part of the transaction early, before the rest
    2. Saving the whole transaction so it can be run again later
    3. Rolling back to a named point without abandoning the transaction
    4. Switching the rest of the transaction to read-only mode

    Answer: C. Rolling back to a named point without abandoning the transaction `ROLLBACK TO SAVEPOINT` undoes work after the savepoint; the outer transaction can still commit.

  3. Transaction A reads a row that transaction B has changed but not committed; B then rolls back. What anomaly is this?

    1. A non-repeatable read
    2. A phantom read
    3. A dirty read
    4. A lost update

    Answer: C. A dirty read Dirty reads are only possible at READ UNCOMMITTED.

  4. Two users read a stock count of 10, each subtracts 1 in application code and writes 9. The correct result is 8. What is this anomaly?

    1. A phantom read
    2. A dirty read
    3. A deadlock
    4. A lost update

    Answer: D. A lost update Fix it with an atomic `UPDATE ... SET stock = stock - 1`, `SELECT ... FOR UPDATE`, or optimistic concurrency with a version column.

  5. What does snapshot isolation guarantee?

    1. Every transaction runs strictly one at a time, in a single queue
    2. Reads always see the latest uncommitted changes from other sessions
    3. Writers block all readers until they commit or roll back
    4. Reads see a consistent snapshot from the start; conflicting writes fail

    Answer: D. Reads see a consistent snapshot from the start; conflicting writes fail Snapshot isolation prevents dirty reads, non-repeatable reads and phantoms but can still allow write skew.

  6. What does `SELECT ... FOR UPDATE` do?

    1. Updates every row that the SELECT returns
    2. Reads the rows' uncommitted data instead
    3. Creates an index to speed up future updates
    4. Locks the selected rows until this transaction ends

    Answer: D. Locks the selected rows until this transaction ends It is pessimistic locking. SKIP LOCKED lets job-queue workers grab unlocked rows without waiting.

  7. What is a deadlock?

    1. A query that keeps running past its configured timeout
    2. A table that an administrator has locked for maintenance
    3. Transactions each hold a lock the other needs, so none proceed
    4. A transaction that's left open and never commits

    Answer: C. Transactions each hold a lock the other needs, so none proceed The engine detects the cycle and kills one transaction as the victim. The application should retry it.

  8. What is a write-ahead log (WAL)?

    1. A cache holding the results of recently executed queries
    2. Changes logged durably before data pages, replayable after a crash
    3. A queue of database users who are waiting to write
    4. A log that records every query slower than a threshold

    Answer: B. Changes logged durably before data pages, replayable after a crash WAL (called the transaction log in SQL Server and the redo log in MySQL) underpins durability, crash recovery and replication.

  9. Why is a distributed transaction across two databases harder than a local one?

    1. SQL statements can't reference objects in more than one database at all
    2. Distributed transactions skip durability, so committed data can be lost
    3. Both databases must come from the same vendor and run the same version
    4. Both must agree via two-phase commit, which blocks if the coordinator fails

    Answer: D. Both must agree via two-phase commit, which blocks if the coordinator fails Microservices usually avoid two-phase commit and use sagas with compensating actions instead.

  10. Which ACID property guarantees that a committed transaction survives a power failure?

    1. Atomicity
    2. Isolation
    3. Durability
    4. Consistency

    Answer: C. Durability Durability is usually achieved with a write-ahead log flushed to disk before the commit is acknowledged.

Practice all 261 questions

More Storage and Data