Skip to main content

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 NameDescriptionExample Value
Maximum requests per secondDefines 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 SelectAllows selecting a Redis storage type for rate-limiting counters. Options include APIMRedis, CustomRedis, or RedisCluster.APIMRedis

Rate-Limiting

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 NameDescriptionExample Value
redisHostThe hostname of the Redis server.127.0.0.1
redisPortThe port used for Redis connections.6379
redisPasswordThe password for Redis authentication (if required).password
redisDatabaseSpecifies which Redis database to use.1
redis_pool_sizeDefines the number of Redis connections that can be kept in the pool.1000
redis_pool_backlogSpecifies 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 NameDescriptionExample Value
redis_cluster_nodesThe address of the Redis cluster node.redis-cluster.apim:6379
redis_cluster_passwordThe password for accessing the Redis cluster (if applicable).password
redis_cluster_nameDefines the name of the Redis cluster.kong_redis_cluster
redis_connect_timeoutTimeout for establishing Redis connections (in ms).1000
redis_read_timeoutTimeout for reading responses from Redis (in ms).1000
redis_send_timeoutTimeout for sending requests to Redis (in ms).1000
redis_pool_sizeThe maximum number of connections that can be allocated in the Redis pool.1000
redis_pool_backlogThe number of queued requests allowed if the pool is full.30
redis_keepalive_timeoutDefines how long idle connections should be kept alive (in ms).55000