Time window 24 hours. Suggested effort about 4 hours.
Context
The platform team needs a reusable rate limiter for its HTTP services: per API key, configurable, and honest with clients about when to retry.
Core requirements
- A library with two algorithms behind one interface: token bucket and sliding-window log (or sliding-window counter).
- An in-memory store, and a store interface so a shared store (for example Redis) can be added without touching the algorithms.
- HTTP middleware for one framework: identifies the caller by the
X-API-Keyheader (falling back to IP), applies per-route limits from a config file, and returns 429 withRetry-AfterandRateLimit-*headers. - A small demo server with two routes that have different limits.
- Time is injectable (a clock interface) so behaviour is testable without sleeping.
Acceptance criteria
- Tests with a fake clock prove: bursts up to the bucket size pass, the next request is rejected, and capacity refills at the configured rate; the sliding window does not allow double the limit across a window boundary.
- Concurrent requests (for example 100 at once against a limit of 10) admit exactly 10; the test proves it.
- Memory does not grow without bound for many distinct keys (idle keys are evicted; explain the policy).
- The README compares the two algorithms and says when you would choose each.
Stretch goals (optional)
- A Redis store using an atomic script, with tests against a local Redis (skipped if none is running).
- Hot reload of the limits file.
- A load-test script and its results.
Constraints
- Any language. Suggested: Go, TypeScript (Node) or Python.
Deliverables (every project)
- Source code committed in this repository (the grader diffs against the first commit).
README.mdthat replaces the stub, with: how to install, run and test it (copy-pasteable commands); the decisions and trade-offs you made; what you would do next with more time; and a short note on how you used the AI agent (what you delegated, what you checked or rewrote).- Automated tests that run with a single command (
npm test,pytest,go test ./...orcargo test). - No secrets in the repository. Anything configurable reads from environment variables with safe defaults.
Ground rules
- The 24-hour clock is a window, not a workload. Stop at roughly the suggested effort, then write down what you would do next. A small, finished, tested core beats a large unfinished one.
- Use the AI agent as much or as little as you like: every prompt is recorded and the report shows how it was used. You are judged on the result and on whether you understood and verified what the agent produced.
- The work is yours. PraxisAI uses it only to produce your assessment report.