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

HappyHorse-1.0 vs Seedance 2.0: which AI video model wins right now?

HappyHorse-1.0 vs Seedance 2.0: which AI video model wins right now?

HappyHorse-1.0 leads on visual quality benchmarks (T2V Elo 1333 vs Seedance 2.0’s 1273) but has no stable API and no consumer access. Seedance 2.0 has a ByteDance backing, consumer access via Dreamina, and leads on audio generation

10 April 2026

Best free AI face swapper in 2026: no signup options, API access, ethical use

Best free AI face swapper in 2026: no signup options, API access, ethical use

The best free AI face swappers in 2026 are WaveSpeedAI (no-signup web tool, full REST API, consent-first design), Reface (mobile app), DeepFaceLab (open source desktop), Akool (API-ready), and Vidnoz (web-based).

10 April 2026

How to use Google Genie 3: interface walkthrough, generation tips, and what to expect

How to use Google Genie 3: interface walkthrough, generation tips, and what to expect

Google Genie 3 is a sketch-to-video model in limited research access as of early 2026. Access is through experimental demos and select partner pilots, not a public API.

10 April 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs