How Do You Build Event-Driven APIs with Webhooks and Message Queues?

Event-driven APIs decouple services and enable asynchronous processing. Learn how to combine webhooks, message queues, and event buses with Modern PetstoreAPI patterns.

Ashley Innocent

Ashley Innocent

13 March 2026

How Do You Build Event-Driven APIs with Webhooks and Message Queues?

TL;DR

Event-driven APIs use webhooks for external notifications and message queues for internal processing. Publish events to a queue (RabbitMQ, Kafka), process asynchronously, and notify clients via webhooks. Modern PetstoreAPI uses this pattern for order processing, inventory updates, and payment notifications.

Introduction

A customer places an order. Your API needs to charge payment, update inventory, send email, notify warehouse, and trigger webhooks. Do you do all this synchronously, making the customer wait 10 seconds? Or respond immediately and process asynchronously?

Event-driven APIs respond fast and process in the background. The order endpoint returns 201 Created immediately. Events trigger background processing. Webhooks notify clients when complete.

Modern PetstoreAPI uses event-driven architecture for orders, payments, and inventory.

Apidog helps you test webhooks, validate event flows, and simulate async processing.

button

Event-Driven Architecture

Event-driven APIs publish events when things happen. Other services subscribe and react.

Components

  1. Event Producer - API endpoint that publishes events
  2. Event Bus/Queue - Routes events (RabbitMQ, Kafka, SQS)
  3. Event Consumer - Background workers that process events
  4. Webhooks - Notify external clients

Flow

Client → POST /orders → API
API → Publish "order.created" → Queue
API → Return 201 Created → Client
Worker → Consume event → Process order
Worker → Publish "order.completed" → Queue
Webhook Worker → Send webhook → Client

Webhooks for External Events

Webhooks notify external clients about events.

// Publish event when order created
app.post('/v1/orders', async (req, res) => {
  const order = await createOrder(req.body);

  await eventBus.publish('order.created', {
    orderId: order.id,
    userId: order.userId,
    total: order.total
  });

  res.status(201).json(order);
});

// Background worker sends webhooks
eventBus.subscribe('order.completed', async (event) => {
  const webhooks = await getWebhooks(event.userId, 'order.completed');

  for (const webhook of webhooks) {
    await sendWebhook(webhook.url, {
      event: 'order.completed',
      data: event
    });
  }
});

Message Queues for Internal Events

Message queues handle internal event processing.

RabbitMQ Example

// Publisher
await publishEvent('order.created', { orderId: '019b4132' });

// Consumer
await consumeEvents('order.*', async (event) => {
  await processOrder(event);
});

How Modern PetstoreAPI Implements Event-Driven APIs

Order Processing

  1. POST /orders returns 201 immediately
  2. Publish order.created event
  3. Payment worker processes payment
  4. Inventory worker updates stock
  5. Email worker sends confirmation
  6. Webhook worker notifies client

See Modern PetstoreAPI event architecture.

Testing with Apidog

Apidog supports event-driven API testing:

Conclusion

Event-driven APIs improve performance and scalability. Use webhooks for external notifications and message queues for internal processing. Modern PetstoreAPI demonstrates production-ready event-driven patterns.

FAQ

What’s the difference between webhooks and message queues?

Webhooks notify external clients over HTTP. Message queues handle internal service communication.

Which message queue should I use?

RabbitMQ for simplicity, Kafka for high throughput, AWS SQS for managed service.

How do you handle webhook failures?

Implement retry logic with exponential backoff (see our webhook reliability guide).

Can you use events without message queues?

Yes, but queues provide durability, retry, and decoupling.

How do you test event-driven APIs?

Use Apidog to test webhooks and validate event flows.

Explore more

What is Tokenization? The Ultimate Guide to API Security

What is Tokenization? The Ultimate Guide to API Security

Tokenization is a powerful method to secure sensitive data by replacing it with non-sensitive tokens. In this guide, we explore the core concepts of tokenization, compare it with encryption, review key benefits and use cases, and show how to design and test secure APIs using Apidog.

13 March 2026

How Do You Stream API Responses Using Server-Sent Events (SSE)?

How Do You Stream API Responses Using Server-Sent Events (SSE)?

Server-Sent Events let you stream API responses in real-time. Learn how to implement SSE for live updates, AI streaming, and progress tracking with Modern PetstoreAPI examples.

13 March 2026

How Should You Design Reliable Webhooks?

How Should You Design Reliable Webhooks?

Webhooks are unreliable by nature. Learn how to design production-ready webhooks with retry logic, idempotency, signature verification, and timeout handling using Modern PetstoreAPI patterns.

13 March 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs