When a webhook hits our servers, we do four things:

  • verify it,
  • store it,
  • and put it on a queue
  • return 200

That's it. The real work happens later, in the background, where a slow database or a flaky API can't hurt the delivery.
I work in the engineering team at EverTry, a fintech that moves money for customers across Nigeria, Kenya, Ghana, Egypt, South Africa, and beyond. Webhooks tell us when a deposit lands, a card is charged, or a payout clears. If we miss one, a customer's money looks missing. So we've spent more time on this than we'd like to admit.
This is how we handle webhooks today, and why.

What went wrong before

We used to do all the work inside the webhook request, and only then tell the provider "thanks, got it."

It worked fine until it didn't. Most providers wait only a few seconds for a response. If you're slower than that, they assume you failed and send the same event again.

Our ID verification flow was hit hardest by this. When a verification result came in, our handler accepted the event, moved the ID images to our secure storage, ran our own analysis, and queued the case for a human reviewer. All of that happened before we sent a response.
Then customers started telling us their verification was stuck. Some waited hours. Some waited days, and a few waited weeks. The explanation we kept hearing was that "a webhook failed." When we finally checked the logs, it wasn't some webhooks. It was 56% of them.

The heavy work inside the request was the problem. Every extra second we spent moving images and running analysis was a second the provider spent waiting, and too often it gave up before we answered.

That was the moment we stopped treating webhooks as "just another API call." A webhook is a delivery. Our only job in that request is to sign for the package. Opening it can wait.

How we receive webhooks now

The receiving side is deliberately boring. It does three things and gets out of the way.
First, we check the signature. Every provider signs its webhooks. If the signature doesn't match, we return 401 and stop. We never store or queue anything we haven't verified, because otherwise anyone who finds the URL can fill our queue with junk. Where the provider sends a timestamp, we check that too, so an old request can't be replayed.

Second, we save the raw event. We store the full payload and headers in a webhook events table, with a unique index on the provider name and the provider's event ID. When a provider retries, the second insert hits that index, and nothing new gets created. No duplicate row, no duplicate job.

Third, we return 200 and queue it. The event goes onto its own webhooks queue. We keep it separate from emails and notifications, so a pile of marketing emails can never delay a payment confirmation.
Here's roughly what the controller looks like:

WHEN a webhook arrives from a provider: IF the signature is not valid: RETURN 401 and stop LOOK UP the event by (provider, event ID) IF we have not seen this event before: SAVE the raw payload and headers, with status = "received" ADD the event to the "webhooks" queue RETURN 200 

The whole thing usually finishes in milliseconds. The provider gets its 200, and we get the event safely on disk.

How we process them safely

The unique index stops duplicate deliveries. It doesn't stop duplicate processing. The system can run the same job twice: a worker crashes halfway, a job times out and retries, or someone on the team clicks "retry" in the dashboard. So every job we write assumes it might run more than once.

In practice, that means three habits.
We check before we act. Before crediting a wallet, the job asks whether this transaction is already settled. If it is, the job marks the event as processed and quits. Running it a second time changes nothing.

We lock the row. The check and the credit happen inside one database transaction, with the transaction row locked. Two workers can't both read "pending" at the same moment and both credit the customer.

START a database transaction: FIND the transaction by its reference LOCK that row so no other worker can touch it IF the transaction is already settled: STOP, there is nothing to do MARK the transaction as settled CREDIT the customer's wallet with the amount COMMIT, which releases the lock 

We retry with space. Each job has a set number of tries and a backoff, so failing jobs wait longer between attempts. When a provider's API has a bad minute, we don't want hundreds of jobs hammering it all at once.
The event record tracks all of this: received, processing, processed, or failed, plus an attempt count and the last error.

Why we don't trust the payload

This one took us a while to accept. Even a verified webhook can be stale or arrive in the wrong order.

Say a payment goes from pending to successful. Sometimes the "successful" event reaches you before the "pending" one. If your code applies events in the order they arrive, it can move a finished payment back to pending. With money, that's a real problem.

So we treat a webhook as a tap on the shoulder: "something changed on this transaction." Before the job moves any money, it calls the provider's API and asks for the current status. Then it acts on that answer, not on the payload.

When a webhook never arrives

Everything above assumes the webhook shows up. Sometimes it doesn't. The provider has an outage, a network hop drops the request, or retries run out while we're deploying.

No amount of clever webhook code fixes a webhook that was never sent. So we run a scheduled job that looks for transactions stuck in pending for too long. For each one, it asks the provider for the real status and settles or fails the transaction.
This sweep is our safety net. Webhooks make us fast. Reconciliation makes us correct.
Because we keep every raw event, we can also replay one by hand. If a job failed because of a bug, we fix the bug and replay the event from our admin dashboard. We don't have to email the provider and ask them to resend anything.
It costs one extra API call per event. We'll take that trade every time.

What changed

We rebuilt the ID verification webhook to do only two things: store the event and queue it. The image handling, the analysis, and the hand-off to our human reviewers all moved into the background job.
Our webhook success rate went from 44% to 99.999%.
Same provider, same analysis, same reviewers. The only thing we changed was when we did the work.

The bigger change was in how the team works. When something breaks now, the event is already sitting in our database. We fix the problem, replay the event, and the customer often never notices.

Our checklist

If you handle payment webhooks, this is the list we'd give you:

  1. Verify the signature and the timestamp if there is one, before anything else.
  2. Store the raw event, with a unique index on the provider's event ID.
  3. Return 200 straight away.
  4. Queue the work on its own queue.
  5. Make every job safe to run twice, and lock the row before you move money.
  6. Re-fetch the real status from the provider instead of trusting the payload.
  7. Run a reconciliation job for anything stuck in pending.
  8. Keep a way to replay failed events. None of this is clever. It's just being honest about the fact that networks fail, providers retry, and workers crash. Build for that, and webhooks stop being scary.