Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to throttle clients in a REST API

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 ?

like image 263
Jacques René Mesrine Avatar asked Mar 30 '10 06:03

Jacques René Mesrine


People also ask

How do you implement throttle in API?

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 does it mean to throttle an API?

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.


1 Answers

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.

like image 54
Alex Martelli Avatar answered Oct 02 '22 21:10

Alex Martelli