Skip to main content
Vertex
Docs/Building Idempotent Webhook Consumers
7 min readv2.4
WebhooksDifficulty: Intermediate

Building Idempotent Webhook Consumers

How to engineer resilient webhook receivers that survive duplicate deliveries, network timeouts, and out-of-order events using Redis deduplication.

By Devon K. (Staff Systems Engineer)•Published Oct 14, 2026

Building Idempotent Webhook Consumers

Network partitions, client timeouts, and automated upstream retries mean that your webhook receiver will occasionally receive the same event multiple times. Designing your ingestion endpoint to be strictly idempotent is essential for data consistency.


The At-Least-Once Delivery Reality

Vertex guarantees at-least-once delivery for all webhook events. In scenarios where your server processes an event but crashes before sending an HTTP 200 OK, Vertex’s retry engine will dispatch the payload again.

Every webhook payload includes an immutable unique event ID (evt_01H...):

{
  "id": "evt_01HXY882910Z",
  "type": "inference.session.completed",
  "created": 1792440100,
  "data": { ... }
}

Redis Deduplication Lock Pattern

Use Redis atomic SETNX with a 24-hour expiration key:

import { Redis } from 'ioredis';

const redis = new Redis(process.env.REDIS_URL);

async function handleWebhook(event: { id: string; type: string; data: any }) {
  const lockKey = `webhook:lock:${event.id}`;
  
  // Set key only if it doesn't already exist (NX) with 86400s (24h) TTL
  const acquired = await redis.set(lockKey, 'processing', 'EX', 86400, 'NX');
  
  if (!acquired) {
    // Duplicate delivery detected. Acknowledge HTTP 200 immediately
    console.log(`Duplicate event ${event.id} suppressed.`);
    return { status: 200, message: 'Already processed' };
  }

  try {
    await processBusinessLogic(event);
    await redis.set(lockKey, 'completed', 'EX', 86400);
    return { status: 200, message: 'Success' };
  } catch (err) {
    // Release lock so retry can be attempted
    await redis.del(lockKey);
    throw err;
  }
}
Was this documentation page helpful?

Help us improve the Vertex developer experience.