Webhook processing

Process webhooks reliably without making the sender wait

Acknowledge webhook requests immediately, queue each event, and process it asynchronously with retries and full visibility.

WebhookQueueFunction
  1. Request received
  2. 202 response returned
  3. Event processed asynchronously
  • Immediate acknowledgement
  • Managed queue
  • Automatic retries
  • Observable processing

Why processing inside the webhook request fails

Synchronous handler

  1. 1Webhook
  2. 2Validate payload
  3. 3Call database
  4. 4Call third-party API
  5. 5Send response
  • The sender waits for every operation
  • Slow dependencies cause timeouts
  • Temporary failures become lost events
  • Retries can duplicate side effects
  • Application requests carry background work

RocketStack workflow

WebhookQueueImmediate response
QueueFunctionProcessing complete
  • The sender receives a fast acknowledgement
  • Events remain available during temporary failures
  • Processing happens outside the request
  • Retry behavior is centralized
  • Failures are visible in the console

Three components, one reliable workflow

1

Webhook endpoint

Validate the request, normalize the payload, and enqueue the event.

  • Verify signatures
  • Create an idempotency key
  • Add the event to Queue
  • Return a successful response
2

Queue

Hold events safely until the processing function is ready.

  • Decouple receipt from processing
  • Retry temporary failures
  • Control delivery
  • Preserve event payloads until delivery
  • Move exhausted messages to a dead-letter queue
3

Function

Run the application logic outside the original webhook request.

  • Update application state
  • Call external services
  • Record results
  • Surface errors

Example workflow

See the workflow process an event

Simulated client-side demo with example timings — not production benchmarks.

Example workflow

Sample webhook payload

{
  "id": "evt_123",
  "type": "payment.completed",
  "customerId": "cus_123",
  "amount": 4900
}

Activity timeline

Example timings

Ready to send an example webhook.

  1. Webhook received
    +0ms
  2. Signature validated
    +18ms
  3. Event added to queue
    +24ms
  4. 202 response returned
    +28ms
  5. Function invoked
    +140ms
  6. Event processed successfully
    +180ms

Build the workflow

Use the RocketStack HTTP API or generated SDKs. Examples below use real request fields.

Step 1 of 4

Create a queue

Language

Create the queue that will hold webhook events until they are processed.

Create a queue · JavaScript
import { Configuration, QueuesApi } from '@rocketstack/sdk';

const queues = new QueuesApi(
  new Configuration({ accessToken: process.env.ROCKETSTACK_API_KEY })
);

// Deploy the Function first, then bind it as the delivery target.
const { data } = await queues.createQueue({
  name: 'webhook-events',
  deliveryTarget: {
    type: 'function',
    functionId: process.env.ROCKETSTACK_FUNCTION_ID
  }
});

console.log(data.data.queueId);

Ready to run this workflow?

Also see Queue and Functions product docs.

Use it with your existing application

Keep your app where it is. Call RocketStack from the webhook route, then return quickly.

App Router route handler that verifies, enqueues, and returns quickly.

Next.js example
// app/api/webhooks/stripe/route.ts
import { headers } from 'next/headers'

export async function POST(request: Request) {
  const rawBody = await request.text()
  const signature = (await headers()).get('stripe-signature')

  // Verify the Stripe signature with your endpoint secret.
  // const event = stripe.webhooks.constructEvent(rawBody, signature, process.env.STRIPE_WEBHOOK_SECRET!)
  const event = JSON.parse(rawBody)

  await fetch(
    `https://api.rocketstack.sh/queues/${process.env.ROCKETSTACK_QUEUE_ID}/messages`,
    {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${process.env.ROCKETSTACK_API_KEY}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        payload: event,
        idempotencyKey: event.id
      })
    }
  )

  return new Response(null, { status: 202 })
}

Related reading: Next.js Stripe webhook starter

Next.js starter

Start from a working Stripe webhook example

Clone a Next.js application with signature verification, RocketStack Queue integration, and asynchronous Function processing.

Retries should not create duplicate work

Principle 1

Use the event ID as an idempotency key

Store processed event IDs before applying irreversible side effects. Pass the provider event ID as idempotencyKey when enqueueing so duplicate deliveries reuse the same queue message.

Principle 2

Separate temporary and permanent failures

Retry network and service failures. Surface invalid payloads for review instead of treating them like transient outages.

Principle 3

Make handlers safe to run again

A repeated delivery should not charge a customer, send an email, or update state twice.

Principle 4

Keep failed work visible

Use the RocketStack console to identify failed resources and processing errors. Messages that exceed maxReceiveCount move to a dead-letter queue for inspection.

Deploy it from your coding agent

Use RocketStack MCP to create the Queue, deploy the Function, and connect the workflow from an MCP-enabled coding client. This workflow uses RocketStack Queue and Functions.

MCP deployment prompt
Add reliable webhook processing to this application using RocketStack.

Requirements:
- Verify incoming webhook requests
- Acknowledge valid requests immediately
- Add each event to a RocketStack Queue
- Deploy a RocketStack Function to process queued events
- Use the webhook event ID to prevent duplicate processing
- Surface processing failures clearly
- Keep secrets in environment variables

See every event from receipt to completion

Build this workflow on the Free plan

Every RocketStack primitive is available on Free with lower monthly usage allowances.

  • Function invocations5,000 / mo
  • Queue messages500 / mo

PRIVATE ALPHA

Build this workflow with the RocketStack team

Bring a real application, complete the setup during a guided session, and help shape the product.

Apply for the alpha

FAQ

Make your next webhook handler reliable

Create a free account, get an API key, and deploy the Queue and Function behind your workflow.