Statement
Write createRateLimiter(limit, windowMs), returning allow(key, now). allow returns true if that key has fewer than limit allowed requests in the last windowMs milliseconds (sliding window: requests with now - t < windowMs count), and records it; otherwise it returns false and doesn't record it. now is passed in so it can be tested. In the explanation, say how you'd do it with several instances of the service behind a load balancer and when you'd pick a token bucket instead.