I want to limit clients to an upper limit of number of calls to my REST APIs. What should I return to inform clients that they've been throttled ?
Amazon S3 is returning HTTP 503 with an error code SlowDown to inform clients.
What do you advise ?
One way to implement API throttling in distributed systems is to use sticky sessions. In this method, all requests from a user are always serviced by a particular server. However, this solution is not well-balanced or fault tolerant. The second solution to API throttling in distributed systems are locks.
What is API Throttling? API throttling allows you to control the way an API is used. Throttling allows you to set permissions as to whether certain API calls are valid or not. Throttles indicate a temporary state, and are used to control the data that clients can access through an API.
Since RFC 2616 documents status 503 as (my emphasis):
The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header.
it seems a reasonable approach, especially with a Retry-After
header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With