diagram.mmd — sequence
REST API Request Lifecycle sequence diagram

A REST API request lifecycle describes the complete journey a client request takes from the moment it leaves the browser or application through authentication, business logic, data persistence, and back as a structured HTTP response.

What the diagram shows

This sequence diagram traces a single REST API call across four participants: the Client, an API Gateway, the Application Server, and a Database. The flow begins when the client issues an HTTP request — for example, GET /users/42. The API Gateway intercepts the request first, validating the authentication token and checking whether the request should be rate-limited before proxying it upstream.

Once the request reaches the Application Server, it is routed to the correct handler, which constructs and executes a database query. The Database returns the result set, the server serializes the payload into JSON, and the response travels back through the gateway to the client — carrying the appropriate HTTP status code (200 for success, 4xx/5xx for errors).

The diagram also captures the error branch: if authentication fails at the gateway, the server never receives the request and the client immediately receives a 401 Unauthorized response. This short-circuit behavior is one of the key reasons API gateways exist.

Why this matters

Understanding the full request lifecycle helps developers:

- Debug latency: knowing that serialization, query execution, and network hops all contribute to total response time lets you profile the right layer. - Design error handling: each hop can fail independently. Modeling the lifecycle explicitly reveals where timeouts, retries, and circuit breakers need to live. - Secure the API: authentication and authorization checks at the gateway reduce the attack surface before business logic is ever reached.

For a deeper look at the gateway layer, see the API Gateway Request Flow. If your API sits behind multiple services, the Microservice Request Chain extends this pattern to distributed architectures. To understand how throttling is applied earlier in the pipeline, explore Rate Limiting Architecture.

Free online editor
Edit this diagram in Graphlet
Fork, modify, and export to SVG or PNG. No sign-up required.
Open in Graphlet →

Frequently asked questions

The REST API request lifecycle describes the complete journey a client request takes from leaving the browser or application through authentication, business logic, data persistence, and back as a structured HTTP response. It encompasses every layer — API gateway, application server, and database — and the handoffs between them.
The client issues an HTTP request (e.g., GET /users/42) which first hits the API gateway. The gateway validates the authentication token (returning 401 if invalid) and checks rate limits (returning 429 if exceeded), then proxies the request to the application server. The server routes it to the correct handler, which queries the database, serializes the result to JSON, and returns the response back through the gateway to the client.
Authentication happens at the API gateway before the request ever reaches the application server. The gateway validates credentials — typically a JWT or API key — and either passes the request upstream with identity context attached or immediately returns a 401 Unauthorized. This short-circuit behavior is one of the primary reasons API gateways exist: it keeps unauthenticated traffic away from application logic entirely.
The most common culprit is slow database queries — the application server's query execution is typically the largest share of total response time. N+1 query patterns (fetching a list, then querying each item individually) are a frequent source of unexpected latency. Serialization overhead for large response payloads and missing connection pool configuration (causing the server to wait for database connections) are also common issues that the lifecycle view helps diagnose.
mermaid
sequenceDiagram participant C as Client participant GW as API Gateway participant AS as Application Server participant DB as Database C->>GW: HTTP GET /users/42 GW->>GW: Validate auth token alt Token invalid GW-->>C: 401 Unauthorized else Token valid GW->>GW: Check rate limit alt Rate limit exceeded GW-->>C: 429 Too Many Requests else Within limit GW->>AS: Forward request AS->>AS: Route to handler AS->>DB: SELECT * FROM users WHERE id=42 DB-->>AS: Row data AS->>AS: Serialize JSON response AS-->>GW: 200 OK + JSON body GW-->>C: 200 OK + JSON body end end
Copied to clipboard