Skip to main content

Apply Rate Limiting

Refuse requests beyond a number per second, minute or hour, before they reach your service.

How it works​

The gateway counts requests over a window and answers 429 beyond the limit. It protects the service from overload and keeps one caller from consuming everything.

Counted per gateway instance

Each instance of the gateway keeps its own counter: with three instances the effective limit is up to three times the value.

Every parameter and its default: reference.

Use cases​

To protect a service from overload, from a client that loops, or from an unexpected peak.

Prerequisites​

Procedure​

  1. In API Manager, go to API Instances and open the API. To cover everything published on a gateway instead, open the gateway.
  2. Open its Backend traffic policies and add the rule rate limit.
  3. In Max Requests, give the number of requests allowed.
  4. In Time Unit, choose the window: second, minute or hour.
  5. Deploy.

Parameters​

FieldWhat it isDefault
Max RequestsThe number of requests allowed in the window.100
Time UnitThe window the limit is counted over: second, minute or hour.Minute

Verification​

Beyond the limit
for i in $(seq 1 120); do curl -s -o /dev/null -w "%{http_code}\n" https://orders.example.com/orders; done | sort | uniq -c
Result, with 100 requests per minute
100 200
20 429

Behavior and limits​

  • A refused request is answered 429 Too Many Requests.
  • Size the limit above what a well-behaved client sends at its busiest.

See also​