You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
♻️ refactor(models): remove redundant burst field from Limit model (#408)
## Summary
- Remove the redundant `burst` field from `Limit` and `burst_milli` from
`BucketState` — `capacity` now serves as the bucket ceiling (max
tokens), which is what `burst` was actually doing in all bucket math
- Drop `bx` attribute from DynamoDB writes (bucket and config records);
read path uses `max(cp, bx)` fallback for backward compatibility with
existing records
- Update `refill_bucket()` parameter naming (`burst_milli` →
`capacity_milli`), aggregator processor, CLI display, exception
serialization, migration logic, examples, and all documentation
- Add inline period suffix support to CLI `-l` flag:
`name:rate[/period][:burst]` where period is `/[N]sec`, `/[N]min`
(default), `/[N]hour`, or `/[N]day` — fully backward compatible
## Test plan
- [x] `uv run pytest tests/unit/` — all unit tests pass with updated
assertions (models, bucket, limiter, repository, CLI, exceptions,
migrations, processor)
- [x] `uv run pytest tests/integration/` — integration tests pass with
LocalStack
- [ ] `uv run pytest tests/e2e/` — end-to-end workflows pass
- [x] `hatch run generate-sync` output matches committed sync files
- [x] `pre-commit run --all-files` passes (lint, type check, sync
verification)
Closes#406Closes#410
🤖 Generated with [Claude Code](https://claude.ai/code)
Copy file name to clipboardExpand all lines: docs/guide/basic-usage.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ When using stored config, configure multiple limits at setup time:
66
66
67
67
## Burst Capacity
68
68
69
-
Allow temporary bursts above the sustained rate:
69
+
Allow temporary bursts above the sustained rate by setting `burst` higher than the rate:
70
70
71
71
```python
72
72
# Sustain 10k tokens/minute, but allow bursts up to 15k
@@ -75,7 +75,7 @@ limits = [
75
75
]
76
76
```
77
77
78
-
The bucket starts full at `burst` capacity and refills at `capacity` tokens per period. See [Token Bucket Algorithm](token-bucket.md#capacity-and-burst) for details on how burst and capacity interact.
78
+
The bucket starts full at `burst` capacity and refills at `rate` tokens per period. See [Token Bucket Algorithm](token-bucket.md#capacity-and-burst) for details on how burst and rate interact.
# 10,000 tokens/minute sustained, bucket holds up to 10k
53
+
Limit.per_minute("tpm", 10_000)
54
+
55
+
# 10,000 tokens/minute sustained, but allow bursts up to 15k
56
+
Limit.per_minute("tpm", 10_000, burst=15_000)
57
57
```
58
58
59
59
```mermaid
@@ -71,9 +71,9 @@ graph TD
71
71
style E fill:#87CEEB
72
72
```
73
73
74
-
**Key insight**: The bucket is larger (15k) but refills at the same rate (10k/minute). After fully depleting the burst, it takes **1.5 minutes** to return to full capacity—not 1 minute.
74
+
**Key insight**: When `burst` is set, the bucket is larger than the refill rate. After fully depleting a 15k burst bucket that refills at 10k/minute, it takes **1.5 minutes** to return to full capacity. Without `burst`, the bucket ceiling equals the rate.
75
75
76
-
**When to use burst > capacity:**
76
+
**When to use burst:**
77
77
78
78
-**Startup surge**: Handle initial traffic before steady state
79
79
-**Bursty workloads**: Allow temporary spikes followed by quiet periods
@@ -192,9 +192,9 @@ except RateLimitExceeded as e:
192
192
193
193
### Choosing the right limits
194
194
195
-
| Scenario |Capacity| Burst | Rationale |
196
-
|----------|----------|-------|-----------|
197
-
| Steady API traffic | 100 rpm |100| No bursting needed |
195
+
| Scenario |Rate| Burst | Rationale |
196
+
|----------|------|-------|-----------|
197
+
| Steady API traffic | 100 rpm |--| No bursting needed |
198
198
| Bursty batch jobs | 100 rpm | 500 | Allow 5x burst, then sustain |
0 commit comments