MadhuTiwari-345 commented on issue #13027:
URL: https://github.com/apache/apisix/issues/13027#issuecomment-3979139480
### Proposed Incremental Design for `adaptive-limit` (Phase 1 – Baseline
Tracking PoC)
To move this feature forward in a structured and reviewable way, I would
like to begin with a minimal implementation focused only on per-consumer
baseline tracking, without enforcing adaptive limits yet.
This phased approach keeps the initial scope small while laying the
technical foundation for future adaptive rate control.
---
## Scope (Phase 1)
This initial PoC will:
* Track request count per consumer
* Maintain a rolling request-rate baseline using Exponential Moving Average
(EMA)
* Store metrics in `ngx.shared.dict`
* Log or expose the computed baseline for observability
This phase will **not** enforce stricter limits or modify request behavior.
---
## High-Level Architecture
**Plugin name:** `adaptive-limit`
**Execution phase:** `access`
### Data Storage
Use a dedicated shared memory dictionary:
```
ngx.shared.adaptive_limit_dict
```
Key format:
```
adaptive:{consumer_id}
```
Each consumer entry will store:
* `count` – request count within current time window
* `window_start` – timestamp of current window
* `ema` – rolling baseline request rate
---
## Baseline Algorithm
Use Exponential Moving Average:
```
EMA_new = α * current_rate + (1 - α) * EMA_old
```
Where:
* `α` (alpha) is configurable (default: 0.2)
* `current_rate = request_count / window_size`
EMA is preferred over Simple Moving Average because:
* Constant memory usage
* Faster adaptation to behavioral changes
* Lower implementation complexity in Lua
---
## Windowing Strategy
* Fixed time window (default: 1 second)
* Increment counter per request
* On window expiration:
* Compute current rate
* Update EMA
* Reset counter
---
## Future Phases
Phase 2:
* Spike detection (e.g., `current_rate > multiplier × ema`)
Phase 3:
* Temporary limit tightening
* Gradual relaxation when traffic stabilizes
---
I would like to proceed with implementing Phase 1 as a small, self-contained
PoC for review. Feedback on the storage model, execution phase, or algorithm
choice would be appreciated before I begin development.
---
--
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]