What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Build a webhook receiver that verifies each request, durably records accepted events, and makes repeated processing safe. Use the provider’s stable event ID to suppress duplicate deliveries, but also make downstream business operations idempotent: a worker can crash after applying an effect and before recording completion.

What idempotency and deduplication protect against

Webhook senders may retry delivery, so a receiver should not assume that each request arrives exactly once. Idempotency means repeating an operation does not apply its business effect more than once. Event deduplication is the receiver’s mechanism for recognizing that it has already accepted a particular provider event.

Stripe’s API documentation describes idempotency keys for safely retrying API requests without accidentally performing the same operation twice. That describes Stripe API requests; it is not a universal definition of webhook delivery behavior. The receiver still needs its own durable event record and processing safeguards. Stripe: Idempotent requests.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right deduplication key

For suppressing repeat deliveries of the same event, use a stable identifier supplied by the provider, scoped by provider name. A database uniqueness constraint on (provider, event_id) makes the rule enforceable even when multiple requests arrive concurrently.

An event ID does not necessarily prevent two distinct events from triggering the same real-world action. If that is possible, define a separate business-operation idempotency key for the effect itself. Keep the two scopes distinct: event IDs identify deliveries of provider events; business keys identify operations your application must not repeat.

Verify the request before trusting its contents

Use the provider’s documented signing secret and signature procedure. For providers that sign the request body, verification may depend on the exact received bytes. If middleware parses JSON and then reserializes it, the bytes can differ, making verification fail or invalidating the provider’s signing scheme. Preserve the raw body using the framework’s supported mechanism and verify that mechanism against the provider’s current documentation.

For Stripe, configure and use the webhook endpoint secret documented for signature verification. Do not treat a parsed payload as authentic until verification succeeds. Stripe: Webhooks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Also check how your runtime and deployment path expose repeated headers. Node.js documents header-specific duplicate handling, and the joinDuplicateHeaders option changes how some duplicates are represented. Do not assume every signature header is parsed identically; follow the provider’s requirements in the actual server environment. Node.js HTTP documentation.

  • Set a request-size limit appropriate for the provider’s event payloads.
  • Verify the signature and any timestamp rules before creating business effects.
  • Validate the event envelope and expected event types after authentication.
  • Never log signing secrets; restrict or redact sensitive payload data in logs.

Accept durably, then process asynchronously

Keep the HTTP handler’s work small. A practical pattern is to authenticate and validate the request, store the event durably, mark work ready in the same transaction, and return the provider-appropriate success response only after that durable acceptance. This is an engineering pattern, not a universal acknowledgment deadline: consult the selected provider’s current delivery requirements.

An inbox table can include:

  • provider and event_id, protected by a unique constraint together.
  • Received time and signature-verification result.
  • Payload or a protected reference to it.
  • Processing state, attempt count, and most recent error.

Insert the event and enqueue work—or mark it ready—in one transaction. If the uniqueness constraint reports a conflict, the event was already durably accepted; acknowledge the repeated delivery without repeating its business effect. If acceptance cannot be committed, return the response appropriate for the provider so it can retry, rather than claiming success for work that was not saved.

Synchronous processing versus durable acceptance

Approach Response latency Failure isolation Operational complexity Replayability
Process the business operation in the request handler Can be longer because the response waits for processing. Processing errors and slow dependencies affect the request path. Fewer components, but the handler must manage processing and retries. Depends on whether the application separately stores events and state.
Persist acceptance and process with a worker Can return after durable acceptance rather than after slower work. Separates delivery acceptance from downstream processing failures. Requires durable storage, worker operation, and state monitoring. Accepted events can be retried or replayed under controlled rules.

These are design trade-offs, not measured performance results. Asynchronous work only improves recovery if acceptance is genuinely durable and the worker’s effects are safe to repeat.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make worker retries safe

A worker can apply a downstream change and then crash before marking the job complete. When the job runs again, the event-level inbox key alone cannot tell whether that effect already happened. Make downstream mutations idempotent too—for example, by recording a business-operation key alongside the mutation where the downstream system supports it.

Track attempts and the latest error, and distinguish pending, failed, and completed work. Retry transient failures according to a policy suited to the dependency and provider; there is no single retry schedule established for all webhook senders. Avoid retrying permanent validation or business-rule failures indefinitely. Preserve enough state to investigate and safely resume work.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Recover after failures and outages

Provide operational views for accepted, pending, failed, and completed deliveries. Alert on the age of the oldest pending item and repeated failures, since a growing queue can indicate a worker or dependency outage. Support controlled replay from stored records while keeping deduplication and downstream idempotency safeguards intact.

Provider-side history is useful but not a substitute for local retention. Stripe’s Events API documentation says events are retrievable for 30 days. Stripe also says event data is rendered using the API version in effect when the event was created; it does not silently become the current version. Retain the information needed for your own recovery, and account for versioned event schemas when migrating. Stripe: Events API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If local records are missing or a provider’s history is no longer available, reconcile against the provider’s current resource state where possible. That may establish the current state, but it cannot always reconstruct every historical transition; design reconciliation around the business facts your application must preserve.

Use a focused TypeScript request path

The exact raw-body setup depends on the framework and deployment stack. The available provider and runtime documentation does not establish one framework-specific TypeScript middleware recipe, so do not copy a generic JSON-body configuration without confirming that it preserves the bytes required for signature verification.

  1. Limit and capture: enforce a body-size limit and retain the original request bytes.
  2. Authenticate: verify the provider signature, secret, and timestamp requirements using the current provider instructions.
  3. Validate: parse the authenticated payload and check the envelope and supported event types.
  4. Persist: insert under the unique provider/event key and make work ready in a durable transaction.
  5. Acknowledge: return the provider-appropriate success response after commit; handle an already-accepted duplicate without repeating effects.
  6. Process: let a worker apply idempotent business changes and update processing state.

Keep provider-specific rules explicit

Signature format, timestamp tolerance, retry behavior, manual redelivery, response expectations, and event-history retention vary by provider and can change. Confirm those rules in the provider’s current documentation before setting production behavior. Stripe’s 30-day event retrieval window and API-version behavior are Stripe-specific, not general webhook guarantees.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.