✨ Support usage-milestone-based rate limit ramp-up
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 6h 51m
- Merged PRs (30d)
- 104
Description
Problem or Use Case
New entities (users, API keys) may need to demonstrate legitimate usage patterns before unlocking higher rate limits. Time-based ramp-up (#222) assumes trust increases with account age, but this can be gamed by attackers who create accounts and wait.
Usage-milestone-based limits unlock higher capacity based on demonstrated good behavior:
- Abuse prevention - Attackers must invest real usage before getting high limits
- Trust building - Limits increase as users prove legitimate usage patterns
- Gaming/social platforms - New accounts can't immediately flood systems
- Gradual onboarding - Users naturally unlock more capacity as they use the service
Proposed Solution
Add milestone-based ramp-up configuration to limits:
Limit.per_minute(
"rpm",
capacity=1000, # Target capacity
ramp_up=RampConfig(
initial=100,
milestones=[
{"total_requests": 1000, "capacity": 250}, # After 1K requests
{"total_requests": 10000, "capacity": 500}, # After 10K requests
{"total_requests": 100000, "capacity": 1000}, # After 100K requests
],
),
)
Behavior
| Entity's Total Requests | Effective Limit |
|---|---|
| 0 - 999 | 100 RPM |
| 1,000 - 9,999 | 250 RPM |
| 10,000 - 99,999 | 500 RPM |
| 100,000+ | 1000 RPM |
Implementation Notes
- Requires tracking cumulative request count per entity
- Could leverage
total_consumed_millicounter or usage snapshots - At acquire-time, look up entity's total usage and find applicable milestone
- Milestones are one-way (don't reduce limits if usage decreases)
Success Criteria
- Define usage milestones on limits
- Track cumulative usage per entity
- Effective limit calculated from current milestone tier
- CLI can display entity's current milestone and progress to next
- Audit logs capture milestone transitions
Open Questions
- Metric for milestones - Total requests? Total tokens? Configurable?
- Milestone scope - Per-resource or aggregate across all resources?
- Reset behavior - Should milestones ever reset (e.g., monthly)?
- Interaction with other dynamic limits - How do milestones combine with time-based (#222) or utilization-based (#223)?
Alternatives Considered
- Time-based ramp-up - Covered by #222. Simpler but can be gamed by waiting.
- Manual tier upgrades via webhooks - Covered by #224. More flexible but requires external logic.
Related Work
- #222 - Time-based dynamic rate limits (includes time-based ramp-up)
- #223 - Utilization-based adaptive rate limits
- #224 - Event-driven webhooks (alternative approach)
- Usage snapshots provide cumulative usage data
- Part of the Dynamic Rate Limits initiative
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Limit.per_minute configuration, usage snapshots, and the total_consumed_milli counter mentioned in the issue. Resolve the open questions about milestone metrics, scope, resets, and interactions with other dynamic limits; done means all listed success criteria are implemented, including CLI progress and audit-log transitions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100