Skip to main content

Automation & Integrations

Building a Webhook Event Inbox With Polling Recovery

Process webhooks durably, acknowledge them quickly, deduplicate delivery, retry work safely, and use scheduled checks to recover missed events.

By Sunbot Labs

Updated

5 min read

Webhook delivery and scheduled polling working together through durable receipt, duplicate protection, and recovery.

How the workflow connects

  1. 1Verify and store the webhook
  2. 2Acknowledge receipt
  3. 3Claim an unprocessed event
  4. 4Apply idempotent business handling
  5. 5Reconcile missing or stale records

A webhook endpoint should not attempt the entire business workflow before responding. Providers retry, events arrive out of order, and downstream systems become unavailable. An event inbox separates receipt from processing and lets a polling or reconciliation job recover what delivery alone cannot guarantee.

Store before doing slow work

Verify the signature against the raw request, capture the provider and event identifier, store the payload or permitted subset, and return within the provider's expected window. Use a unique constraint on provider, connection, and event ID to make repeated delivery harmless.

Sensitive payloads need retention and access rules. Store only what processing and audit requirements justify.

Process through a claimable inbox

Workers can claim pending events with an attempt count and lease time, then mark them processed, retryable, or needs review. Keep the business record or action identifier beside the event. A failed worker can release the lease without losing the original delivery.

Protect against order and duplication problems

A customer-updated event may arrive before customer-created, or a payment-refunded event may repeat after completion. Load the current authoritative state and apply transitions idempotently. When sequence matters, compare provider versions or retrieve the latest resource instead of trusting arrival order.

  • Scoped event uniqueness
  • Current-state transition check
  • Retry backoff and maximum attempts
  • Dead-letter or review queue
  • Trace from event to changed record

Use polling to find what webhooks missed

Run a scheduled query for records changed since a safe checkpoint, with an overlap window. Compare them with locally processed versions and enqueue missing work through the same handler. Also flag events that remain pending beyond the normal processing window.

Trace one event through receipt and processing

A payment provider sends an event indicating that an invoice was paid. The endpoint verifies the request signature using the raw body, writes the event to an inbox under the provider event ID, and responds. A worker later claims the event, retrieves the current payment when required, checks whether the invoice is already paid, and applies the transition once.

If the accounting system is unavailable, the event remains retryable without asking the provider to redeliver it. If the same webhook arrives again, the uniqueness rule points to the existing inbox record. If a refund event arrived first, current-state validation and a provider lookup prevent the later payment event from incorrectly reopening the invoice.

A signed event entering durable storage before queued processing and duplicate detection.

Visual guide

Fast receipt, durable processing, independent recovery

The public endpoint does only the work required to trust and retain the event; business processing happens behind a durable boundary.

  1. 1

    Verify

    Check signature, source, timestamp, and permitted payload size.

  2. 2

    Store

    Persist the raw event or approved subset under a scoped unique ID.

  3. 3

    Acknowledge

    Return promptly after durable receipt rather than after every downstream action.

  4. 4

    Process

    Claim, validate current state, and apply the business transition idempotently.

  5. 5

    Recover

    Retry temporary failures and poll for missing changes.

Separating receipt from processing reduces timeouts and gives operations a record that can be retried or reviewed.

Secure and operate the inbox

Signature verification is only one control. Limit request size, accept expected content types, reject unsupported event types, protect secrets, and avoid logging sensitive payloads by default. If events contain personal or payment-related information, define who can view them and when raw bodies are redacted or deleted.

Operational reporting should distinguish invalid deliveries, accepted events, processing failures, retries, dead-letter items, and reconciliation discoveries. Alert on a sustained backlog or an event that exceeds its processing target; do not page someone for every individual retry. A review screen should provide the event, linked business record, last error, attempt history, and safe next actions.

  • Monitor oldest pending age as well as queue length
  • Keep retryable provider errors separate from invalid business data
  • Require an authenticated action to replay or dismiss an event
  • Test duplicate, out-of-order, delayed, invalid-signature, and outage cases
Polling checkpoints, retry backoff, failed-event review, security controls, and operational monitoring.

Practical questions

Questions that often come up

Should the webhook endpoint always return success after storing an event?

Return success when verification and durable receipt succeed. Return an appropriate error when the request cannot be trusted or stored so the provider can follow its documented retry policy.

How long should raw webhook payloads be retained?

Retention depends on debugging, audit, privacy, and provider terms. Define a period and remove or redact sensitive data that is no longer needed.

Work with Sun Cluster

Planning a similar system for your organization?

Sun Cluster builds API and webhook integrations with durable processing, safe retries, observability, and recovery paths.