When to use it
Microservice architecture design, integration notes and technical reviews. activate / deactivate draws the period during which a service is handling a request; the message queue decouples the notification from the main call chain, so synchronous calls and asynchronous events are easy to tell apart.
Making it yours
- Add a service with
participant X as Name; participants are laid out left to right in the order they first appear. - Synchronous calls use
->>plus a-->>reply; asynchronous events use a single->>with no reply. - Add timeouts and fallbacks with
alt Inventory service timed out … else … endaround the reservation. - Add
autonumberunder the first line if you want numbered messages.
Mermaid code
sequenceDiagram
participant C as Client
participant G as API gateway
participant O as Order service
participant I as Inventory service
participant Q as Message queue
participant N as Notification service
C->>G: POST /orders
G->>O: Create order
activate O
O->>I: Reserve stock
activate I
I-->>O: Stock reserved
deactivate I
O->>Q: Publish "order created" event
O-->>G: 201 with order id
deactivate O
G-->>C: Return order id
Q->>N: Consume event
N-->>C: Push "order placed" notificationAsk an AI for one with this structure
Send the prompt below to ChatGPT or Claude, then paste the whole reply into the editor; the code inside is detected automatically.
Draw a microservice order creation sequence diagram in Mermaid sequenceDiagram syntax with participants Client, API gateway, Order service, Inventory service, Message queue and Notification service. The client calls the gateway, which calls the order service; the order service synchronously reserves stock with the inventory service, publishes an "order created" event to the queue and returns the order id; the notification service consumes the event and pushes a notification to the client. Use activate/deactivate for the order and inventory services. Output only the mermaid code block.
FAQ
- What is the difference between activate and the + / - shorthand?
O->>I: Reserve stockfollowed byactivate Iis the same asO->>+I: Reserve stock, and-->>-matches deactivate. The long form reads more easily; AI-generated code uses both.- Too many participants make the diagram wide
Merge minor participants (for example gateway and client), or group services with
boxand shorten names. SVG export scales without loss.- How do I name the event on the queue?
Put it in the message text in quotes, for example "order created". Avoid semicolons in message text.
More in this category
Updated 2026-09-05