A ticket-creation request reaches the receiver. The receiver creates ticket 72, but the response never returns to the worker. A new identifier generated inside the retry loop tells the receiver that the next request is a different operation.
Create an operation ID when the user or workflow commits to the logical action. Persist that ID and a description of the intended effect before the first attempt can leave the process. Restoring the worker after a crash must recover the same ID. Two separate intentions to create otherwise identical tickets should still receive distinct IDs. Deriving the ID solely from the ticket text would merge legitimate work.
What the receiver has to promise
A receiver that supports idempotency defines a scope and a retention period for its keys. Within that scope, it must associate a key with its original parameters and handle a concurrent duplicate without creating two tickets. An application you control might enforce a unique operation ID in the same database transaction as creating the ticket. A provider you do not control may offer different guarantees. Check what happens while the first attempt is in progress, when arguments change, and after the key expires.
For a small test, make a fake receiver create the ticket and discard its first response. Restart the caller from persisted state. Replay the same logical operation and inspect the receiver’s count of tickets. Then issue a new logical operation with the same text and expect another ticket. Finally change the original operation’s target while keeping its ID: the request should be rejected rather than attached to the wrong result.
A local “sent” flag only tells you what your worker attempted. If the receiver offers no durable deduplication and no authoritative way to look up the operation, keep an interrupted write pending reconciliation. Retrying until an acknowledgment arrives cannot tell you how many effects came before it.
Test the receiver after a lost acknowledgment
Record the ticket count at the fake receiver before starting. After the response-loss replay of the same intent, expect the count to rise by exactly one. After the independent second intent with identical text, expect it to rise by two from the original count. Repeat the first ID with changed parameters: expect a conflict and no change in the count. Check the IDs as well as the totals.
This article was created with AI assistance.
Top comments (0)