Skip to content

Sequence diagrams

Use a sequence diagram when order is the point. Participants stay on a horizontal axis and time moves downward, so a reader can see calls, replies, concurrency, and alternatives in context.

diagram.kdiagram
sequence "Place order" {
autonumber
browser: actor "Browser"
api: gateway "API"
orders: service "Orders"
database: database "Postgres"
browser -> api POST /orders
activate api
api -> orders "PlaceOrder"
activate orders
orders -> database "insert"
database --> orders "order"
orders --> api "201 Created"
deactivate orders
api --> browser "order id"
deactivate api
}

Participants use the same id: kind "Label" form as flow diagrams. Messages are rendered in source order. An HTTP call can be the method and the route, with no quotes: POST /orders or GET /orders/{id}. Quote any other label. A reply uses --> (dashed shaft, open head). An asynchronous handoff uses => (solid shaft, open head). An eventual signal uses ~> (dotted shaft, open head). Those are not two spellings of one event. Open heads stay solid; the dashed shaft is what marks a reply.

activate participant starts an execution bar; deactivate participant ends it. Use activations for ownership of work, not around every message. A sync call also opens a bar on its target until the matching reply. Nested calls stack to the right, and a self call is a short bar on that one message.

Sync messages use a filled arrow. Replies are dashed with an open head. Async handoffs stay solid with an open head. Eventual signals are dotted with an open head. create drops the new participant onto the timeline at that message, and destroy ends the lifeline. Longer sequences repeat each surviving participant along the bottom.

diagram.kdiagram
alternate "payment accepted" is success {
orders -> fulfillment "ShipOrder"
} else "payment declined" is danger {
orders -x orders "reject order"
}
parallel "reserve inventory" {
orders -> inventory "Reserve"
} and "authorize payment" {
orders -> payments "Authorize"
}

Available structured fragments include alternate, optional, loop, parallel, critical, break, and section. Keep fragment labels short and factual. Deeply nested fragments are a sign that the sequence is trying to document an implementation rather than explain a scenario.

diagram.kdiagram
note over orders, payments "Authorization expires after 15 minutes"
divider "PaymentCaptured signal"

Notes explain a constraint. Dividers mark a meaningful phase or time jump. Neither should narrate what the messages already say.

Use create and destroy when lifecycle matters:

diagram.kdiagram
create shipment: subprocess "Ship order"
orders -> shipment "start"
activate shipment
shipment --> orders "shipped"
deactivate shipment
destroy shipment

The label on the arrow is the call or the event name. Add payload when the reader needs a few fields from the body. Leave it off when the name is enough, and do not repeat the excerpt on the consumer when the publish already showed it.

diagram.kdiagram
sequence "Charge" {
web: gateway "Web"
orders: service "Orders"
bus: topic "orders.v1"
web -> orders "PlaceOrder" {
payload: """
{
"cartId": "c_91",
"idempotencyKey": "c_91"
}
"""
}
orders => bus "AuthorizeRequested" {
payload: """
{
"cartId": "c_91",
"amount": 4200,
"currency": "usd"
}
"""
}
}

Paste the excerpt between """ so the JSON keeps its own quotes. The card hangs under the arrow and keeps the line breaks you wrote. Its accent follows the message: the edge color for a call, green for an asynchronous handoff, muted for a reply, and danger for a failure. Six lines is the cap; a longer excerpt warns and the card shortens.

The Sketch control on the diagrams below redraws lifelines, message shafts, and shape outlines. Arrowheads and the reply dash stay put.

Charge a cart is the worked example. POST /checkout and PlaceOrder carry the fields that matter, AuthorizeRequested carries the amount on orders.v1, and the consume hop stays a name. Play Charge authorized to follow that chain.

Edit source — diagram updates live
Source

Two gallery specimens cover the two jobs. Charge a cart is the checkout call, the event on the topic, and the reply, with an excerpt only where the fields matter, and it plays Charge authorized. Checkout payment is the full construct specimen: fragments, notes, create, and destroy, with Funds captured and Declined as the two paths.

The example below combines a queue, parallel work, a signal, an alternative, and a temporary child process. Use it as a ceiling for a design review. Most useful sequences are much smaller.

Edit source — diagram updates live
Source

Use a workflow instead when business states and branches matter more than the exact order of messages.