Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
Databases, SQL & BIDatabase conceptSeniorCommonTheory

Which concurrency anomalies do transaction isolation levels try to prevent?

Answer

Isolation levels address anomalies such as dirty reads, non-repeatable reads, phantom reads and lost-update/write-skew patterns, with exact guarantees varying by DBMS. A serialization failure is typically a DBMS response when an execution cannot be made consistent with the requested serializable semantics, rather than another read anomaly. Test with controlled concurrent sessions, barriers, retries and assertions on the business invariant.

Strong answer includes

  • names concrete concurrency anomalies
  • uses deterministic multi-session tests
  • checks product-specific guarantees and retries

Practical example

Two-session non-repeatable-read experiment
Dialect · DBMS-dependentRuntime · static example

Requires two concurrent database sessions and an explicitly configured isolation level.

-- Session A
BEGIN;
SELECT balance FROM accounts WHERE id = 1;
-- pause here
SELECT balance FROM accounts WHERE id = 1;
COMMIT;

-- Session B, during the pause
BEGIN;
UPDATE accounts SET balance = balance + 100 WHERE id = 1;
COMMIT;

Run the statements with a deliberate barrier between Session A reads. What Session A observes depends on the configured isolation level and the database's MVCC/locking implementation, so the test should assert the business invariant rather than only the isolation-level label.

Expected result: Observation differs by isolation level; the test records whether the second read may see Session B's committed change.

#database#transactions#isolation#concurrency

Sources

PostgreSQL documentationPostgreSQL Global Development Group · Relational modelling, SQL, joins, constraints, transactions, concurrency, indexes, query plans and recovery