Mercury webhooks in production: duplicates, ordering, retries and timeouts
This guide covers the problems Mercury webhooks cause in production and how to handle each one. What Mercury sends is on the Mercury webhooks overview, every event type is on Mercury webhook events, and signature verification code is on Verify Mercury webhooks.
At a glance
| Problem | What to do | With Event Gateway |
|---|---|---|
| Timeouts | Return a 2xx within 5 seconds; process in a background job | Accepts the delivery at once, then queues it for your service |
| Duplicates | Record processed event id values and skip repeats | Can drop repeats before they reach your handler |
| Ordering | Keep the last resourceVersion for each resource; ignore lower ones | Logs every event and attempt, so you can see arrival order when debugging |
| Retries | Return 4xx only for invalid requests; reconcile from the Events API | Accepts deliveries while your service is down and replays them |
| Choosing events | Filter with eventTypes and filterPaths; route on resourceType and operationType | Filters and routes on any field in the body |
| Testing | Send a test event with the verify call; there's no sandbox | Forwards to localhost and replays past events |
| Other limits | Save the secret at creation; plan for 100 endpoints | Fans one endpoint out to many destinations |
Mercury webhook timeouts and slow handlers
Return a 2xx within 5 seconds, then do the work in a background job.
Why it happens: Mercury marks a delivery as failed if it gets no response within 5 seconds, then retries it. A handler that applies a merge patch to your ledger and calls the Mercury API before responding can run past that limit, even though the work succeeds.
Fix it in your handler:
- Verify the signature, store the event and return 200.
- Apply the patch or fetch the resource in a worker. See why to process webhooks asynchronously.
- Keep the request path free of calls to other services.
With Event Gateway: Hookdeck accepts each Mercury delivery immediately, then queues it and delivers it to your service with its own retries. Your handler can take as long as it needs without failing a Mercury delivery.
Duplicate Mercury webhooks
Mercury delivers at least once, so the same event can arrive more than once. Record each event's id and skip any you've already processed.
Why it happens: A delivery that succeeds on your side but times out on Mercury's is retried, and Mercury's docs say you may occasionally receive the same event several times. Tracking id also protects you against an attacker re-sending a captured request, which Mercury points out.
Fix it in your handler:
- Store each event
idbefore you process the event, with a unique constraint. See our guide to webhook idempotency. - Skip any
idyou've seen, and still return a 2xx so Mercury stops retrying. - Keep the records for at least as long as Mercury retries, which is about a day. Keep them for 90 days if you also reconcile from the Events API, since that's how long events stay available.
With Event Gateway: Deduplication can compare the fields you choose, such as id, and drop repeats within a time window before they reach your handler.
Out-of-order Mercury webhooks
Mercury doesn't document an ordering guarantee, so don't rely on arrival order. Use resourceVersion to tell which change is newer.
Why it happens: Mercury retries a failed delivery over about a day, so a retried event can arrive after a later change to the same transaction. resourceVersion starts at 1 for a new resource and goes up with each update.
Fix it in your handler:
- Keep the last
resourceVersionyou applied for eachresourceId, and ignore events with a lower one. - If the version jumps, fetch the resource from the API rather than applying the patch. A merge patch only holds the fields that changed, so it can't fill the gap. A
filterPathsfilter can cause jumps too, because it holds back changes to other fields. - Treat
previousValuesas a check: if they don't match your stored copy, you've missed something.
With Event Gateway: Hookdeck logs every event and delivery attempt, so when state looks wrong you can see the order events arrived in and replay them.
Mercury webhook retries and disabled endpoints
Mercury retries a failed delivery up to 10 times over about a day, but never retries a 4xx other than 429. After consecutive failures it disables the endpoint.
Why it happens: No response or a non-2xx status counts as a failure, and Mercury retries it with exponential backoff. A 4xx is the exception, so a 400 from a strict validator or a 401 from a misconfigured verifier loses that delivery after one attempt. Mercury sets an endpoint's status to disabled after consecutive delivery failures. It doesn't publish the threshold, or say what happens to an event once its retries run out.
Fix it in your handler:
- Return a
4xxonly for requests that really are invalid, such as a bad signature. Return a5xxif your own dependencies are down, so Mercury tries again. - Check
GET /webhooks, which can filter by status, and alert when an endpoint reportsdisabled. - Reactivate a disabled endpoint with
POST /webhooks/{id}, settingstatustoactive. - Reconcile the gap with
GET /events, which can filter byresourceTypeandresourceId. Events stay available for 90 days after they occur.
With Event Gateway: Hookdeck keeps accepting Mercury's deliveries while your service is down, so your outages don't count as Mercury delivery failures. Failed events can be retried on the status codes you choose, automatically or in bulk once you recover.
Choosing and routing Mercury events
Subscribe with eventTypes and filterPaths, and route on resourceType and operationType. The names you subscribe to never appear in a delivery.
Why it happens: eventTypes only decides what gets sent. The body is an Events API event, so a handler that switches on transaction.created never matches. The verbs differ too: create in the body, created in the subscription. Mercury's Events API lists the resourceType values as transaction, checkingAccount, savingsAccount, treasuryAccount, investmentAccount and creditAccount, but it doesn't publish a balance event body or state a rule that maps a subscription name to a pair.
Fix it in your handler:
- Route
transactionandcreatefortransaction.created, andtransactionandupdatefortransaction.updated. - Expect a balance subscription such as
checkingAccount.balance.updatedto arrive ascheckingAccountandupdate, and log your first delivery of each type to confirm it. - Log and acknowledge any combination you don't recognise, so new types don't produce errors.
- Leave out
eventTypesonly if you want all event types. AddfilterPathsto send an event only when certain fields change. A reconciliation job that cares about posting can subscribe totransaction.updatedand filter on the status field.
With Event Gateway: Hookdeck filters can route on resourceType and operationType, so transactions and balance changes can go to different destinations.
Testing Mercury webhooks
Webhooks aren't available in Mercury's sandbox, so test against a production endpoint with the verify call.
Why you need a plan: Every endpoint belongs to a production account, so triggering a real transaction as a test means moving real money. Mercury's verify call sends a test event instead. It doesn't document how to tell a test event from a real one.
Test it safely:
- Call
POST /webhooks/{id}/verify. It sendstransaction.createdunless you pass anothereventTypein the body. - Log the test event and check it before you let it reach any code that writes to your ledger.
- Keep fixtures of the deliveries you receive. Mercury's docs have only one body example, a transaction update, which is on Mercury webhook events.
With Event Gateway: The Hookdeck CLI receives webhooks on your machine without a public server, and you can replay past events to your handler as you change it.
Other Mercury webhook limits
Save the signing secret when you create the endpoint, and plan for the endpoint limit and the gaps in Mercury's docs.
The secret is shown once. Mercury returns it only in the create response, in a field named secret, and GET and update calls leave it out. Mercury's Webhooks page calls the same value secretKey. Write it to your secret manager in the same script that creates the endpoint. If it's lost, create a new endpoint, switch your receiver over and delete the old one.
100 endpoints per organization. Contact api@mercury.com if you need more.
filterPaths values. The Webhooks page shows bare field names such as status, while the API schema lists prefixed values such as transaction.status. Check the response to your create call to see what Mercury stored.
No source IP list. Mercury doesn't publish IP addresses for webhook traffic, so the signature is how you authenticate a delivery.
With Event Gateway: Hookdeck sends one Mercury endpoint's events to as many destinations as you need, so the secret only has to live in one place and your own services never need it.
Keep an outage from disabling your Mercury endpoint.
Event Gateway verifies the signature and answers Mercury as soon as it accepts each delivery, so downtime on your side doesn't count as failed deliveries, and your events wait in its queue until your service recovers.