API Platform & Lifecycle · Contract-First Design

AsyncAPI for Event-Driven APIs

Describe channels, messages and bindings for Kafka, AMQP, MQTT and WebSockets.

AsyncAPI does for event-driven systems what OpenAPI does for HTTP: it describes channels (topics/queues), operations (send/receive), messages (payload schemas, headers, correlation IDs) and protocol bindings (Kafka partitions/keys, AMQP exchanges). AsyncAPI 3.0 separates channels from operations, making it clearer who sends and who receives. Generate docs and code, and validate events in CI and at runtime with a schema registry.

OpenAPI vs AsyncAPI

Concept OpenAPI AsyncAPI
Unit Path + method Channel + operation
Direction Request/response send / receive
Protocols HTTP Kafka, AMQP, MQTT, WebSockets, NATS…
Payload Request/response bodies Messages (headers + payload)
asyncapi: 3.0.0
info: { title: Order Events, version: 1.2.0 }
servers:
  production: { host: kafka.internal:9092, protocol: kafka }
channels:
  orderPaid:
    address: orders.order-paid.v1
    messages:
      orderPaid: { $ref: "#/components/messages/OrderPaid" }
operations:
  publishOrderPaid:
    action: send
    channel: { $ref: "#/channels/orderPaid" }
components:
  messages:
    OrderPaid:
      headers: { type: object, properties: { traceparent: { type: string } } }
      payload:
        type: object
        required: [eventId, orderId, total, occurredAt]
        properties:
          eventId: { type: string, format: uuid }
          orderId: { type: string }
          total: { type: integer, description: Minor units }
          occurredAt: { type: string, format: date-time }
      bindings: { kafka: { key: { type: string, description: orderId } } }

Common pitfalls

  • Undocumented events that other teams reverse-engineer.
  • Schemas without versioning or compatibility rules.
  • Ignoring headers (trace context, correlation IDs).

Key points

  • Channels, operations, messages, bindings
  • AsyncAPI 3 separates channels and operations
  • Pair with a schema registry

Further reading: AsyncAPI 3.0 specification

Practice questions

What did AsyncAPI 3.0 change about operations?

Answer

Operations are defined separately from channels with an explicit action (send/receive), removing the confusing publish/subscribe perspective of 2.x.

Why document the Kafka message key in AsyncAPI?

Answer

Consumers rely on the key for partitioning and ordering guarantees (e.g., all events of one order are ordered); it's part of the contract.

Open in the app to mark lessons complete, take notes and track your progress.