Skip to main content
The Rate Limit Traffic Policy action enables you to configure thresholds that restrict the throughput of traffic that successfully reaches your endpoint. Traffic may be limited overall or by attributes of the incoming requests.

Configuration reference

The Traffic Policy configuration reference for this action.

Supported phases

on_http_request

Type

rate-limit

Configuration fields

Behavior

Determining the rate limit bucket

When this action is executed, information from the incoming HTTP request is used to determine which rate limit bucket the request falls into. Each bucket is defined by specific criteria through the bucket_key configuration field such as client IP, request host, or a header value. If the bucket has not exceeded its capacity, the request proceeds to the next action in your policy configuration.

Multiple buckets

If multiple bucket_key values are specified, the action will create a unique rate limit bucket for each combination of the specified keys. For example, if you have two bucket_key values, such as req.host and conn.client_ip, all incoming requests that have the exact same combination of Host header and client IP will be grouped into the same rate limit bucket. To rate limit separately with two different buckets, you can create multiple rate-limit actions instead.

Rate limit exceeded

If the identified bucket has received more events than its capacity over the specified duration:
  1. The request is rejected with an HTTP 429—Too Many Requests status code.
  2. The retry-after header is included in the response, indicating the number of seconds after which the request may be retried.

Capacity per ingress server

Currently, the capacity for each rate limit bucket is applied per ingress server. This means that each server independently tracks the number of requests and enforces the rate limits accordingly.

Non-terminating action

This is a Non-terminating action. It does not return a response, and will allow Traffic Policy processing to continue to the next Action in the chain. All Cloud Endpoint Traffic Policies must end with a terminating action. This requirement does not apply to Agent Endpoints.

Examples

Rate limit by host header

The following Traffic Policy configuration demonstrates how to use the rate-limit action to rate limit all incoming requests by the Host header.

Example Traffic Policy document

For this example, assume that ngrok is pointing at the upstream service https://httpbin.org.

Example request

In this example, a connection attempt to httpbin.ngrok.app using the curl command returns a 429 status code with a retry-after header indicating the number of seconds to wait before retrying the request.

Action result variables

The following variables are made available for use in subsequent expressions and CEL interpolations after the action has run. Variable values will only apply to the last action execution, results are not concatenated.