Skip to main content

Backend Traffic Policy Reference

Reference of the backend traffic policy: how the gateway sends requests to the backend of an API. It is deployed as an Envoy Gateway BackendTrafficPolicy.

Policy Target​

FieldValuesMeaning
targetRef.kindHTTPRoute, Gateway, GRPCRouteAn API instance, or a whole gateway
targetRef.nameNameThe API instance or the gateway
targetRef.sectionNameName, optionalOne access point of a gateway

Rate limit​

Why. Protect a backend from more traffic than it can serve, and keep one caller from starving the others.

ParameterDefaultMeaning
requestsRequiredRequests allowed in the window
unitMinuteSecond, Minute or Hour

Consequences. Beyond the limit the gateway answers 429.

The limit is local to each gateway instance

The counter is kept by each instance of the gateway, not shared. With two instances, the effective limit is up to twice the configured value. Size it per instance, and remember that autoscaling the gateway changes the total.

Procedure: Rate limiting.

Timeout Fields​

Why. Without a timeout, a backend that stops answering holds a connection and a caller indefinitely. Timeouts bound how long the gateway waits at each stage.

ParameterDefaultMeaning
connectTimeoutGateway defaultMaximum time to open a connection to the backend, such as 5s
requestTimeoutGateway defaultMaximum time for the complete response, such as 30s
idleTimeoutGateway defaultClose backend connections idle for this long, such as 1h

Consequences. A request that exceeds requestTimeout is answered 504 and the backend call is abandoned, although the backend may still complete it.

Order the timeouts

Client timeout above gateway requestTimeout above the timeout the route applies to its own outgoing calls. Otherwise the caller gives up first and the work is wasted.

Procedure: Request timeouts.

Retry Fields​

Why. Many failures are transient: a connection reset, an instance restarting. A retry hides them from the caller, at the cost of sending the request again.

ParameterDefaultMeaning
numRetries2Attempts after the first failure
perRetryTimeout—Maximum time of each attempt
triggers5xx5xx, gateway-error, connect-failure, reset, retriable-4xx, retriable-status-codes
httpStatusCodes—Status codes retried when retriable-status-codes is a trigger
baseInterval25msWait before the first retry; grows exponentially
maxInterval250msUpper bound of the wait
Retries repeat side effects

A retried POST may be executed twice by the backend. Retry on connect-failure and reset for any operation; retry on 5xx only when the operation is idempotent or deduplicated.

Consequences. Worst-case duration is (numRetries + 1) × perRetryTimeout plus the waits: keep it below requestTimeout. Retries multiply load on a backend that is already failing, pair them with a circuit breaker.

Procedure: Retries.

Circuit breaker​

Why. Cap what the gateway sends to a backend, so that a slow backend fails fast instead of accumulating requests.

ParameterDefaultMeaning
maxConnections1024Concurrent connections to the backend
maxPendingRequests1024Requests waiting for a connection
maxParallelRequests1024Requests in progress
maxParallelRetries1024Retries in progress

Consequences. Beyond a cap the gateway answers 503 immediately. The caps apply per gateway instance.

Procedure: Circuit breaker.

Load balancing​

Why. When a backend has several instances, the algorithm decides which one receives each request. The default suits most cases; change it for uneven request durations or for session affinity.

ParameterDefaultMeaning
algorithmRoundRobinRoundRobin, LeastRequest, Random, ConsistentHash
affinityKeySourceIPWith ConsistentHash: SourceIP, Header or Cookie
headerNamex-user-idHeader used as key
cookieNamesessionCookie used as key
cookieTTLSession cookieLifetime of the cookie, such as 3600s
AlgorithmUse
RoundRobinHomogeneous instances, short requests
LeastRequestRequests of uneven duration
ConsistentHashSession affinity, local caches

Active health check​

By default the gateway relies on the readiness reported by the platform. An active health check makes the gateway probe each instance itself and stop sending to those that fail.

ParameterDefaultMeaning
healthCheck.protocolHTTPHTTP, TCP or GRPC
healthCheck.interval3sTime between probes
healthCheck.timeout1sTime allowed for a probe
healthCheck.unhealthyThreshold3Consecutive failures before an instance is removed
healthCheck.httpPath/healthzPath probed over HTTP
Affinity is not a guarantee

With ConsistentHash, a change in the number of backend instances remaps part of the keys. Keep session state outside the instances when it must survive a scale-out.

Procedure: Load balancing.