jizhuozhi opened a new issue, #12748:
URL: https://github.com/apache/apisix/issues/12748

   ### Description
   
   #### **Background**
   
   Currently, APISIX provides two rate-limiting modes:
   
   * **`local` mode** — simple and fast, but limited to a single APISIX node.
     → Causes inaccurate global QPS limits when APISIX is horizontally scaled.
   * **`redis` mode** — distributed and accurate, but introduces external 
dependency (Redis) and increases latency.
   
   This tradeoff makes it difficult to achieve both **scalability** and **low 
latency** in production environments where Redis may not be preferred or 
available.
   
   #### **Problem**
   
   When using `local` mode in a clustered APISIX deployment (multiple workers 
or multiple nodes), the rate limit is **enforced independently per instance**, 
leading to:
   
   * Global limit overshoot when scaling out APISIX;
   * Inconsistent rate-limiting behavior between nodes;
   * Operational complexity if the cluster size changes dynamically (e.g., with 
autoscaling).
   
   #### **Proposal**
   
   Introduce a new **adaptive local rate-limiting mode**, which automatically 
adjusts the effective local limit based on **the current number of active 
APISIX instances** in the cluster.
   
   Example configuration:
   
   ```yaml
   plugins:
     - name: limit-req
       config:
         rate: 1000               # global target rate
         burst: 200
         key_type: var
         key: remote_addr
         policy: adaptive_local   # new mode
         sync_interval: 10        # optional: recheck etcd node list every 10s
   ```
   
   #### **Expected Behavior**
   
   * APISIX automatically retrieves the current cluster instance count (from 
etcd or built-in discovery).
   * Each node’s local limiter divides the total rate evenly:
   
     ```
     effective_rate = global_rate / active_instances
     ```
   * When nodes join/leave the cluster, limits dynamically rebalance.
   * No external Redis dependency or network round-trips required.
   * Maintains local-mode latency characteristics.
   
   #### **Benefits**
   
   * No external dependency (no Redis).
   * Low-latency local enforcement.
   * Horizontal scalability with correct global QPS behavior.
   * Seamless integration with APISIX’s cluster-awareness.
   
   #### **Possible Implementation Notes**
   
   * APISIX already had a **`server-info` plugin**, which periodically reports 
each node’s status under etcd path:
   
     ```
     /data_plane/server_info/{id}
     ```
   * Although this plugin is marked for deprecation, its underlying mechanism 
(APISIX node self-registration in etcd) provides a lightweight and 
dependency-free way to **track active APISIX instances**.
   * The adaptive local rate limiter can **reuse a similar mechanism** — either:
   
     * read the existing `/data_plane/server_info` keys, or
     * implement an internal lightweight watcher for APISIX node presence.
   * This avoids introducing any new components (no Redis, no sidecar) and 
leverages APISIX’s existing etcd connection.
   * The instance count can be cached locally and refreshed at a configurable 
interval (e.g., every 10 seconds), with minimal etcd read overhead.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to