Ory webhooks in production: duplicates, ordering, retries and timeouts
This guide covers the problems you meet when an Ory Action calls your endpoint from a registration, login, settings, recovery or verification flow, and how to handle each one. It doesn't cover live event streams, a separate feature for enterprise contracts that sends named events to an HTTPS endpoint or AWS SNS.
What Ory sends is on the Ory webhooks overview, and how to check the key is on Verify Ory webhooks.
At a glance
| Problem | What to do | With Event Gateway |
|---|---|---|
| Timeouts | Respond inside 30 seconds; process in a background job | Answers Ory at once, then queues the request for your service |
| Duplicates | Send ctx.flow.id in the template and skip keys you've processed | Drops repeats before they reach your handler |
| Ordering | Fetch the identity from Ory when order matters | Logs every request, so you can see arrival order when debugging |
| Retries | Expect three attempts within seconds, then reconcile | Accepts requests while your service is down and retries on your schedule |
| Choosing events | Name the event in every template, or give each action its own path | Filters and routes on the fields or path you send |
| Testing | Use a public URL that forwards to localhost, then run the flow | Forwards to localhost and replays past requests |
| Other limits | Use non-blocking webhooks and api_key in a header | Compares the key header on non-blocking webhooks |
Ory webhook timeouts and slow handlers
Respond within 30 seconds, then do the work in a background job. Each attempt times out after 30 seconds, and the login failure trigger allows only 10 seconds.
Why it happens: An attempt that times out counts as failed, so Ory sends it again even though your handler is still working. On a webhook whose response isn't ignored, a timeout also reaches the flow as a webhook_timeout error.
Fix it in your handler:
- Check the key, store the request and return
200. See why to process webhooks asynchronously. - Do the work in a worker, outside the request.
- Keep any blocking endpoint small and fast, because your users wait for it.
With Event Gateway: Hookdeck answers Ory as soon as a request arrives, then queues it and delivers it to your service at a rate it can handle. Your handler can take as long as it needs.
Duplicate Ory requests
Your endpoint can receive the same request more than once. Put ctx.flow.id in the template, build a key from it, and skip keys you've processed.
Why it happens: Ory retries an attempt that timed out, even if your handler finished the work. Ory's webhook docs name no delivery ID. Kratos's open-source sender sets Ory-Webhook-Trigger-ID, which stays the same across retries, and Ory-Webhook-Request-ID, which changes on each attempt. Those docs don't mention either header, so check that they arrive on your deliveries before you rely on them.
Fix it in your handler:
- Add
ctx.flow.idand your own event name to the template, plusctx.identity.idonafterhooks. - Store the key in a table with a unique constraint before processing. See webhook idempotency.
- Don't key a login
submithook on the flow ID alone. That hook runs once per request, not once per flow, so the same flow ID repeats across real attempts.
With Event Gateway: Hookdeck deduplicates requests before they reach your endpoint, using the fields you choose.
Out-of-order Ory requests
Ory's webhook docs make no promise about order, so don't assume requests arrive in the order things happened. When order matters, treat the request as a signal and fetch the identity from Ory.
Why it happens: Non-blocking webhooks run in the background, and a retried attempt can arrive after a request from a later flow.
Fix it in your handler:
- Send the identity ID, then read the current identity from the Ory identities API when you process the request.
- Don't order on the timestamps in
ctx.identity. Ory's ownctxexample for a registration flow showscreated_atandupdated_atas0001-01-01T00:00:00Z.
With Event Gateway: Hookdeck logs every request and attempt, so you can see arrival order when debugging. For more on the general problem, see Webhook Ordering: Why It's Hard and How to Handle It.
Ory webhook retries
Ory Network makes up to three attempts and then stops, and its docs describe no way to resend a request. Plan for the requests that don't get through.
Why it happens: Ory Network retries after a timeout, a connection failure, a 429 or a 5xx other than 501. It waits 1 second before the second attempt and 2 seconds before the third, so an endpoint that answers 503 uses all three within about 3 seconds. An endpoint that doesn't answer at all takes about 93 seconds. A 429 or 503 with a Retry-After header stretches a wait, to 30 seconds at most. The login failure trigger makes one attempt and is never retried.
A non-blocking webhook's flow carries on either way, so nothing surfaces the loss. On a webhook whose response isn't ignored, running out of retries fails the flow with webhook_request_failed.
Fix it in your handler:
- Return
503withRetry-Afterfor temporary problems. Another4xxor a501isn't retried. - Don't take the endpoint down during a deploy, because even the longest waits add up to about a minute.
- Check the Ory identities API on a schedule for anything you can't afford to miss.
With Event Gateway: Hookdeck accepts each request as soon as it arrives and stores it, then delivers it to your service with retries on a schedule you control. Issues alert you when deliveries fail, and you can replay any request after a fix.
Choosing events: Ory has no event list for Actions
Ory defines no event names for Actions webhooks, because you choose where each one fires and write its body. Your events are whatever your templates say they are, so name them yourself.
Why it happens: Each action is set on a flow and a position. Registration, login, settings, recovery and verification each have before and after, and login also has submit and failure on Ory Network. The after position of login, registration and settings can also target specific authentication methods. Ory adds no field or header saying which of these fired.
Fix it in your template:
Add an
eventkey to every template, using your own naming:function(ctx) { event: 'registration.after', flow_id: ctx.flow.id, identity_id: ctx.identity.id, email: ctx.identity.traits.email, }Traits depend on your identity schema.
ctx.identityis bound only onafterhooks, so abeforetemplate has to usectx.flowand the request fields.Or give each action its own path, so the URL says which one fired.
If you need Ory's own named events, such as
IdentityCreatedorLoginSucceeded, look at live event streams, which need an enterprise contract.
With Event Gateway: Filters route requests by a body field or path, so each flow's webhooks reach the service that handles them.
Testing Ory webhooks locally
Point the action at a public URL that forwards to your machine, then run the flow.
Why it happens: Ory Network can't reach localhost, and Ory's docs describe no test button or resend, so a real flow is what sends a request.
How to test it:
Run
hookdeck listen 3000 ory --path /webhooks/oryand use the URL it prints as the action's URL.Run the flow, for example by registering a test user, and check the body your template rendered.
Keep test accounts out of your CRM by cancelling the webhook for them. A canceled webhook sends no request, and the flow continues:
function(ctx) if std.startsWith(ctx.identity.traits.email, "test-") then error "cancel" else { user_id: ctx.identity.id }
With Event Gateway: The Hookdeck CLI forwards requests to localhost, and you can replay past requests without running the flow again.
Other Ory limits
A static key isn't a signature. Ory's webhook authentication is basic_auth or api_key, and nothing is computed over the body, so anyone who learns the key can send requests your endpoint accepts. Use a long random value over HTTPS, keep it out of logs, and for sensitive actions look the identity up through the Ory API by ID before you act on the body.
Blocking webhooks tie sign-in to your uptime. A webhook without response.ignore: true makes the flow wait, and a failure can reach the user as webhook_timeout, webhook_request_failed or webhook_. Set response.ignore: true on every webhook that only informs another system.
The session hook can stop a webhook firing. The session hook modifies the response, so no other hooks run after it. If a webhook on after registration never fires, export your identity config and make the session hook last.
Send only the data you need. ctx.identity includes every trait, so template only the fields your receiver uses. ctx.request_headers exposes only an allowed list of headers by default, which actions.web_ changes.
Ory publishes its outgoing IPs. If your endpoint sits behind a firewall, allow the addresses for your project's region.
With Event Gateway: Create a source with the Ory type, then enter the same header name as API Key Header and the whole value as API Key, including any prefix. Header names match case-insensitively, but the value must match exactly. A request with a missing or wrong value is recorded as failed verification and doesn't reach your destination. The source type pre-selects POST, so if your action uses another method, allow it on the source too. An api_key sent as a cookie and basic_auth can't be checked by this source type.
Route only non-blocking webhooks through Hookdeck. Hookdeck answers Ory with its own response, not your service's, so a webhook that expects your response to change the identity or stop the flow can't work through it. For notifications, this keeps your users' sign-in path independent of your downstream services.
Get started with Hookdeck for free and receive Ory webhooks reliably in minutes.
Keep a short outage from losing your Ory sign-ups.
Ory's retries end within seconds of a failing response. Event Gateway checks the API key header on each non-blocking webhook, stores the request and retries to your service on your schedule.