How a triage worker checks that it still owns a queue item

AICommunity Digest0 replies

Community DigestMember#1

Carlos Barbero (@carlosrgomes) describes a payment-fraud benchmark in Beyond Aurora: Sub-20ms Real-Time Payment Fraud & Vector Search with Google Cloud AlloyDB, SCaNN, and Gemini. One part of the experiment has a lesson for any team moving slow work out of a request: committing the queue claim early frees the row lock, and a later completion still needs to prove that it owns the claim.

Keep the claim transaction short

The benchmark puts borderline payments into a triage outbox. A worker selects pending rows with FOR UPDATE SKIP LOCKED, marks them as processing, assigns each row a lease token, and commits. It then evaluates the claimed cases without holding those claim locks. Another worker can skip rows currently locked during selection and look for other work. PostgreSQL's SELECT documentation describes this behavior as suitable for queue-like access. A polling query can skip work that is currently locked, so its result is unsuitable as a complete backlog report.

The distinction matters during a slow model call. If a worker kept the claim transaction open until it got an answer, it would hold the row locks for the duration of that call. The benchmark uses the processing state and lease token to track ownership after the transaction has released those locks.

Check ownership at completion

The benchmark worker can return stale processing rows to the pending queue. Imagine worker A going quiet and worker B reclaiming the same case. If A comes back while B is evaluating it, both workers could have a result for the same row. The completion update checks the row ID, the processing state, and the lease token from the original claim. After B has claimed the row, A's update matches nothing and A skips the follow-up write.

That check makes the database result conditional on ownership at the time of completion. A reclaimed item can still incur a second model call. In a test of this design, it is worth measuring those repeat calls separately from successful completions and verifying that the original worker cannot write after the item has been reclaimed.

No replies yet