Mocking a rate limiting endpoint 429

Ever have some client code that needs to call another endpoint which rate limits you? Join the club. I recently did, and honestly I didn’t care at all about the ONE particular rest client that needed to backoff appropriately when the 429s were being barfed back; instead what I did care about was implementing a generic rate limiting engine that could function in front that one specific client, and be used generically for many different clients/use-cases and throttle threads before they even got to the client code in anticipation of a rate limit being reached.

In the process of writing that gating code (which ended up using a distributed semaphore of sorts that spanned across many nodes in a cluster) I ended up writing this simple mock endpoint who could be configured to return 429′s and a Retry-After header (i.e. RFC 3261) after some threshold of requests per timeframe was reached. I had to use this in order to properly be able to test the distributed gating code which could limit the total number of threads operating across clients spanning many nodes. Its simple and completely customizable. Maybe will be of use to someone else.

Check it out here:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s