This is a bit of a theory question, but it was bugging me since some time now.
Background
Suppose you created a nice RESTful service for some highly volatile data. Your users will need to query the RESTful server quite often to get the changes. However, so many requests stress the server quite hard. Also it may make actually not too much sense to query more often then say once per 30 sec. Since the request is parameterised, it would not make much sense to precalculate everthing and serve from the cache. So you need to somehow restrict the user from accessing your resource too often.
The question
How can you restrict a user by throttling down his requests without breaking the RESTful paradigm of not keeping state in the server?
My current thinking
My service now creates a helper map that holds a timestamp of the current request together with the access token. The service answers with an http error 429 (too many requests) if the last access to the RESTful endpoint was less than 30 sec ago. This breaks REST.
Alternative idea
I could send the access time along encrypted by a private key. The client would then need to send this key along for the next request. My server decrypts it and decides if the client can perform the query yet. This is a lot of overhead it seems...
Twist
The situation gets more complicated, since I have different endpoints in my RESTful server for which different access time restrictions should apply. One request basically builds a complete database dump - this is only meant for the customer to get the current state of everything, but it should not be used to query again and again.
How would you try to implement such a requirement in a RESTful server? Should I continue with my approach although it clearly introduces a state? Anyone has experience with the performance of encrypted state that can be safely passed around without fear for client side manipulation?
This is different from
If REST applications are supposed to be stateless, how do you manage sessions?
The above question discusses the general idea of RESTful server APIs and I do understand the concept all right I think. The question here is about a design desicion, not the question if my design breaks REST and why.
The question is how to implement throttling in a so far RESTful server and keep the benefits of high scalability of REST. What are the best practices for that. My question is specific about getting throttling to work. The client can't be trusted to keep the state, so that state transfer in the sense of REST will not work. How do others solve this?