Microservices API Gateway — Mermaid Flowchart
Flowchart of an API gateway routing requests to microservices with auth, rate limiting, and load balancing.
What this diagram shows
This Mermaid flowchart starts at the client and stops at each service's dependency. The API gateway faces two diamonds before any business service runs: a rate-limit check that returns 429, and an auth middleware that returns 401. Requests that pass both hit a route resolver, which fans out to User, Order, Payment, and Notification. User and Order read their own databases. Payment calls Stripe and a payments database. Notification calls email and push.
Use it in an architecture doc when the question is what the gateway is allowed to reject before traffic reaches a service. It is also a good onboarding diagram for a new backend engineer, because the 401 and 429 branches are explicit instead of hidden in middleware code. It does not show service-to-service calls. Order does not talk to Payment on this chart; the client, or a later event, would do that.
The node shapes carry the meaning. Rectangles are processes and services. Diamonds are the two checks. Cylinders are databases. The Stripe, email, and push nodes are external systems sitting beside the notification and payment services.
Mermaid syntax in this template
The chart is flowchart TD, so the client is on top and the databases sit at the bottom. Edges are unlabeled except where the diamond needs a Yes/No style label.
flowchart TDTop-down layout. Use LR instead if you want the gateway on the left and the services in a row, which reads more like a network sketch.
RateLimit{Rate Limit Check}Curly braces draw a diamond. Both outgoing edges need labels, here Exceeded and OK, or the branch is ambiguous.
Client[Client App]Square brackets are a process rectangle. IDs (Client, Gateway, UserSvc) stay short so edge lines do not have to quote them.
UserDB[(Users DB)][( ) ] is the cylinder shape. Use it only for datastores so a reader can separate Postgres from a service box.
Variations and ways to customize it
Add a service-to-service call
If order creation charges a card, draw OrderSvc to PaymentSvc directly. Keep that edge visually distinct from the gateway edges so it is obvious the call skipped the public router.
OrderSvc --> PaymentSvc
PaymentSvc --> Stripe[Stripe API]Show a circuit breaker
Put a diamond after the route resolver for one unhealthy downstream. The failure label should name the status you return, usually 503, so it is not confused with the 401 from auth.
Router --> OrderHealth{Order Service Up?}
OrderHealth -->|No| R503[503 Service Unavailable]
OrderHealth -->|Yes| OrderSvc[Order Service]Split public and internal routes
Add a second subgraph for internal admin routes that skip the rate limiter but still pass auth. Subgraphs keep the public 429 path from mixing with the admin path.
Diagram type
FlowchartTags
Frequently asked questions
Why does the gateway return 429 before 401?
The template checks the rate limit first, then auth. That matches a gateway that spends less work rejecting floods before it verifies a signature. Swap the two diamonds if your gateway authenticates first and rate-limits per user id.
How do I add another microservice to this Mermaid flowchart?
Add a rectangle after the route resolver and give it the same kind of downstream the others have: a cylinder for a database or a named external API. Connect it with Router --> NewSvc so the edge starts at the resolver, not at the client.
Does this diagram show Kubernetes or just logical services?
It is logical. There are no pods, ingress objects, or namespaces. Pair it with the Kubernetes architecture template if the audience needs the cluster layout, and keep this chart for the request path.
What Mermaid shape should I use for Redis?
Use a cylinder, the same [( )] form as Users DB. A rectangle reads as a service that runs code. A cache is storage on this chart.
Related templates and guides
All Software Architecture templatesEvent-Driven Architecture
Sequence diagram of an event-driven system with message queue, producers, consumers, and dead letter handling.
Load Balancer with Health Checks
Flowchart showing a load-balanced web architecture with health checks, auto-scaling, and failover routing.
CI/CD Deployment Pipeline
Flowchart showing a complete CI/CD pipeline from code push through testing, staging, and production deployment.
Mermaid flowchart syntax
Diamonds, cylinders, and edge labels used for the rate-limit and auth checks.
Flowchart syntax guide
Node shapes and subgraphs to extend this gateway diagram.