ENGINEERING JOURNAL

Webhook Delivery Retries: Exponential Backoff Done Right

Webhook delivery retries with exponential backoff: why fixed intervals fail, how to schedule retries, add jitter, and make redelivery safe.

THE ARTICLE 01 — 02

A webhook that fails once is normal. A webhook that fails five times in ten seconds, because your retry logic hammered a receiver that was already down, is a self-inflicted outage. The retry strategy matters as much as the first delivery attempt. Here is how webhook delivery retries with exponential backoff should actually work.

Why webhooks fail in the first place

The mistake is treating a failed delivery as an emergency that needs instant repetition. If the receiver is down, retrying every second does not bring it back faster. It adds load to a system that is already struggling, and it burns through your queue workers on attempts that were never going to succeed.

Fixed-interval retries make a bad day worse

The simplest retry setup is a fixed delay: retry every 60 seconds, five times. It looks reasonable until many deliveries fail at once, which is exactly when a receiver outage happens. Hundreds of webhooks all retry on the same 60-second beat, and the receiver comes back to a wall of simultaneous requests. That is the thundering herd problem, and it can knock a recovering service straight back down. Fixed intervals also waste attempts: if the receiver is down for ten minutes, five retries spaced a minute apart are spent in the first five minutes.

Exponential backoff, concretely

Exponential backoff means each retry waits longer than the last. A common starting schedule is 1 minute, then 2, then 4, then 8, then 16. The delay doubles each time, so attempts spread out over a window that actually covers a realistic outage: five retries over roughly half an hour instead of five minutes.

In Laravel, a queued job can declare this directly:

class DeliverWebhook implements ShouldQueue
{
    public $tries = 5;

    public function backoff(): array
    {
        return [60, 120, 240, 480, 960];
    }

    public function handle(): void
    {
        $response = Http::timeout(10)
            ->post($this->url, $this->payload);

        if (! $response->successful()) {
            throw new \Exception(
                "Webhook delivery failed: HTTP {$response->status()}"
            );
        }
    }
}

One more detail: add jitter. If a thousand webhooks all fail at 10:00 and all retry at 10:01, 10:03, and 10:07, you still get synchronized waves. Randomize each delay a little, for example waiting between 80 and 120 percent of the scheduled delay, so retries flatten into a steady trickle and the receiver recovers under a manageable load.

Cap the delay and cap the attempts

Backoff without a cap grows forever: 32 minutes, 64 minutes, two hours between attempts. Cap the maximum delay at something sensible, like 15 or 30 minutes, and cap the total attempts at five to eight. After the last attempt, the delivery is dead, and that is fine, as long as dead is a state you can see.

Dead deliveries need a home. Log every final failure with the event id, the destination URL, the last HTTP status, and the response body if you have it. Give yourself a way to replay a dead webhook manually from a dashboard or a console command. A webhook that fails permanently and silently is worse than one that fails loudly five times.

Make retries safe to repeat

A retry is only safe if delivering the same event twice does no harm. Receivers should treat your webhook as at-least-once delivery, not exactly-once, because a timeout on your side can mean the receiver processed the event but your request never got the response. Send a stable event id with every attempt, and include it in a header such as X-Event-Id, so the receiver can deduplicate. If you control the receiver, store processed event ids and skip duplicates.

The same rule applies on your side: a retry must not create a second charge, a second email, or a second database row. If your webhook handler has side effects, guard them with the event id before doing the work.

What to log and alert on

Retry behavior is invisible unless you record it. Log the attempt number, the delay before the next attempt, and the outcome of each try. Alert when the failure rate crosses a threshold, for example more than 5 percent of deliveries failing over ten minutes, or when a single destination fails every attempt for an hour. The second alert usually means the receiver changed something, an expired secret, a rotated URL, a revoked token, and no amount of retrying will fix it. That is a human problem, not a queue problem.

Takeaway

Good webhook retries are boring on purpose: wait longer each time, randomize the wait a little, stop after a handful of attempts, and keep a record of everything that died. That small set of rules turns a flaky integration into a reliable one, and it keeps a short receiver outage from becoming your outage too.

Muhammad Aqib ← ALL ARTICLES
KEEP EXPLORING

More ideas.
Better engineering.

Explore the journal ↗