Блог

Where do webhooks go when your server is down?

Юрій Мельников

A customer pays for an order, the payment provider sends a notification, and at that exact moment the store’s server is unavailable. Half an hour later, the site is back, but the order is still waiting for payment. What happened to the request?

When some hosting providers had outages, I read through chat threads where people were dealing with the aftermath. It made me think: the server is back, the site opens again. But what happened to the requests that were trying to get through while the server was down?

Say you run an online store. A customer pays for an order, and the payment provider sends the store a notification: “Order paid.” That kind of notification is called a webhook. In practice, it is just a regular HTTP request. But at that moment, your server is unavailable. For the customer, the payment went through; in your system, the order is still waiting for payment. Half an hour later, the server comes back up, but the order status will not update by itself.

What happens next depends on the sender. One service will retry the request a few times. Another will keep trying for a long time. A third may not retry at all. Sometimes you can request the event again through the provider’s API, if the provider allows it. But if the request never reached your server, there is no point looking for it in your application logs. And if you do not know exactly which events you missed, an outage leaves you with another job: reconciling data between systems.

I would split this into two separate tasks. The first has to happen immediately: receive the event and store it. The second can happen later: deliver the event to the place that will process it. If both actions depend on the same server, a failure can stop both receiving and processing. If the receiving endpoint runs separately, you have a chance to store incoming events while the application recovers.

This is how request intake works in Adal Cloud. We give the payment provider a public Adal Cloud URL, and in the service itself we specify where those notifications should be forwarded. Adal Cloud receives the request, stores it, and responds to the sender. After that, it calls our handler.

Back to the order. The payment provider sent the notification while the store was unavailable. Adal Cloud accepted it, but the first delivery attempt to the store failed. If the store is back by the next attempt, it will receive the same notification. The payment provider does not need to send anything again.

If, after the outage, the order is still waiting for payment, I can open the log and check whether the request reached Adal Cloud and what happened next. I can see when each attempt happened, what status code the store returned, or what error occurred. And if the same notification needs to go both to the store and to the accounting system, each recipient has its own history. For example, the store may have already confirmed receipt, while the accounting system still has one more attempt ahead.

There is another situation that tends to show up during recovery. Imagine that a thousand events piled up during the downtime. The application has just started, the database is still building up connections, and it already has to handle both new requests and the backlog. In Adal Cloud, you can configure the interval between sends for a specific recipient. This lets you feed accumulated requests through at a pace your handler can actually handle. On the intake side, you can also, for example, accept only POST requests with the required Content-Type and restrict sender addresses if the provider publishes a list of them. That way, clearly unsuitable requests are filtered out before they ever reach your application.

If the downtime drags on and the automatic retries run out, the log is still useful. You can see which events Adal Cloud accepted and which ones remained in an error state. As long as the request body is available, you can compare it with the provider’s data and understand what needs to be restored. This is why it is useful to keep the receiving history separate from the delivery history.

So when someone tells me after an outage, “the server is back,” I still have a question: “What about the events that arrived during that time?” If payments or orders depend on them, it is worth knowing in advance who will receive them while the application is unavailable, and where you can later check whether they reached the handler. A server can be back in half an hour, but without that history, sorting out the orders can take more than a day.