Verify a transaction answer against the business invariant it claims to protect. Individually atomic transactions can still produce an invalid combined result when concurrent execution permits each transaction to act on an older shared state.
Build an interleaving history with read sets, write sets, commit outcomes and an invariant evaluation. This is a source-to-answer test of a concurrency guarantee, not another tutorial showing BEGIN and COMMIT or a claim that every database permits the same history.
State the invariant before naming an isolation level
An invariant is the condition the business requires across the relevant data. It may involve several rows even when each operation changes only one. Record that condition explicitly rather than assuming successful commits establish it.
PostgreSQL's transaction-isolation documentation distinguishes isolation levels and describes serialization anomalies. It defines such an anomaly as a committed concurrent result inconsistent with all possible one-at-a-time orderings. Its Serializable discussion also explains the need to handle serialization failures.
Those are scoped database semantics. The hypothetical trace below specifies its own permitted model and does not report an executed PostgreSQL test or establish behavior for every client and configuration.
Freeze a complete two-record fixture
Assume two fictional duty records, A and B, both initially on call. The business rule is that at least one remains on call: A or B must be true. Each transaction lets one person leave only if the other is currently on call.
Transaction T1 reads the initial state and plans to set A false because it sees B true. Transaction T2 independently reads the same initial state and plans to set B false because it sees A true. The model permits both snapshots and both nonconflicting-row writes to commit.
These are teaching assumptions, not healthcare instructions or a real staffing process. No personal records, production database or external action is involved.
Populate the concurrent history
| Step | T1 | T2 | Committed State |
|---|---|---|---|
| Initial | Not started | Not started | A true; B true |
| Read snapshots | Reads A true, B true | Reads A true, B true | A true; B true |
| Plan writes | Sets A false in its transaction | Sets B false in its transaction | Initial committed values remain |
| T1 commits | A false committed | Retains its earlier read of A true | A false; B true |
| T2 commits | Complete | B false committed | A false; B false |
The final invariant is false: neither record remains on call. Each transaction's own write can be atomic, with no partial commit. Atomicity alone therefore does not establish the broader cross-record guarantee in this declared model.
The absence of both transactions writing the same row is not proof that their business effects are independent. Each decision reads the row that the other changes.
Compare both serial reference orders
Run T1 completely before T2 in a separate reference history. T1 sees B true and sets A false. T2 then sees A false and declines to leave. The final state is A false, B true, which satisfies the invariant.
Reverse the order. T2 sets B false while A is true. T1 then sees B false and declines to leave. The final state is A true, B false, which also satisfies the invariant.
First verify that the transaction logic preserves the invariant in the serial reference histories. If each transaction simply cleared its own flag without checking the other, even one-at-a-time execution could reach false/false. Stronger isolation cannot repair an application rule that already fails its serial specification.
Neither permitted serial outcome is false/false. That comparison supplies the exact obstruction rather than merely labeling the concurrent result surprising. The same transaction logic behaves differently because its observations are ordered differently.
Separate atomicity, isolation and durability
Atomicity concerns each transaction's all-or-nothing boundary. Isolation constrains how concurrent transactions interact. Durability concerns persistence of committed results. Preserving one property does not automatically establish the others or every application invariant.
The transaction-state tutorial checks starting, committed and rolled-back values for a single teaching transfer. Its explicit concurrency limitation matters: that acceptance record cannot verify the interleaving claim here.
Likewise, replicating the false/false state durably would not repair the invariant. A correct read of the final committed values can faithfully expose an invalid business outcome.
Verify whether the actual source permits the trace
Before classifying a real answer, identify the database version, isolation level, transaction boundaries, constraints and exact operations. A source may forbid this history, abort one transaction or enforce the invariant through another documented mechanism.
Do not claim that a named product permits the fixture merely because it offers transactions or a broadly familiar isolation label. Conversely, do not claim that a transaction keyword guarantees serial behavior without inspecting its actual contract.
If the source does not establish the relevant concurrency semantics, the stronger answer remains unverified. The fictional counterexample proves that the inference from atomic to invariant-safe is invalid in general; it does not diagnose an uninspected deployment.
Treat an aborted transaction as a different outcome
A serialization failure can prevent both transactions from committing in the illustrated arrangement. Preserve that abort and the required recovery behavior instead of reporting it as a successful false/false commit.
PostgreSQL's documentation says applications using Serializable must be prepared for serialization failures and retries. A correct public explanation should not promise that choosing a stronger mode eliminates every application responsibility or guarantees that each initial attempt succeeds.
This article does not prescribe a live migration or a blind retry loop. Any operational remedy needs the actual client, side-effect boundary and authorized implementation review.
Preserve the whole decision record
Record each transaction's observed values, intended mutation and final outcome. A log containing only the two final writes omits the older reads that explain why each decision appeared permissible at the time.
The audit reconstruction guide can preserve attempt and commit identities. Keep missing read evidence unresolved rather than inventing a snapshot to explain a surprising result.
Use the worked-example review to reproduce the Boolean states and serial alternatives. The relevant check is logical consistency, not a statistical error rate or measured database benchmark.
Release an invariant-matched answer
The final artifact should contain the invariant, initial state, transaction logic, allowed interleaving, both serial references, source contract and exact verdict. Use the source record for the actual isolation evidence and its limits.
A supported answer explains which mechanism protects the invariant or identifies the missing guarantee. It does not use a successful commit, durable write or transaction label as a substitute for the concurrency relationship the business rule requires.
