Search⌘ K

Feature #4: Request Limiter

Discover how to implement a request limiter for the Facebook Status API by using a hashtable to track requests and timestamps. Learn to accept or reject requests based on a throttling window, ensuring only one request per Status ID is processed within five days. Understand how to manage duplicates efficiently with constant time complexity and apply this pattern to real-world coding interview problems.

Description

The Facebook Status API queues requests using the requested Status ID and a timestamp. We want to implement a throttling mechanism on the requests that limits one request for a particular Status ID at a pre-configured time interval. Any additional requests for the same Status ID in this interval will be dropped. Multiple requests for different Status IDs can occur at the same time.

We’ll be provided with the name of the request and the time it arrived. Our system will have to decide whether to accept the request or reject it based on its arrival time. In this scenario, we’ll use a time limit of five days before a similar request can be sent from the same or different platform.

Solution

The hashtable data structure will be used to implement this feature. This data structure can uniquely store all of the incoming requests while simultaneously taking care of the duplicate requests. The requests will be stored ...