Make Media Webhooks Idempotent and Safe to Retry

Three-stage diagram for make media webhooks idempotent and safe to retry

·

·

A media webhook may arrive more than once or out of order. Design the receiving handler so processing the same event twice has the same result as processing it once. This is essential when an approval or replacement event triggers a CMS update, derivative job, or cache purge.

Identify the event and asset

Use the provider’s event ID or a stable composite key. Store that key with the result of processing. Verify the webhook signature before trusting the payload. Record the asset ID, version, event type, and occurrence time so a late event cannot overwrite a newer approved state.

Acknowledge quickly

Validate and enqueue the work, then return a success response promptly. Slow transformations should run in a worker. A failed worker can retry against the same idempotency key, with bounded attempts and a dead-letter path for investigation.

Make state changes conditional

An “approved” event for version two should not replace a public reference already pointing to version three. Compare versions or state sequence numbers before mutating content. Store the decision and the effect together where possible, so a crash between them does not produce an invisible half-update.

Test delivery disorder

Send the same event twice, then send an older event after a newer one. Simulate a timeout after the work succeeds. Confirm the public page, job count, and event log remain consistent. These tests expose more than a happy-path webhook demo.

A concrete example

An approval event reaches the CMS twice because the first acknowledgment times out. The handler records the event ID before enqueuing the update, so the second delivery observes the completed effect. A delayed older event cannot move the page back to an unapproved version.

Related reading

Primary reference

The Stripe webhook delivery guidance provides the underlying technical reference for this workflow.

Related field note

Continue with Idempotent media webhooks without duplicate files.

Share with