[Arch] Three independently-invented rate-limiting mechanisms #51

Closed
opened 2026-07-01 07:26:30 +02:00 by bullitt · 1 comment
Owner

Severity: Medium | Category: Backend

_write_timestamps/_check_write_rate_limit() (main.py:24-27,583-588), _ingest_timestamps (main.py:145,600-609), and _last_manual_scrape/_MANUAL_SCRAPE_COOLDOWN (scheduler.py:430-431,455-460) all reimplement "limit calls per window" with three different shapes across two files.

Recommendation: Extract one small RateLimiter helper used by all three call sites.

Refactoring safety: Add characterization tests asserting current rate-limit behavior for all three call sites before consolidating.

Full detail: docs/architecture-review.md § C, Finding "Three independently-invented rate-limiting mechanisms"

**Severity:** Medium | **Category:** Backend `_write_timestamps`/`_check_write_rate_limit()` (main.py:24-27,583-588), `_ingest_timestamps` (main.py:145,600-609), and `_last_manual_scrape`/`_MANUAL_SCRAPE_COOLDOWN` (scheduler.py:430-431,455-460) all reimplement "limit calls per window" with three different shapes across two files. **Recommendation:** Extract one small `RateLimiter` helper used by all three call sites. **Refactoring safety:** Add characterization tests asserting current rate-limit behavior for all three call sites before consolidating. Full detail: `docs/architecture-review.md` § C, Finding "Three independently-invented rate-limiting mechanisms"
Author
Owner

Fixed on branch architecture-rework, commit 64fa05d: added rate_limit.RateLimiter (one sliding-window class; max_calls=1 is behaviorally equivalent to the old single-timestamp cooldown, verified with a dedicated test). All three call sites — main._write_rate_limiter, main._ingest_rate_limiter, scheduler._manual_scrape_rate_limiter — now share it. Added tests/test_rate_limit.py. Full suite: 257 passed.

Fixed on branch `architecture-rework`, commit 64fa05d: added `rate_limit.RateLimiter` (one sliding-window class; `max_calls=1` is behaviorally equivalent to the old single-timestamp cooldown, verified with a dedicated test). All three call sites — `main._write_rate_limiter`, `main._ingest_rate_limiter`, `scheduler._manual_scrape_rate_limiter` — now share it. Added `tests/test_rate_limit.py`. Full suite: 257 passed.
Sign in to join this conversation.
No labels
arch
harness
security
ux
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
bullitt/trackbox#51
No description provided.