ACID, isolation and MVCC
31 questions in 11 subtopics.
ACID properties
Explain each letter of ACID for a relational database and give, for each one, a concrete example of what goes wrong in a money transfer between two accounts if that property is missing.An order service writes the order row to PostgreSQL in a@Transactional method and then publishes an OrderCreated event to Kafka inside the same method. In production some events refer to orders that do not exist, and some orders never get an event. Explain why ACID does not help here and how you would fix it.Your company runs core ledgers on a relational database, and several product teams now propose moving to stores that offer weaker guarantees for scale and cost. How do you decide, at company level, which data needs full ACID transactions and what guarantees you accept elsewhere?Write-ahead logging
What is write-ahead logging, and how does it let a database such as PostgreSQL promise durability without writing every changed data page to disk at commit time?A PostgreSQL 17 primary runs out of disk. The pg_wal directory has grown to 400 GB while max_wal_size is 4 GB. Which causes do you check, with which queries, and how do you recover safely?Different teams set PostgreSQL synchronous_commit, MySQL innodb_flush_log_at_trx_commit and replica acknowledgement differently, and after a failover one team lost a few seconds of committed payments. Design a durability standard for databases across the company.Dirty, non-repeatable and phantom reads
Define dirty reads, non-repeatable reads and phantom reads with a short example of each, and say which standard isolation level is the first to prevent each one.Two PostgreSQL sessions run at READ COMMITTED on tableaccount(id int primary key, balance int) with id 1 balance 100. Session A:BEGIN;
SELECT balance
FROM account
WHERE id = 1;
UPDATE account
SET balance = 50
WHERE id = 1;
SELECT balance
FROM account
WHERE id = 1;
findById, check quantity >= requested, then save the entity with quantity - requested, all in one @Transactional method on PostgreSQL READ COMMITTED. Under load the stock goes negative in reports. Explain the anomaly and give three fixes with their trade-offs.Write skew
A hospital rule says at least one doctor must stay on call per shift. Two doctors who are both on call press 'go off call' at the same moment. Each transaction runs SELECTcount(*) FROM on_call WHERE shift_id = 7 AND on_call = true, sees 2, and updates its own row to false. Both commit at PostgreSQL REPEATABLE READ. Explain why this is possible and how to prevent it.Your platform has dozens of services on PostgreSQL READ COMMITTED, and incident reviews show several write skew bugs: double-booked rooms, overlapping discount campaigns, and two primary addresses per customer. Define an approach that teams can follow to find and prevent this class of bug.MVCC
How does PostgreSQL implement MVCC at the row level? Explain xmin, xmax, snapshots, and why an UPDATE leaves a dead tuple behind.A PostgreSQL table with heavy updates grows from 5 GB to 80 GB in a week, queries slow down, and autovacuum runs constantly but removes few tuples. pg_stat_activity shows a session in state 'idle in transaction' that started six days ago. Explain the link and what you change.You own the database platform for 300 PostgreSQL clusters. Bloat, wraparound warnings and vacuum-related incidents keep recurring. Design the operating model for MVCC housekeeping across the fleet.Snapshot isolation
What exactly does snapshot isolation guarantee and what does it not? Relate it to PostgreSQL REPEATABLE READ, Oracle SERIALIZABLE and MySQL InnoDB REPEATABLE READ.After moving a batch job's transactions to PostgreSQL REPEATABLE READ to get consistent reports, the nightly job that also updates a status column fails intermittently with 'ERROR: could not serialize access due to concurrent update'. The team proposes going back to READ COMMITTED. What do you recommend?Most distributed SQL and cloud databases advertise snapshot isolation or serializable as their default, while traditional databases default to READ COMMITTED. As a senior technical leader choosing a database direction for the next decade, how do you weigh isolation guarantees against latency and cost?Serializable isolation
How does Serializable Snapshot Isolation (SSI) in PostgreSQL detect anomalies? Explain SIRead locks, rw-antidependencies and why some transactions abort even though no real anomaly happened.Write a Spring Boot service method that books a seat under PostgreSQL SERIALIZABLE isolation and retries on serialization failures up to three times. Explain where the retry must sit and which exceptions to catch.An architecture group proposes making SERIALIZABLE the default isolation for all new PostgreSQL-backed services so that developers stop reasoning about anomalies. Evaluate the proposal and describe how you would roll it out if you agree.Twenty years ago most enterprise applications relied on database locks and READ COMMITTED; today many teams use ORMs, microservices and distributed databases. How should a company's engineering standards on transaction isolation change, and how do you make sure the standard is followed?Two-phase locking
What is two-phase locking (2PL), how does strict 2PL differ from basic 2PL, and why does it guarantee serializable schedules? Do not confuse it with two-phase commit.A PostgreSQL service logs 'ERROR: deadlock detected' (SQLSTATE 40P01) several times an hour. The detail shows two transactions each updating rows in the accounts table for a transfer between the same two accounts in opposite directions. Explain the cause and the fixes.Lock-based concurrency control dominated databases for decades and was then largely replaced by MVCC with optional locking. Explain why the ecosystem moved, and what this history means for how your organisation should design contention-heavy systems today.Savepoints
In PostgreSQL an insert in the middle of a transaction fails with a unique violation, and every following statement fails with 'current transaction is aborted, commands ignored until end of transaction block'. Show with SQL and with plain JDBC how a savepoint lets you continue the transaction.How does Spring'sPropagation.NESTED use savepoints, how does it differ from REQUIRES_NEW, and what pitfalls exist when using it with JPA and Hibernate?Autocommit
A plain JDBC method updates the orders table and then inserts into order_audit. The insert fails, but the order update is still in the database. The code never callssetAutoCommit. Explain what happened and fix the code.Your Spring Boot JPA service sets spring.datasource.hikari.auto-commit=false and spring.jpa.properties.hibernate.connection.provider_disables_autocommit=true. What do these settings change, what is the benefit, and what can break?Isolation defaults by database
What is the default transaction isolation level in PostgreSQL, MySQL InnoDB, Oracle and SQL Server, and what does Spring'sIsolation.DEFAULT mean?Your company is migrating 25 services from MySQL 8.4 to PostgreSQL 17. Code reviews show that teams never set isolation explicitly. Which behaviour changes do you expect because of different isolation defaults and locking, and how do you manage the risk?Engineers across your organisation assume the database default isolation level is safe because it is the default. As head of engineering, how would you set policy for isolation levels across many teams and several database products?No question matches these choices.