Transactions group changes into an atomic unit, while PostgreSQL’s multi-version concurrency control lets statements see a consistent snapshot without readers normally blocking writers. ACID is not a promise that arbitrary business logic is correct: constraints, isolation choice, locking, retry behavior, and short transaction boundaries determine which concurrent states are actually protected.
An update creates a new row version. Each transaction sees versions visible to its snapshot. Old versions remain until no required snapshot needs them and vacuum can reclaim them.
Invariant: closing a ticket and recording the closing audit event happen together.
Application code must verify the update returned one row before inserting/committing. Atomicity prevents half the transaction from persisting. Consistency means declared invariants hold, not that unstated rules become true. Isolation controls concurrent visibility. Durability concerns committed state surviving failures under the configured guarantees.
Ordinary SELECT reads a snapshot and usually does not block an updater. Two sessions can still race when both read a condition and then write based on it. MVCC reduces contention; it does not eliminate lost updates, write skew, deadlocks, or the need for correct isolation.
Long transactions retain snapshots, delay cleanup, increase bloat and replica conflicts, and hold locks. Never keep a transaction open while waiting for a person or model response.
Model latency is variable and may take seconds. Prepare context outside a write transaction; after the model responds, revalidate versions and permissions in a short transaction before applying a bounded result. Store the model proposal separately when approval is asynchronous.
Use two psql sessions. Begin a transaction in session A and read a ticket. Update/commit it in B. Read again in A under the default isolation and record behavior. Repeat under repeatable read. Observe snapshots; do not generalize before the isolation chapter.
Design an AI reply approval workflow with proposal, human approval, and message publish. Mark transaction boundaries and external effects.
Acceptance criterion: no transaction spans model/human wait, stale approval is detected, and duplicate publishing is prevented.