Distinguish a slow receiver from a failed action

A provider reports a webhook timeout even though your database contains the expected update. The receiver may be performing several remote calls before replying. A slow email service or third-party API can consume the provider's response deadline, leaving the sender unable to tell whether the action completed.

Measure the receiver in stages: signature verification, durable acceptance, business processing, and response transmission. Include a delivery identifier in operational logs. A timeout does not prove that nothing happened. Repeating the full action immediately can create duplicates, especially when an external call succeeded just before the connection closed.

Make acceptance a small durable transaction

Keep the HTTP request responsible for validating and recording the event, not executing an entire workflow. Save the event in a durable inbox with a unique delivery key. Return a success response only after that transaction commits. A process-local array or an unawaited promise is not a durable queue and can disappear during a deploy.

A worker can claim pending jobs in a short PostgreSQL transaction. The example below gives an item a lease expiry so an interrupted worker does not leave it permanently inaccessible. The selection and update happen together. Commit immediately after claiming; perform slow external work outside the row-locking transaction.

sql example
WITH next_job AS (
  SELECT id
  FROM webhook_jobs
  WHERE state = 'pending'
     OR (state = 'processing' AND lease_until < now())
  ORDER BY created_at, id
  FOR UPDATE SKIP LOCKED
  LIMIT 1
)
UPDATE webhook_jobs AS job
SET state = 'processing',
    lease_until = now() + interval '2 minutes',
    attempts = attempts + 1
FROM next_job
WHERE job.id = next_job.id
RETURNING job.*;

Design recovery before increasing throughput

Assume the jobs table has id, created_at, state, lease_until, attempts, and the validated work payload. Make the lease longer than expected processing time or renew it safely. A successful worker marks the same claimed item complete; a failed worker records a bounded reason and schedules a retry. Protect completion updates with a claim token if leases can expire while work continues.

The worker must still make side effects idempotent. A lease can expire after a remote action succeeds, and another worker may claim the job. For non-idempotent operations, use the destination's supported idempotency key or add reconciliation. Put a ceiling on automatic attempts and expose exhausted jobs for review instead of retrying forever.

Verify acknowledgement and recovery independently

In a test environment, deliberately slow the downstream service. The webhook acknowledgement should stay quick because it waits only for validation and storage. Stop the worker after a claim and confirm the lease permits recovery. Then run two workers and confirm they do not claim the same active lease.

Monitor oldest pending age, processing duration, attempts, and failed count. Queue depth alone can look healthy while one important job is stuck. Provider deadlines differ: GitHub documents its own response requirement, which should not be assumed for every service. Keep a separate alert for inbox storage failures because those prevent safe acknowledgement.

  1. Delay the downstream call and measure HTTP acknowledgement time.
  2. Stop a claimed worker and observe lease recovery.
  3. Run two workers against harmless sample jobs.
  4. Confirm exhausted retries remain visible and replayable.

Sources and further reading

Related engineering notes