API Flow Diagram Guide
What an API flow diagram is, what it has to show to be worth drawing, and three ready-to-edit examples — a REST request, a retry after a timeout, and an async webhook.
What is an API flow diagram?
An API flow diagram shows what actually happens between the moment a client sends a request and the moment it gets a response: which services get involved, in what order, and what each one sends back. It is the picture your API reference does not give you — a reference documents endpoints one at a time, and a single endpoint is almost never the whole story.
The right notation for this is a sequence diagram, not a flowchart. The reason is structural: an API call is a conversation between several parties (client, gateway, auth service, your service, a database, a third-party provider), and the interesting information is who talks to whom, in what order. A sequence diagram puts each party on its own vertical lifeline and draws time downward, so the ordering is the shape of the picture. A flowchart has one implicit actor and no time axis, so the moment you have three services it starts lying.
Where an API flow diagram earns its keep is the unhappy paths. The success path is usually obvious and everyone already agrees on it. What nobody agrees on is: which service returns the 401 — the gateway or the auth service? If the payment provider times out, do we retry? Who is responsible for the 409? Those disagreements are invisible in prose and unmissable in a diagram, because an unlabelled arrow is a hole you can point at.
One diagram per flow, not per endpoint. "Create an order" is a flow; POST /v1/orders is one arrow inside it.
What an API flow diagram has to show
A diagram that only draws the success path is decoration. Five things make it load-bearing:
- Every participant, including the boring ones. The gateway, the cache and the database are the three most commonly omitted, and they are where latency and failure actually live.
- The method and path on the arrow, not just "request".
POST /v1/orderstells the reader which code to open; "create order" does not. - Status codes on the return arrows. This is the single highest-value detail.
201 Createdvs200 OKvs202 Acceptedis a real design decision, and putting it on the arrow forces the team to make it once instead of three times. - At least one failure branch. Use an
altblock. If you cannot name a single way the flow fails, you have not looked hard enough at it yet. - Whether each call is synchronous. A solid arrow that expects a reply and a fire-and-forget enqueue look identical in prose and completely different in a diagram.
Here is the smallest diagram that satisfies the first three. It is the skeleton every example below grows out of — four participants, explicit paths, explicit status code.
View the Mermaid source
sequenceDiagram
participant Client
participant Gateway as API Gateway
participant Service as Orders Service
participant DB as Database
Client->>Gateway: POST /v1/orders
Gateway->>Service: forward with user id
Service->>DB: insert order row
DB-->>Service: order id
Service-->>Gateway: 201 Created
Gateway-->>Client: 201 Created + LocationHow to draw an API flow diagram
Three steps. Do them in this order — people who start by drawing arrows always end up redrawing.
Step 1 · List the participants, then cut them
Write down everything the request touches. Then remove any participant that never sends a message of its own — if a component only sits between two others and forwards bytes unchanged, it is infrastructure, not a participant, and drawing it adds a lifeline without adding information.
Four to six participants is the sweet spot. Past seven the diagram gets wider than a screen and people stop reading it. If you genuinely have nine, that is a signal to split the flow: draw "client → gateway → service" as one diagram and "service → downstream fan-out" as another, and link them.
Step 2 · Draw the happy path, then break it on purpose
Get the success path down first — it is usually five to eight arrows and takes two minutes. Then go back over it and, for each arrow, ask the same three questions:
What if this times out? Not "what if it returns an error" — timeouts are worse, because you do not know whether the other side did the work. That distinction is the whole subject of the second example below.
What if this returns 4xx? Which of the two adjacent participants translates it, and into what? A downstream 404 surfacing to the client as a 500 is one of the most common API bugs, and it is visible in a diagram the moment you draw both arrows.
Can this be retried safely? If yes, say so on the arrow. If not, the diagram needs to show what makes it safe — an idempotency key, a dedup table, a state check.
Each "yes, that can happen" becomes an alt block. Three or four alt blocks is a healthy diagram; zero means you drew the brochure version.
Step 3 · Draw it
Describe the call in plain sentences and let text2diagram lay it out — "a client posts to the gateway, the gateway checks the token with the auth service, then forwards to the orders service, which writes to Postgres and returns 201; if the token is expired the gateway returns 401" comes back as an editable sequenceDiagram.
Faster still: open any example below in the editor and rename the participants. The arrangement of arrows is the part that took thought; the names are the part you can retype in thirty seconds.
API flow diagram examples
Three flows that cover most of what a real API does: a synchronous request with auth, a call that fails in the worst possible way, and an operation too slow to answer inline.
1 · A REST request, end to end
The thing to copy here is not the shape — it is that both failure branches are drawn, and each one names the participant that produces the status code. The gateway returns the 401 (the auth service only says "rejected"); the orders service returns the 409 (the database only says "duplicate key"). Writing that down settles an argument that otherwise gets re-litigated every few months.
autonumber is worth turning on for any diagram over about eight arrows — it gives reviewers something to point at.
View the Mermaid source
sequenceDiagram
autonumber
participant Client
participant Gateway as API Gateway
participant Auth as Auth Service
participant Orders as Orders Service
participant DB as Postgres
Client->>Gateway: POST /v1/orders (Bearer token)
Gateway->>Auth: verify token
alt token expired or invalid
Auth-->>Gateway: rejected
Gateway-->>Client: 401 Unauthorized
else token valid
Auth-->>Gateway: user id and scopes
Gateway->>Orders: POST /orders
Orders->>DB: insert order row
alt unique constraint hit
DB-->>Orders: duplicate key
Orders-->>Gateway: 409 Conflict
Gateway-->>Client: 409 Conflict
else row written
DB-->>Orders: order id
Orders-->>Gateway: 201 Created
Gateway-->>Client: 201 Created + Location
end
end2 · A timeout, and why you cannot just retry
This is the flow most worth having on a wall. A timeout is not an error — an error tells you the work did not happen, a timeout tells you nothing. The dashed --x arrow is Mermaid's notation for a message that never arrived, and it is doing real work here: it visually distinguishes "the provider said no" from "we have no idea".
The resolution is the two arrows after it: look before you retry. Query by idempotency key first, retry only if the lookup comes back empty. Teams that skip that lookup double-charge customers, and the reason it gets skipped is almost always that nobody drew this picture.
View the Mermaid source
sequenceDiagram
autonumber
participant Client
participant API as Your API
participant Provider as Payment Provider
Client->>API: POST /payments (Idempotency-Key abc)
API->>Provider: charge card
Provider--xAPI: timeout after 10s
Note over API: outcome unknown - a blind retry may double charge
API->>Provider: GET /charges by idempotency key
alt charge already exists
Provider-->>API: charge succeeded
API-->>Client: 200 OK
else nothing was charged
API->>Provider: retry with the same key
Provider-->>API: charge succeeded
API-->>Client: 200 OK
end3 · An async operation with a webhook
When the work takes longer than a request should, the API stops being a question-and-answer and becomes two separate conversations. The diagram has to show the seam: the 202 Accepted goes back before any of the real work happens, and everything after it is a different flow that your caller does not control.
Two details people leave out and then regret. First, the retry schedule belongs in the diagram (that Note is not decoration — "how many times do we retry a customer's webhook" is a question support will ask). Second, the customer's endpoint is a participant like any other, which means it gets failure branches too. It is the least reliable box on the page and the one most often drawn as if it always returns 200.
View the Mermaid source
sequenceDiagram
autonumber
participant Client
participant API as Your API
participant Queue
participant Worker
participant Hook as Customer Webhook
Client->>API: POST /exports
API->>Queue: enqueue job
API-->>Client: 202 Accepted + job id
Queue->>Worker: deliver job
Worker->>Worker: build the export file
Worker->>Hook: POST /webhooks/export-ready
alt endpoint returns 2xx
Hook-->>Worker: 200 OK
else endpoint errors or times out
Hook-->>Worker: 500
Worker->>Queue: requeue with backoff
Note over Queue,Worker: 5 attempts - 1m, 5m, 30m, 2h, 12h
endPut the diagram next to the handler, not in a wiki
An API flow diagram goes stale faster than almost any other diagram, because the flows change every sprint while the wiki page does not. Since the source here is plain Mermaid text, commit it in the repo next to the code that owns the flow — GitHub renders Mermaid code blocks in Markdown natively, so the diagram shows up in the README and shows up as a diff in code review. A picture that changes in the same pull request as the behaviour is the only kind that stays true.
FAQ
Should an API flow diagram be a sequence diagram or a flowchart?
A sequence diagram, in almost every case, because an API call involves several parties and the ordering between them is the point. Use a flowchart for the one thing a sequence diagram is bad at: decision logic inside a single component — how your gateway picks a rate-limit bucket, or how a handler maps a downstream error onto a status code. Rule of thumb: if you are listing services, sequence diagram; if you are listing
ifstatements, flowchart.How detailed should an API flow diagram be?
One flow per diagram, four to six participants, and every arrow either a real network call or a state change worth naming. Do not draw internal function calls — that is what the code is for. The test: if a new engineer can read the diagram and correctly predict which service to check first when the endpoint returns 500, it is detailed enough. If they still have to ask, add the missing failure branch, not more boxes.
How do I show authentication in an API flow diagram?
As a real participant with real arrows, not as a note. Draw the token verification as a call to whatever actually verifies it, and draw the rejection branch — the most useful thing this diagram tells a reader is which component returns the 401 and therefore where to look when a valid token gets rejected. If verification is local (a signature check with a cached public key) draw it as a self-message on the gateway's own lifeline, so the reader can see there is no network hop.
Do I need a separate diagram for every endpoint?
No — draw flows, not endpoints. Most endpoints are one arrow inside a flow someone already drew, and a diagram with a single request-response pair tells the reader nothing they could not get from the API reference. Draw a diagram when a flow crosses at least two services, or when it has a failure mode people argue about. For a typical service that ends up being five to ten diagrams, not fifty.
Can I generate an API flow diagram from my OpenAPI spec or code?
Partly, and the gap is the important bit. An OpenAPI spec describes endpoints in isolation — it knows the shapes but not the order, so it cannot tell you that the gateway calls auth before it calls your service. Code tells you more but buries it in call sites. What works in practice is pasting the handler (or the spec plus a sentence of context) and letting the AI produce a first draft, then correcting the ordering and adding the failure branches by hand — the corrections are where the design thinking happens anyway.
Is it free?
Yes. Anonymous users get 20 generations per day, logged-in users 500. Opening any example on this page in the editor costs nothing — that path does not call the model at all.