Expected behavior for the Rate Limiting plugin with a path identifier

Uses: Kong Gateway
TL;DR

What is the expected behaviour for the Rate Limiting plugin with path identifier?

With config.identifier=path, the Rate Limiting plugin keeps a separate counter for the exact path configured on the plugin, and a second, shared counter for every other path on the same service or route. Requests to the configured path only consume that path’s limit; requests to any other path share the other counter, so total throughput across all paths can exceed the configured limit.

What is the expected behavior for the Rate Limiting plugin with a path identifier

When configuring the Rate Limiting or Rate Limiting Advanced plugin with a path identifier, what is the expected behavior?

When configuring the Rate Limiting plugin (or Rate Limiting Advanced) with config.identifier=path it means the plugin will have a counter for the path configured and another counter for the paths that don’t match the configured path. For example:

  • Configure a service to httpbin.org/anything

  • Configure 3 routes for that service: /http1 /http2 /http3

  • Configure the Rate Limiting plugin at the service level and set: identifier=path, strategy=local, path=/http1, window_size=[ 60 ], limit=[ 3 ], window_type=fixed

We are configuring 3 requests per minute. This means the plugin will have a counter for the path /http1 and a counter for the other paths (also using fixed window for an easier understanding). Let’s see an example:

  • We are going to send 6 requests within the same window. We can confirm we are in the same window with the header RateLimit-Reset (RateLimit-Reset:53 throughout)

  • We are going to send 4 requests to /http1. The first 3 will respond with a 200 OK and the forth 429 Too Many Requests (note RateLimit-Remaining:0)

  • We are going to send 2 requests more, to /http2 and /http3. We still are in the same window (RateLimit-Reset:53). We see now both requests respond with a 200 OK as they use another counter. Also, you can see they use the same counter, for /http2 RateLimit-Remaining:2 and for /http3 RateLimit-Remaining:1


curl -I http://proxy.kong/http1
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 2
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 2

curl -I http://proxy.kong/http1
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 1
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 1

curl -I http://proxy.kong/http1
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 0
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 0

curl -I http://proxy.kong/http1
HTTP/1.1 429 Too Many Requests
Retry-After: 53
RateLimit-Reset: 53
RateLimit-Remaining: 0
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 0

curl -I http://proxy.kong/http2
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 2
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 2

curl -I http://proxy.kong/http3
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 1
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 1

Note if we don’t configure any path, the plugin will only accept 3 requests per minute. In this case, it accepts 6 requests per minute:

  • 3 for /http1

  • 3 for either /http2 or /http3 (or any other path configured)

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!