Idempotency
An API call or operation is “idempotent” if it has the same result when called more than once.
We currently support idempotency at the task level, meaning that if you trigger a task with the same idempotencyKey
twice, the second request will not create a new task run.
idempotencyKey
option
You can provide an idempotencyKey
to ensure that a task is only triggered once with the same key. This is useful if you are triggering a task within another task that might be retried:
You can use the idempotencyKeys.create
SDK function to create an idempotency key before passing it to the options
object.
We automatically inject the run ID when generating the idempotency key when running inside a task by default. You can turn it off by passing the scope
option to idempotencyKeys.create
:
If you are triggering a task from your backend code, you can use the idempotencyKeys.create
SDK function to create an idempotency key.
You can also pass a string to the idempotencyKey
option, without first creating it with idempotencyKeys.create
.
You can pass the idempotencyKey
when calling batchTrigger
as well:
Payload-based idempotency
We don’t currently support payload-based idempotency, but you can implement it yourself by hashing the payload and using the hash as the idempotency key.
Important notes
Idempotency keys, even the ones scoped globally, are actually scoped to the task and the environment. This means that you cannot collide with keys from other environments (e.g. dev will never collide with prod), or to other projects and orgs.
If you use the same idempotency key for triggering different tasks, the tasks will not be idempotent, and both tasks will be triggered. There’s currently no way to make multiple tasks idempotent with the same key.