Two robot-cell services each reserve a different item from the same recorded stock. Both receive successful database responses, yet the final quantity reflects only one reservation. The problem can occur without a duplicate network request: two distinct operations can overwrite one another when they calculate replacement values from the same earlier read.
The following inventory is hypothetical. It explains one concurrency problem using PostgreSQL 18's documented Read Committed behavior. It is not an executed database experiment, a production migration, or evidence that a physical bin contains the recorded quantity.
Specify the business operation
Let one inventory row describe bin B7 with available quantity 10. Service A intends to reserve one item. Service B independently intends to reserve another item. If both reservations are accepted, the intended final quantity is 8.
These are separate reservations, each requested once. Their identities are assumed distinct and valid throughout. Duplicate-request detection would answer a different question from whether two legitimate updates preserve both decrements.
Suppose each service implements its operation as an ordinary read followed by a replacement assignment. It reads the available value, subtracts one in application memory, and later writes that computed number back into the row. The write identifies the bin, but does not check whether the earlier value has changed.
An original interleaving loses one decrement
First A reads 10. Before A writes, B also reads 10. Both application processes calculate the replacement value 9.
A assigns available = 9 to B7 and commits. B then assigns available = 9 to the same row and commits. The stored result is 9, although two reservations were accepted by the hypothetical application.
No individual subtraction was wrong. Both calculated 10 minus one correctly. The problem is that B's assignment describes a value computed from an obsolete observation. It does not describe a fresh decrement of the row that now contains 9.
The final value is consistent with either assignment considered alone. It is inconsistent with the stated combined business effect of reserving two items. A successful write response therefore does not establish that all concurrent intentions survived.
A transaction boundary alone does not change the stale expression
Wrapping each read and write in its own transaction does not, by itself, change the sequence above under the specified Read Committed assumptions. An ordinary SELECT does not lock the selected row against another transaction's update for the duration of that business calculation.
PostgreSQL's isolation documentation states that a normal Read Committed query sees committed data as of the command's start. Its update behavior can wait for a concurrent updater and then operate on the updated row. That does not make an application-supplied constant magically become a relative decrement.
If B's statement still says to assign the constant 9, waiting for A to commit can leave it assigning 9 afterward. The database has serialized the conflicting row writes, but the application expressed the second intended change incorrectly for that interaction.
Express the relative change at the row update
For this simple single-row model, compare an update whose assignment is available = available − 1, restricted to bin B7. The expression refers to the row being updated rather than to a previously copied application value.
If A decrements 10 to 9 and commits, B's qualifying concurrent update can proceed against that updated row and decrement 9 to 8 under the documented Read Committed behavior. Both relative changes are retained in this stated case.
This is not a guarantee for arbitrary multirow queries or isolation levels. The example holds the target row, operation, and database semantics fixed. A more complex invariant needs a model covering all rows and decisions that participate in it.
Make availability part of the same decision
Now begin with only one available item. A separate precheck that sees available greater than zero can become stale before a later write. Two services can both pass such a precheck against the same original quantity.
An alternative single-row statement combines the decrement with a condition that available is at least one. Under the specified PostgreSQL behavior, a waiting updater rechecks its row condition after the first updater commits.
If A changes one to zero, B's rechecked condition no longer qualifies. B must inspect the actual result, such as the affected-row count or returned row, and report that its reservation was not accepted. A statement that changes zero rows is not evidence of a successful reservation.
This handles the declared single-row availability rule. It does not decide whether a container is physically accessible, whether another inventory system agrees, or whether a robot successfully collected anything.
A locking read provides another declared boundary
When an application must inspect the row before calculating a more involved change, a locking read such as SELECT FOR UPDATE can make that inspection part of a protected transaction. PostgreSQL documents that conflicting writers and lockers wait until that transaction ends.
The useful order is to obtain the protected current row, make the decision from that row, update it, and finish the same transaction. Reading without protection first and acquiring a lock only after calculating from stale data does not automatically validate the earlier decision.
Locking also has costs and scope. Other sessions can wait, and multiple-row interactions can deadlock. PostgreSQL documents that detected deadlocks can abort a transaction. An application must handle its actual outcome rather than treat waiting or a submitted statement as completion.
Keep the invariant and evidence together
Serializable isolation, explicit row locks, relative updates, and conditional writes are different tools with different contracts. Naming one is not enough to establish every inventory invariant. The relevant question is which decision must remain valid while which data can change.
For the small example, the difference is concrete: two writes of a stale replacement value leave 9; two accepted relative decrements leave 8. Keeping that operation semantics visible makes database success easier to relate to the business effect, while leaving physical stock reconciliation as a separate source of evidence.
Sources checked October 23, 2026
PostgreSQL 18 documentation, Transaction Isolation, Read Committed:
https://www.postgresql.org/docs/18/transaction-iso.html
PostgreSQL 18 documentation, Explicit Locking, row-level locks and deadlocks:
https://www.postgresql.org/docs/18/explicit-locking.html
All bins, quantities, services, and operation sequences are original hypothetical examples. No database statements were executed against an inventory system.
Illustration note: The accompanying robot-and-computer scene is a generic concept illustration. It does not show a deployed inventory service, accepted reservation, or verified physical stock.