Lago webhooks in production: duplicates, ordering, retries and timeouts
This guide covers the problems Lago webhooks cause in production and how to handle each one. What Lago sends and how it's signed is on the Lago webhooks overview, every message type is on Lago webhook events, and signature verification code is on Verify Lago webhooks.
At a glance
| Problem | What to do | With Event Gateway |
|---|---|---|
| Timeouts | Acknowledge at once; process in a background job | Accepts the message at once, then queues it for your service |
| Duplicates | Process each X-Lago-Unique-Key once | Can drop repeats before they reach your handler |
| Ordering | Tolerate reordering; fetch current state from the API | Logs every message and attempt, so you can see arrival order when debugging |
| Retries | Watch the webhook logs; reconcile after an outage | Accepts messages while your service is down and replays them |
| Choosing events | Set event_types; route on webhook_type; accept unknown types | Filters and routes messages by type |
| Testing | Forward messages to localhost with a CLI | Forwards to localhost and replays past messages |
| Other limits | Plan for the JWT default and 10 endpoints | Verifies HMAC-signed endpoints and fans one endpoint out to many services |
Lago webhook timeouts and slow handlers
Acknowledge a message straight away, then do the work in a background job.
Why it happens: Lago doesn't publish the request timeout for Lago Cloud. Self-hosted instances default to 30 seconds, set with LAGO_. A handler that writes to a database or calls other services before responding risks using up one of Lago's three attempts. Lago's webhooks guide lists 200, 201, 202 and 204 as acknowledgements, and marks any other response as failed. Its format page says any 2xx, so stick to those four.
Fix it in your handler:
- Verify the signature, store the message and return
200. - Process the message from a queue. See why to process webhooks asynchronously.
- Keep calls to other services out of the request path.
With Event Gateway: Hookdeck accepts each Lago message immediately, then queues it and delivers it to your service at a rate you set, with its own retries. Your handler can take as long as it needs without failing a Lago attempt.
Duplicate Lago webhooks
Lago can send the same message more than once. Record each X-Lago-Unique-Key and skip repeats.
Why it happens: Lago sends a message again after an error response or a network issue, even if your handler finished the work before the failure. Without a check, a customer can receive two "payment failed" emails, or a wallet top-up can be applied twice.
Fix it in your handler:
- Store each
X-Lago-Unique-Keywith a unique constraint. Lago tells you to "use it to process a message only once". - Make every handler idempotent: the same result however many times it runs.
- Write the side effect and the key in one transaction where you can.
With Event Gateway: Hookdeck's deduplication can drop repeated deliveries based on the X-Lago-Unique-Key header before they reach your handler.
Out-of-order Lago webhooks
Lago tells integrations to tolerate reordering. Fetch current state from the API when your next step depends on it.
Why it happens: Lago's own integration advice is to "tolerate retries and reordering", and a retried message can arrive after newer ones. A subscription.terminated can reach you before the subscription.started for the same customer. For more on the general problem, see Webhook Ordering: Why It's Hard and How to Handle It.
Fix it in your handler:
- Before changing access or sending a customer email, fetch the current subscription or invoice from the Lago API.
- Treat the API as the source of truth when a message and your stored state disagree, as Lago advises.
- Write state transitions that tolerate messages in any order.
With Event Gateway: Hookdeck logs every message and delivery attempt, so when state looks wrong you can see the order they arrived in and replay them.
Lago webhook retries and failed messages
Lago makes up to 3 attempts per message. After that it's on you to notice the failure, so watch the webhook logs and reconcile after any outage.
Why it happens: The 3 attempts are the first call plus 2 retries, waiting longer between each. Lago doesn't publish the intervals. After the last attempt, the message shows an error status in the webhook logs. A short outage on your side can leave invoices and subscription changes that never reached your system. Lago's docs don't describe disabling an endpoint after failures.
Fix it in your handler:
- Open the endpoint's Deliveries tab under Developers > Webhooks, filter by status, and retry failed messages from there.
- On self-hosted Lago, raise the total with
LAGO_WEBHOOK_ATTEMPTS(default 3). - Reconcile important objects, such as invoices and subscriptions, against the Lago API on a schedule.
With Event Gateway: Hookdeck accepts each message on Lago's first attempt and stores it. Delivery to your service is then retried on a schedule you set, failures raise issues, and you can replay messages once your service is back.
Choosing which Lago messages to listen to
Set each endpoint's event_types to the messages your integration processes, and route on webhook_type.
Why it matters: event_types set to null or ["*"] sends every type, and an empty array stops all delivery. Lago lists 83 types and says new ones are added over time. Some names don't mean what they suggest: invoice.created is sent when an invoice is finalized, and wallet.updated isn't sent for changes to a wallet's ongoing balance. event.error is deprecated in favor of events.errors, though Lago still sends it.
Fix it in your handler:
- Switch on
webhook_type. Every message about an invoice hasobject_typeset toinvoice, soobject_typecan't tell you what happened. - Acknowledge types you don't handle, so a new type never counts as a failure.
- Watch for
wallet.depleted_rather thanongoing_ balance wallet.updatedif you act on a wallet running out.
With Event Gateway: Hookdeck's filters on webhook_type send each connection only the messages it needs.
Testing Lago webhooks locally
Forward messages to your machine with the Hookdeck CLI, then make a change in Lago to trigger one.
Why it matters: Lago needs a public URL, and your development server doesn't have one.
Set it up:
- Run
hookdeck listen 3000 lago --path /webhooks/lagowith the Hookdeck CLI, which gives you a public HTTPS URL that forwards to your local server. - Use that URL as the endpoint URL in a non-production Lago organization, or on a self-hosted instance.
- Make a change in Lago, such as creating a customer to send
customer.created.
With Event Gateway: Hookdeck keeps past messages, so you can replay one against your handler while you work on it.
Other Lago limits
Lago signs with JWT unless you choose HMAC, and an organization can have only 10 endpoints.
Why it happens: JWT puts the payload in the signature header, so the header can grow large and some servers reject it. Lago's docs give that as the difference between the two schemes. An HMAC check of the body also can't match a JWT, so a new endpoint fails every check if you haven't chosen HMAC. Each endpoint has its own URL and message types, so finance, product access and customer messaging can use up the 10 endpoints quickly. Lago's webhook pages publish no source IP list, and neither scheme asks you to check a timestamp.
Fix it in your handler:
- Check
X-Lago-Signature-Algorithmon a failing message. If it saysjwt, verify the token as shown in Lago's docs, or change the endpoint withPUT /api/v1/webhook_andendpoints/{lago_ id} "signature_algo": "hmac". - Send
"signature_algo": "hmac"when you create endpoints through the API, because the API also defaults tojwt. - If 10 endpoints isn't enough, point one endpoint at a router you run and fan messages out from there.
With Event Gateway: Hookdeck verifies HMAC-signed Lago endpoints, so choose HMAC for an endpoint that points at it. One Lago endpoint can then feed a Hookdeck source, with a connection for each service that needs its messages.
Keep Lago's three attempts from costing you a billing event.
Point an HMAC-signed Lago endpoint at Hookdeck Event Gateway. It verifies the signature, queues each message and retries to your service on your schedule.