Start free trial
Start free trial Log in

14-day free trial. No credit card.

Receiving and monitoring Laravel webhooks

Signature verification, async processing, idempotency and dead-man's-switch monitoring for a production-ready webhook endpoint.

  • Guide
  • 3 min read

How do I monitor Laravel webhook endpoints?

Track four signals: incoming delivery rate (with drop alerts via dead-man's-switch), signature verification failure rate, webhook receive-to-commit latency, and async processing job failure rate. In code, always: verify signatures before trusting payloads, persist raw bodies, queue processing async, and make handlers idempotent using the webhook's unique ID. NightOwl records webhook endpoints like any request with duration, status, and error context.

Updated

Webhooks are the one part of your app where the failure mode is silence. A normal endpoint that breaks throws 500s you can see; a webhook endpoint that breaks just stops mattering, because the only thing watching it is a provider's retry queue that gives up after a while. By then you've missed a day of Stripe events, and the first you hear of it is a customer asking why their subscription never activated. This guide covers both halves: writing the handler correctly, and noticing when deliveries stop arriving.

The 4-part pattern

Every webhook endpoint should follow the same skeleton:

app/Http/Controllers/StripeWebhookController.php

php
use App\Jobs\ProcessStripeWebhook;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Stripe\Exception\SignatureVerificationException;
use Stripe\Webhook;

public function __invoke(Request $request)
{
    // 1. Verify signature on the RAW body (Stripe signs "timestamp.body")
    $body = $request->getContent();

    try {
        $event = Webhook::constructEvent(
            $body,
            (string) $request->header('Stripe-Signature'),
            config('services.stripe.webhook_secret'),
        );
    } catch (SignatureVerificationException | \UnexpectedValueException $e) {
        abort(401, 'Invalid signature');
    }

    $eventId = $event->id;

    // 2. Persist raw payload for audit and replay
    //    (needs a unique index on provider + event_id)
    $stored = DB::table('webhook_deliveries')->insertOrIgnore([
        'provider' => 'stripe',
        'event_id' => $eventId,
        'event_type' => $event->type,
        'payload' => $body,
        'received_at' => now(),
    ]);

    // 3. Idempotency: only queue if this is a fresh delivery
    if ($stored === 0) {
        // Duplicate retry: we already have it. ACK and bail.
        return response()->json(['status' => 'duplicate']);
    }

    // 4. Process async: return 200 fast
    ProcessStripeWebhook::dispatch($eventId);

    return response()->json(['status' => 'queued']);
}

Signature first: if we can't trust the payload, nothing else matters. Raw body: request()->all() re-serializes and breaks HMAC. Unique event ID insert: duplicate retries hit the constraint. Async dispatch: the controller returns in under a second.

Once you return 200, it's your problem

There's a subtlety in accept-and-queue worth being explicit about: the moment you return 200, the provider considers the event delivered and stops retrying. If your queued job then fails (a processing bug, a downstream outage, a poison payload), the provider won't help you. The event is gone from their side. That's exactly why persisting the raw payload before you return 200 matters: it's the only copy you control, and it's what lets you replay a delivery your own processing dropped. Treat the webhook_deliveries table as the source of truth, not the provider's dashboard.

Dead-man's-switch monitoring

The scariest webhook bug: no webhooks at all. Someone rotates the signing secret in the provider's dashboard without updating your .env, every delivery now fails with 401, and nobody notices until business metrics drop.

Alert on absence, not on errors:

app/Console/Commands/CheckWebhookHeartbeat.php

php
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class CheckWebhookHeartbeat extends Command
{
    protected $signature = 'webhooks:heartbeat';

    public function handle()
    {
        $providers = ['stripe', 'shopify', 'sendgrid'];

        foreach ($providers as $provider) {
            $recentCount = DB::table('webhook_deliveries')
                ->where('provider', $provider)
                ->where('received_at', '>=', now()->subMinutes(30))
                ->count();

            if ($recentCount === 0) {
                logger()->alert("No {$provider} webhooks in 30 minutes");
                // Send Slack alert via a real channel
            }
        }
    }
}

Schedule it every 5 minutes in routes/console.php with Schedule::command('webhooks:heartbeat')->everyFiveMinutes(), and tune the window per provider. A high-volume provider (Stripe at scale) should alert after 5 silent minutes; a low-volume one can go longer.

Metrics that matter

  • Delivery rate per provider: time-series of webhooks received per minute. Drops alert.
  • Signature failure rate: > 0 is a red flag.
  • Receive-to-ACK latency: should be under 1 second. Longer means the controller is doing too much synchronously.
  • Processing job failure rate: async processing is where real business logic lives and breaks.
  • Duplicate rate: measure how often you hit the idempotency constraint. Some duplicates are normal; a spike usually means the provider thinks you're timing out.

Spatie's laravel-webhook-client

If you don't want to hand-roll the pattern, Spatie's package does most of it: signature verification, persistence to a webhook_calls table, and async job dispatch with the stored call. Recommended for multi-provider webhook setups.

Watch your webhook endpoints like any other route

Each webhook route shows up on the Requests page with its 4xx and 5xx counts and average and p95 duration, so a run of rejected signatures or slow handlers shows on the route itself. The jobs that process the payloads appear on the Jobs page with their failures and p95 duration per class.

No credit card needed.

Terminal
composer require nightowl/agent
php artisan nightowl:install
php artisan nightowl:agent

Frequently asked questions

Anything else, write to support@usenightowl.com

How do I reliably receive webhooks in Laravel?

Four principles: (1) return 200 fast and process async: accept the payload, queue a job, return 200 within a few seconds, (2) verify signatures before trusting the payload, (3) make processing idempotent using the webhook's unique ID, since retries mustn't cause duplicate side effects, (4) persist the raw payload to a webhook_deliveries table for audit and replay. Spatie's laravel-webhook-client package handles most of this if you don't want to build it yourself.

What's the most common webhook bug in Laravel?

Processing synchronously in the controller. The webhook provider times out (usually 5-30 seconds), thinks the delivery failed, and retries, sometimes with duplicates. You process the retry, the original completes late, and now you've double-charged or double-emailed someone. Always process async: accept, queue, return 200.

How do I verify webhook signatures in Laravel?

Most providers sign payloads with HMAC-SHA256, but each one builds the signature differently. Stripe signs the timestamp plus the raw body and sends t= and v1= values in the Stripe-Signature header; Shopify sends a base64 digest in X-Shopify-Hmac-Sha256. Use the provider's SDK when it has one (\Stripe\Webhook::constructEvent() for Stripe). Otherwise compute the HMAC of the raw request body with your shared secret, encode it the way the provider does, and compare using hash_equals (constant-time). Fail the request with 401 if signatures don't match. Use the raw body (request()->getContent()), not request()->all(), so you compare what the provider actually signed.

How do I make Laravel webhook handlers idempotent?

Use the webhook's unique event ID (Stripe's evt_, Shopify's X-Shopify-Webhook-Id, etc.) as a primary key in a processed_webhooks table. On receipt, try to insert the ID. If it already exists (duplicate retry), return 200 without re-processing. If it's new, process and record. The insert-first pattern avoids a race between two concurrent deliveries.

What happens when my webhook endpoint is down?

Reputable providers retry with backoff. Stripe retries for up to 3 days, Shopify 8 times over 4 hours. Less reputable ones give up after 1-2 attempts. Either way, your observability has to detect 'webhooks haven't arrived for X minutes' as a signal, because absence of deliveries is hard to alert on. Use dead-man's-switch monitoring: alert if you don't receive any webhook from Stripe in a rolling 30-minute window.

Should I rate-limit incoming webhooks?

Usually no. Rate-limiting incoming webhooks means you're dropping real events. Instead, make your async processing capacity match peak delivery rate. If rate limiting is necessary, return 429 with a Retry-After header so the provider backs off appropriately, and ensure your queue buffers the backlog without dropping payloads.

How do I test Laravel webhook handlers locally?

Use ngrok or Cloudflare Tunnel to expose localhost to the public internet. Configure a test webhook in the provider's dashboard pointing to your ngrok URL. Or use the provider's CLI: stripe listen forwards live Stripe events to a local endpoint, and shopify app webhook trigger sends sample payloads to one. For unit tests, mock the raw body and headers and assert the handler's effects.

What should I monitor for Laravel webhook endpoints?

Four things: (1) receipt rate: how many webhooks per minute are coming in, with alerts on sudden drops, (2) processing latency: receive-to-commit time, (3) signature verification failure rate: spikes indicate a compromised secret or a misconfigured provider, (4) async job failure rate for the processing jobs. An APM that records webhook endpoints like any other route shows receipt rate and signature failures (as 401s); job monitoring covers processing latency and failures.

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial

Related

Watch your webhook routes on your own app

See each webhook route's 4xx and 5xx counts and p95, plus the jobs that process its payloads. No credit card needed.