ConceptsIdempotency

Idempotency

Retry writes safely with Idempotency-Key.

Writes that start durable work or platform side effects require an idempotency key, so a retried request never publishes twice:

  • POST /v1/backfill-requests
  • POST /v1/connections
  • POST /v1/profiles
  • POST /v1/event-destinations/{eventDestinationId}/retry
  • POST /v1/media
  • POST /v1/publish-requests
  • POST /v1/sandbox/profiles/{profileId}/content/{collection}
  • PATCH /v1/sandbox/profiles/{profileId}/content/{collection}/{externalId}
  • DELETE /v1/sandbox/profiles/{profileId}/content/{collection}/{externalId}

Every other POST on a Koil resource (creating an App, Connect Session or Event Destination, rotating a secret, retrying one event's delivery, cancelling a publish request) accepts the same header without requiring it. Send one to make a retry of that request safe; without one, each request runs.

Send it as a header:

Idempotency-Key: 5b0e7d8e-6f6a-4c55-9d3e-2f1c9a0b7e41

Use a fresh unique value (a UUID is fine) for each logical request, and reuse it only to retry that same request. Each endpoint that takes the header says whether it requires it in the API endpoints reference.

Behavior

A key is scoped to your Organization and the operation. The same key may be used for a different operation, but not for a different payload on the same one.

You sendKoil answers
The same key and payload, after the first request succeededThe first request's result, again
The same key and payload, after the first request failedThe request runs again (see Retrying failures)
The same key and payload while the first request is still running409 conflict with Retry-After
The same key with a different payload409 conflict

An idempotency record resolves as soon as Koil has accepted the work and produced its ids (pub_…, med_…, bf_…, conn_…, prof_…); it does not wait for the work itself, such as a publish scheduled for next month. A publish submission sent with Prefer: wait resolves only when it answers, after its wait. Until then a retry answers 409 conflict with Retry-After; afterwards it gets the first answer (the items as they stood then) without waiting again. That answer is 200 only if the retry also sends Prefer: wait and every item in it has its outcome. Records expire 24 hours after first use, after which the key may be reused with any payload. A request that dies mid-flight does not block its key for long: a record still in flight after 15 minutes is treated as abandoned, and the next request with that key and the same payload takes it over, resuming it.

Retrying failures

A request that answered an error is safe to retry with the same key and payload: the retry runs it again, and whatever the failed attempt already created (a publish request it accepted, a media object, a Profile) is found again rather than created twice. A retry of a request that failed for its content fails the same way; once you change the payload, it needs a new key.

For batch submissions (publish and backfill requests), the key covers the whole batch. Once a batch is accepted, items that fail later are part of its result, which the key replays; to retry only those items, submit just them under a new key.

Reads, deletes, and updates are naturally repeatable and take no key.

On this page