Search GimmeJob

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

What do database transactions and ACID properties mean for testing?

Answer

A transaction groups operations into one unit that commits completely or rolls back, while ACID describes atomicity, consistency, isolation and durability. Test success, expected rejection and a failure between each significant step to prove that partial business state is not left behind. Also verify retry behaviour, duplicate requests, visibility to concurrent sessions, constraints at commit time and durable state after reconnect or recovery.

Strong answer includes

  • explains all four ACID properties
  • injects failures between transaction steps
  • covers concurrency, retries and durable outcomes

Practical example

Atomic multi-step business change
Dialect · Portable SQLRuntime · static example

Requires an inventory table and application/test control over the business invariant.

BEGIN;

UPDATE inventory
SET quantity = quantity - 1
WHERE product_id = 10
  AND quantity > 0;

-- The application/test must assert that exactly one inventory row changed.
-- If zero rows changed, ROLLBACK and do not create the order.

INSERT INTO orders (id, product_id, status)
VALUES (1001, 10, 'created');

COMMIT;

Atomicity prevents a partial commit, but ACID does not prove the business rule by itself. The caller must verify the guarded inventory update succeeded before creating the order, and must roll back when the invariant fails.

Expected result: The order is created only when the guarded inventory update succeeds; otherwise the whole transaction is rolled back.

#database#sql#transactions#acid

Sources

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