Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
Sequence Diagram
All Software Architecture templates

Event-Driven Architecture — Mermaid Sequence Diagram

Sequence diagram of an event-driven system with message queue, producers, consumers, and dead letter handling.

What this diagram shows

This Mermaid sequence diagram is an order placed onto a message queue and consumed by three services. Order API publishes OrderCreated. Inventory reserves stock. If stock exists it publishes StockReserved, Payment charges the customer, and on success Shipping creates a shipment. If payment fails, Inventory consumes PaymentFailed and releases the reservation. If stock is missing, Inventory publishes to the dead-letter queue instead of continuing.

Use it when you are explaining why the checkout API returns before the shipment exists. The queue is a participant, which makes the async boundary visible. It is the right figure for a design review of at-least-once delivery, because the failure paths are nested alt blocks rather than a comment in the producer.

Participants are Order API, Message Queue, Inventory, Payment, Shipping, and the dead-letter queue. No database lifelines are drawn. Persistence is implied inside each service's self-message (Reserve stock, Charge customer, Create shipment).

Mermaid syntax in this template

Nested alt/else blocks are the core syntax. The outer alt is stock. The inner alt is payment. A message into the DLQ is the terminal branch for the out-of-stock case.

  • participant OrderAPI as Order API

    The ID has no space. The alias after as is the label readers see. Use the ID on every arrow.

  • alt Stock available

    alt opens a fragment. It must close with end. The else branch here is Out of stock and publishes to the DLQ.

  • Queue->>Payment: Consume StockReserved

    The queue is the sender on consume messages. That reads oddly compared with a direct call, and it is intentional: the consumer did not call the producer.

  • Inventory->>DLQ: Publish OutOfStock

    The dead-letter participant only appears on the failure branch, so the success path stays narrow.

Variations and ways to customize it

Add an idempotency note

Payment can observe the same StockReserved event twice. A note over Payment is the lightest way to say the charge key is the order id.

Note over Payment: Charge is keyed by order id
Payment->>Payment: Charge customer

Show a retry before the DLQ

Insert a loop around the inventory consume. After the third failure, the else of the loop body publishes to the DLQ. Keep the DLQ participant so the poison message has a destination.

loop Up to 3 attempts
    Queue->>Inventory: Consume OrderCreated
end
Inventory->>DLQ: Publish after retries exhausted

Split the queue per event

Replace the single Message Queue participant with OrderQueue, PaymentQueue, and ShipQueue if your review is about topology rather than the business sequence. The alt blocks stay the same.

Diagram type

Sequence Diagram

Tags

eventsmessage queueasyncpub/subCQRS
Open in Editor

Frequently asked questions

What happens when payment fails in this diagram?

Payment publishes PaymentFailed. Inventory consumes it and releases the reserved stock. Shipping never runs. The order API is not called back; it already finished when it published OrderCreated.

Why is the dead-letter queue only on the inventory branch?

The template treats out-of-stock as the poison outcome for OrderCreated. Payment failure is a normal business event, so it is a new message, not a dead letter. Move a payment exception to the DLQ if you want broker-level failure, and keep PaymentFailed for a declined card.

How do I show the queue technology in Mermaid?

Rename the participant alias: participant Queue as SQS or participant Queue as Kafka topic orders. The arrows do not change. Avoid putting broker configuration in the message text; it wraps and hides the event name.

Is this a sequence diagram or a flowchart?

It is a sequenceDiagram because the order of messages across services is the point. A flowchart would show the decision diamonds and hide which service publishes which event.

Related templates and guides

All Software Architecture templates