Idempotency Keys for Agent Actions
In this article
- Build an idempotency key from the run, the step and the operation, and say why an attempt number or a timestamp breaks it.
- Predict what a service does with an identical retry, a retry with a changed payload and a duplicate that arrives late.
- Choose how long a deduplication record must live, given how long a request can be delivered again.
- Explain where duplicates are caught: in the provider's record and in your own action table.
- Terms defined here: idempotency key, payload hash, deduplication record.
Overview
A request that may be sent twice needs a name that stays the same both times. Take a made-up support agent's run that refunds 49.00 EUR on order 1042 after a manager approves it; when the payment provider's answer goes missing, the code running the agent sends the refund again, tagged with the same action id, r-7f3:3:refund. That string is what stops a second refund.
It only works if three things are right: what goes into the string, what is stored beside it, and how long the provider remembers it. You will build the key, attach a fingerprint of the request to it, and predict what happens to an identical retry, a retry with a different amount, and a copy that arrives days later. Then you can design a key for any agent action and say where it would fail.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- What goes into the key
- Binding the key to the payload
- Three retries, three outcomes
- How long to remember
- Two places that check
- Common mistakes
- In production
- Sources
- Check yourself, 13 questions