Rate Limiting
Overview​
The Rate Limiting policy is used to control the rate at which requests are sent to an API. This helps prevent abuse, manage traffic loads efficiently, and protect backend services from being overwhelmed by excessive requests. The policy can be configured with different Redis storage options for managing request limits.
By configuring the Rate Limiting policy, API providers can effectively manage traffic, ensure fair resource allocation, and protect backend services from excessive load.
Configuration Details​
The following table outlines the key configuration options available for the Rate Limiting policy:
Field Name | Description | Example Value |
---|---|---|
Maximum requests per second | Defines the maximum number of requests allowed per second for the API. | 100 |
Redis timeout (ms) | Sets the timeout value for Redis operations in milliseconds. | 2000 |
Redis DB Select | Allows selecting a Redis storage type for rate-limiting counters. Options include APIMRedis, CustomRedis, or RedisCluster. | APIMRedis |
Redis Storage Options​
Depending on the system's requirements, users can choose from the following Redis storage types:
- APIMRedis (Default) - Uses the system’s built-in Redis instance.
- CustomRedis - Allows users to configure their own Redis instance by specifying detailed connection parameters.
- RedisCluster - Uses a Redis cluster setup for scalability and fault tolerance.
APIMRedis is recommended for standard use cases, while CustomRedis and RedisCluster should be used for advanced scenarios requiring dedicated Redis configurations.
Custom Redis Configuration Fields​
If selecting CustomRedis, the following additional fields must be configured:
Field Name | Description | Example Value |
---|---|---|
redisHost | The hostname of the Redis server. | 127.0.0.1 |
redisPort | The port used for Redis connections. | 6379 |
redisPassword | The password for Redis authentication (if required). | password |
redisDatabase | Specifies which Redis database to use. | 1 |
redis_pool_size | Defines the number of Redis connections that can be kept in the pool. | 1000 |
redis_pool_backlog | Specifies the number of pending requests that can be queued when the pool is full. | 30 |
Redis Cluster Configuration Fields​
If selecting RedisCluster, additional fields must be set:
Field Name | Description | Example Value |
---|---|---|
redis_cluster_nodes | The address of the Redis cluster node. | redis-cluster.apim:6379 |
redis_cluster_password | The password for accessing the Redis cluster (if applicable). | password |
redis_cluster_name | Defines the name of the Redis cluster. | kong_redis_cluster |
redis_connect_timeout | Timeout for establishing Redis connections (in ms). | 1000 |
redis_read_timeout | Timeout for reading responses from Redis (in ms). | 1000 |
redis_send_timeout | Timeout for sending requests to Redis (in ms). | 1000 |
redis_pool_size | The maximum number of connections that can be allocated in the Redis pool. | 1000 |
redis_pool_backlog | The number of queued requests allowed if the pool is full. | 30 |
redis_keepalive_timeout | Defines how long idle connections should be kept alive (in ms). | 55000 |