A request's journey¶
ConceptExplains how it works and why.
What happens between a caller's request arriving on a listener and the answer leaving. Knowing this order explains every trace in the request inspector and every refusal code.
1. Listener¶
The listener accepts the connection (HTTP/1.1, HTTP/2 with gRPC on it, TLS if configured, WebSocket upgrades) and applies its limits: header size, header read timeout, idle timeout, connection cap.
2. Routing¶
The router matches host, path, method and header conditions against the deployed configuration,
which is an in-memory structure compiled at deploy time. Path parameters are captured. Nothing
here touches a database. No match answers 404 APX-RT-0001.
3. The request chain¶
The matched operation's policy chain runs in phase order, whatever order you wrote the policies in:
| Phase | Typical policies | On refusal |
|---|---|---|
| Access | ip-filter, cors (preflights answered here), allow-methods |
403, 204, 405 |
| Protection | request-size-limit, threat-protection, deny |
413, 400, the deny status |
| Authentication | api-key, jwt, basic |
401 with WWW-Authenticate |
| Authorization | subscription, lifecycle |
403, 410 |
| Traffic | rate-limit, concurrency-limit |
429, 503 with Retry-After |
| Cache | cache (a hit answers here, without the backend) |
|
| Transformation | transform, set-header, upstream-auth |
400 for a failing body program |
Environment flow hooks run before the whole chain (client side) and after the backend (backend side). Each policy leaves a step in the trace with its decision, reason and duration. A refusal short-circuits: later policies do not run, the backend is not called, and the answer is the uniform error body.
4. The backend call¶
Right before the backend is called, a policy that acts at dispatch time (forward, which drops
the client headers and parameters it does not allow) leaves a dispatch step in the trace, and
a route with a mirror sends its copy and leaves a mirror step, and a route with a canary
picks the side that answers and leaves a canary step. A mock-response, or a
service-callout with respond, answered in step 3 and never gets here.
The upstream picks a target by its balancer, skipping ejected targets and open circuit breakers,
connects with the configured timeouts, and retries on the configured conditions within the retry
budget. Credentials the caller sent are stripped unless a policy says otherwise; identity headers
(X-Apinx-Application, X-Apinx-Subject) and X-Forwarded-* are set. WebSocket,
Server-Sent Events and gRPC streams are streamed; a gRPC call's status is read from its
trailers at the end.
5. The response chain¶
Response-side policies run in reverse phase order: transforms and header rules, normalize-errors
shapes error bodies, the cache stores what is cacheable, compress encodes the body for a caller
that accepts it (last, so the cache holds the plain body), rate-limit adds its headers,
lifecycle adds deprecation headers, upstream-auth reacts to a 401 from the backend, then the
backend-side flow hook.
A refusal by a policy (a 401, a 403, a 429) and an error the gateway answers itself (a backend
that could not be reached, a timeout) still run the response hooks of the policies that ran on
the request, so the answer carries the CORS headers, the rate-limit allowance and the deprecation
notices a success would. The body and status stay the uniform error ones. A CORS preflight
reaches the cors policy even when the operation lists methods without OPTIONS.
6. Telemetry¶
One event per request is emitted after the response is written: the access log line, the analytics rollups and the request inspector consume it asynchronously on a bounded queue. Nothing in steps 1 to 5 waits for storage.
Timing in the trace¶
This is the trace of one request in Analyze → Traffic:
1
2
3
4
5
- The summary: status, total time, and how much of it was the backend and how much the gateway.
- The flow this request took. A step that refused the request is marked, and the steps after it are missing.
- Select a step to read what it decided, why, and how long it took.
- Decisions lists every step; Request and Response show the headers; cURL gives a command that repeats the call.
- The timeline places each step on the total time, so a slow one is easy to see.
The inspector's tiles split the total into gateway time (steps 2, 3 and 5) and backend time (step 4). On a typical route the gateway part is well under a millisecond; a jq body transform or a JWKS refresh shows up as its own step so you can see it.