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
- 4.1 ACID fundamentals
- 4.2 Transaction control in SQL
- 4.3 Read phenomena and isolation levels
- 4.4 Write anomalies and serializability
- 4.5 MVCC and snapshot isolation
- 4.6 Locking and lock modes
- 4.7 Deadlocks, blocking and contention
- 4.8 Durability, logging and recovery
- 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
A bank transfer debits one account and credits another. The server crashes after the debit. Which ACID property guarantees the debit is rolled back?
- Consistency
- Isolation
- Atomicity
- Durability
Answer: C. Atomicity Atomicity means all of a transaction's changes are applied, or none are.
What does SAVEPOINT allow inside a transaction?
- Committing part of the transaction early, before the rest
- Saving the whole transaction so it can be run again later
- Rolling back to a named point without abandoning the transaction
- 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.
Transaction A reads a row that transaction B has changed but not committed; B then rolls back. What anomaly is this?
- A non-repeatable read
- A phantom read
- A dirty read
- A lost update
Answer: C. A dirty read Dirty reads are only possible at READ UNCOMMITTED.
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?
- A phantom read
- A dirty read
- A deadlock
- 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.
What does snapshot isolation guarantee?
- Every transaction runs strictly one at a time, in a single queue
- Reads always see the latest uncommitted changes from other sessions
- Writers block all readers until they commit or roll back
- 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.
What does `SELECT ... FOR UPDATE` do?
- Updates every row that the SELECT returns
- Reads the rows' uncommitted data instead
- Creates an index to speed up future updates
- 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.
What is a deadlock?
- A query that keeps running past its configured timeout
- A table that an administrator has locked for maintenance
- Transactions each hold a lock the other needs, so none proceed
- 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.
What is a write-ahead log (WAL)?
- A cache holding the results of recently executed queries
- Changes logged durably before data pages, replayable after a crash
- A queue of database users who are waiting to write
- 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.
Why is a distributed transaction across two databases harder than a local one?
- SQL statements can't reference objects in more than one database at all
- Distributed transactions skip durability, so committed data can be lost
- Both databases must come from the same vendor and run the same version
- 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.
Which ACID property guarantees that a committed transaction survives a power failure?
- Atomicity
- Isolation
- Durability
- Consistency
Answer: C. Durability Durability is usually achieved with a write-ahead log flushed to disk before the commit is acknowledged.
More Storage and Data
- Relational Database Design and Normalization
- SQL Queries, Joins and Window Functions
- Indexing and Query Optimization
- NoSQL Databases: Document, Key-Value, Wide-Column and Graph
- Caching: Redis, CDNs and Cache Invalidation
- ORMs: Entity Framework Core and Hibernate
- Data Warehousing and ETL
- Message Queues and Event Streaming: Kafka, RabbitMQ and Service Bus
- Blob and Object Storage
- Backups, Replication and Disaster Recovery