Docs Examples Webhook → Queue → Function
Queue

Webhook → Queue → Function

Absorb traffic spikes and process webhooks reliably.

The Pattern

Webhook Queue Function

Why this pattern?

  • Fast acknowledgment: Return 200 immediately, process later
  • Automatic retries: Queue handles failures with exponential backoff
  • Spike absorption: Queue buffers bursts, Functions process at steady rate
  • Idempotency: Each message has a UUID for deduplication
Example implementation
// 1. Create a queue with function delivery (once), then enqueue from webhook
// Create queue: POST .../queues with deliveryTarget: { type: 'function', functionId: 'fn_xxx' }
// Your webhook endpoint (e.g., /api/stripe-webhook)
app.post('/api/stripe-webhook', async (req, res) => {
  res.status(200).send('OK');

  // Enqueue to your existing queue (queueId from create)
  await fetch(`https://api.rocketstack.dev/queues/${process.env.ROCKETSTACK_QUEUE_ID}/messages`, {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ payload: req.body })
  });
});

// 2. Your Function processes the queued message (deliveryTarget.functionId)
// fn_process_payment handles retries automatically
export default async function handler(event) {
  const { type, data } = event.payload;

  if (type === 'payment_intent.succeeded') {
    await updateOrderStatus(data.id, 'paid');
    await sendConfirmationEmail(data.customer_email);
  }

  return { processed: true };
}
Free tier available

Ready to start building?

Create your free account and integrate infrastructure primitives in minutes.