Pick the fix
A checkout endpoint opens a transaction, reserves stock, calls the payment provider (up to 30 s), then commits. Better design?
Hint 1 of 1
What is the transaction waiting on most of the time?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Reserve stock and commit, call the provider outside any transaction, then confirm or release in a second short transaction
Correct. Locks and snapshots are held for milliseconds, and the reservation state machine handles failures.
A transaction that waits on a slow network call holds its locks and snapshot the whole time. Commit the reservation first, call the provider with no transaction open, then confirm or release in a new one.
Why not the others?
- B Raise statement_timeout to 60 s. Makes the long lock hold official.
- C Use SERIALIZABLE. Still holds the transaction open during the call.
- D Use READ UNCOMMITTED. PostgreSQL treats it as READ COMMITTED, and the problem isn't visibility.