How do you implement the rate limiter handling multi-threading and concurrency?
Asked in the technical phone screen stage. Implement a thread-safe, per-client sliding-window rate limiter. The limiter allows at most limit requests from each client during any window_seconds interval.
Implement rate_limit_requests(requests, limit, window_seconds), where requests is a list of [client_id, timestamp] pairs. Process requests in order and return a Boolean list indicating whether each request is accepted. The underlying limiter must protect shared state with synchronization so its allow method can safely be called by multiple threads.
def rate_limit_requests(requests, limit, window_seconds):