Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1.  
  2. Can I do this? -> On yes: do action(s)
  3. Rate Limiter <-> Action Driver/Handler --|
  4. -> On no: deny action(s)
  5.  
  6.  
  7. A rate limiter is a module that regulates the number of actions performed (whether it be requests made from a client, or requests accepted by a server). For example, a component that sends requests to api.google.com should be aware that that API has a rate limit of 2000 READ requests per 100 seconds. This protects api.google.com from being overwhelmed with too many requests. To prevent Google from blacklisting or banning the component, it ought to use a rate limiter to regulate its own requests. As another example, the server on Google side can also use a rate limiter to short circuit and send a 429 to protect itself from abusive users; upon receiving an HTTP request, it consults its rate limiter and allows/denies based on the result of the rate limiter.
  8.  
  9. When something uses the Rate Limiter, it first checks whether the Rate Limiter can handle a certain # of requests. If the rate limit has not been exceeded and has capacity, then the caller continues to perform the operations. The rate limiter tracks that the certain number of requests went through. However, if the rate limiter decides that a certain # request cannot go through, the rate limiter does not add those number of requests to its internal tracking, as they were denied!
  10.  
  11. A rate limiter will have a rate of requests it can accept (something like 5 requests per minute, or N requests per M time). A rate limiter is expected to enforce this over time, and replenish its capacity as time progresses.
  12.  
  13. QUESTION #1 = INTERFACE DESIGN
  14. Let's design the Rate Limiter interface that is called by a Requester. This interface has 2 functionalities:
  15.  
  16. FUNCTIONALITY 1 = Check whether the Rate Limiter can handle N additional requests, within the given rate limit.
  17.  
  18. - If YES, Rate Limiter internally records that N requests were processed, and replies to the Requester that the operations were permitted.
  19. - If NOT, Rate Limiter doesn't record any requests were processed, and replies to the Requester that the operations were NOT permitted.
  20.  
  21. ** Note: Requests are "all or nothing". For example, if I request 10 operations at once and my capacity is 0 / 9, I should deny the request of 10 and remain at 0 / 9 capacity.
  22.  
  23. FUNCTIONALITY 2 = Return the # of requests a Rate Limiter can accept right now, without exceeding the rate limit. For example, if my capacity is 5 / 9, return 4.
  24.  
  25. QUESTION #2 = CODE IMPLEMENTATION
  26. Let's implement the interface you just designed, such that Rate Limiter enforces a limit of N requests per minute.
  27.  
  28. QUESTION #3 = BONUS POINTS
  29. Let's build a separate module that utilizes your interface/implementation, which has the following capabilities:
  30.  
  31. (A) Enforce a rate limit per Requester IP
  32.  
  33. (B) Return the N Requester IPs with the lowest # of remaining capacity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement