Rate limits and the request log (E-commerce Store (full stack))

Protect the shop. RATE <n limits each API key (or anonymous) to n requests in any 10 seconds; T <second sets the clock. Over the limit → 429 {"error":"rate limited","retryafter":<s}, where s = (oldest request in the window) + 10 − now. Rate limiting runs before everything else. After the last request print summary requests=<n 2xx=<n 4xx=<n.

Input: As before, plus RATE and T.

Output: As before, plus the summary.

Difficulty: Hard. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Keep each key’s request times; drop those older than 10 seconds.

More E-commerce Store (full stack) practice