Build a minimal production-leaning service that can handle load, rate limit, and avoid duplicates via idempotency.
POST /v1/signals- body:
{ "userId": "string", "type": "string", "payload": "string" } - headers:
X-API-Key,Idempotency-Key(optional) - behaviors:
- Rate limit per
userId:RATE_LIMIT_PER_MINper minute (default 5). - Idempotency: same
Idempotency-Keyshould not create duplicates.
- Rate limit per
- body:
GET /v1/signals?userId=...&limit=...GET /healthz
- Implement a robust rate limiter in
src/rateLimit.js. - Make idempotency safe across scale in
src/signals.js. - Handle DB failure gracefully with retry/backoff.
- Think for 10k RPS. Add a
SCALE.md. - Finish the tests in
tests/*.test.js.
- Working service, passing tests, updated README, SCALE.md.
- Optional deploy link.
- Atomic Idempotency: Survive concurrent requests and restarts. Avoid check-then-insert races; use a DB-level unique constraint or atomic upsert pattern. Return the same resource for identical
Idempotency-Key. - Concurrency-Safe Rate Limit: Must behave correctly under burst and parallel calls. Naive in-memory counters that race will fail hidden checks. Explain how this becomes multi-instance safe.
- Transient DB Failures: Implement retry/backoff (with jitter) or circuit breaker when DB errors occur (we simulate via
DB_FAIL_RATE). No duplicates on retry. - Scale Plan (10k RPS): Fill
SCALE.mdwith a clear, concise approach (indexes, pooling, caching, queues, horizontal scale, idempotency store).
We will run additional hidden concurrency/multi-instance tests during evaluation.