David Dahan
David Dahan

Reputation: 11172

How do you throttle a REST API using many Heroku dynos?

I configured my REST API throttling, accepting 10 requests max per minute. It works as expected in a local environment.

However, when deploying on Heroku, this throttling is applied on a dyno basis. Since the routing to select a dynos is kind of random, this means for example if I have 2 dynos, an error can occur between the 11th and the 20th request (this often happens around 16 or 17 requests actually).

How to have a clean throttling with deterministic rates, that does not change when dyno config changes, on Heroku?

Upvotes: 0

Views: 249

Answers (1)

Damien MATHIEU
Damien MATHIEU

Reputation: 32627

You must currently be storing the throttling data into memory. You need to store that in a shared database, such as Redis. If you read and write the value to/from that database every time, it will be shared among dynos and you will have something a lot more reliable.

Upvotes: 2

Related Questions