Skip to content
bossfight
.dev
roadmap
problems
rounds
guides
patterns
quiz
mock
math
progress
Search
Ctrl K
~/rounds
Rate limiter
medium
60 min
Python
Shopify-style
Stripe Bug Squash-style
1
Three keys, three times the limit
2
Build a feature
3
Make it fast
repo
gateway/
__init__.py
config.py
keys.py
limiter.py
middleware.py
models.py
tests/
visible/
test_merchant_limit.py
gw.py
README.md
README.md
read-only
# gateway The front door of a payments API. Every request carries an API key; each merchant can have several keys (one per warehouse, one per environment...). Rate limits are **per merchant**: all of a merchant's keys share one budget. gateway/models.py Request and Response gateway/keys.py KeyStore: which merchant owns an API key gateway/config.py LimitConfig: each merchant's limit and window gateway/limiter.py SlidingWindowLimiter: "at most N requests in any W seconds" gateway/middleware.py handle(): auth, rate limiting, then the app Times are seconds (floats) since some fixed start. A request at time `t` counts against the window `(t - window_s, t]`. Run the tests with `python -m pytest` (or press Run in the browser).
esc