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?

Apidog for Enterprise

On-Premises Deploy

SSO & RBAC

SOC 2 Compliant

Explore Apidog Enterprise

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

How to Use Codex with GPT-5.5 for Free  (Unlimited Until August 2026)

How to Use Codex with GPT-5.5 for Free (Unlimited Until August 2026)

Pioneer.ai's Pro tier is unlimited until August 2026. Wire it to Codex CLI with five config flags and get GPT-5.5, Claude Opus, and DeepSeek for free.

1 June 2026

How to Use MiniMax M3 for Free: Open Weights and Low-Cost Access

How to Use MiniMax M3 for Free: Open Weights and Low-Cost Access

How to use MiniMax M3 for free: self-host the open weights, use free trials, and find the cheapest way to access M3's 1M-context coding model.

1 June 2026

How to Use the MiniMax M3 API?

How to Use the MiniMax M3 API?

How to use the MiniMax M3 API: get a key, make your first call, toggle thinking, handle 1M-token context, and test requests in Apidog.

1 June 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs