Handle webhook events received out of order
Use event occurrence fields and file version numbers to reject stale webhook work, then reconcile current state when no ordering field exists.
Last reviewed
Webhook arrival order is not a state-order guarantee. Retry delays and manual redelivery can make an older payload arrive after a newer event, and delivery-row creation time records the attempt rather than the original business change.

Steps
- Verify the signature, deduplicate by the top-level event
id, and parsetype,created,workspace_id, anddata. Event IDs are opaque values and must not be sorted. - Store top-level
createdas the event’s Unix-second occurrence time, not a total-order sequence. Separate events may share the same second, and a redelivery retains the old payload while receiving a new delivery row. - For
file.uploaded, key state bydata.file_idand compare the integerdata.version. Apply a higher version, treat the same event ID as duplicate, and ignore a lower version that arrives after a newer one. - For
share.accessed, usedata.accessed_atfor the access occurrence and retain every distinct event ID. Two views of one link are separate events even when their timestamps are close. - For
file.deleted, note that current payloads providefile_id,name, andpermanentbut no resource version. Reconcile current Dosya state through an independently authorized API read before triggering an irreversible downstream deletion. - Test by delaying an older upload event, processing a higher file version first, and then releasing the old request. Confirm the stored version does not move backward and both attempts receive deliberate acknowledgements.
The sender offers no ordering contract across events or endpoints. Keep per-resource monotonic state where a reliable field exists and use current-state reconciliation where it does not.

Expected result
The consumer converges on the newest known file version, retains distinct share accesses, and refuses to infer deletion order from random IDs or delivery timestamps. Late retries cannot roll downstream state backward.
Two events have the same created value. Use the resource-specific field or reconcile current state; the envelope timestamp has one-second precision.
A delete cannot be reconciled. Quarantine that event for operator review and return according to the receiver’s retry policy instead of guessing at an irreversible transition.
Related guides
Was this helpful?
Loading helpfulness results…
Voting saves a necessary ballot cookie for up to 180 days so you can change your answer.
Questions and replies
Ask about the steps in this guide. Questions are reviewed before publication.
Keep account details, credentials and private files out of public questions. Use private support for those.
Loading questions…
Sign in to your Dosya account to ask a question.