elvanja

elvanja

Rate limiting API with GenStage?

I have a rather expensive action (some PDF generation and upload to an other service) that occurs when related API endpoint is invoked. At the moment, there’s a pool of workers processing those requests and doing what they’re supposed to. However, this approach results in workers filling up their inboxes, potentially overwhelming the system.

The idea is to apply back pressure to API clients and just reject requests if certain conditions are met, e.g. all workers are busy.

Now, workers would be consumers within GenStage driven architecture. However, I’m at loss as to how to construct the producer part. Or, I could make it so that requests are queued somewhere and a producer that reads them, but no idea how to apply back pressure to API clients.

GitHub - loucash/eqm: Erlang pub sub with supply-demand channels · GitHub solves this idea in the sense that I can use it in e.g. endpoint controller to dispatch work to workers and get information if the pool is exhausted or not, consequently informing the API client. So I’m looking for a similar solution via GenStage, if applicable.

Thank you for your time!

Most Liked

technomage

technomage

Look at the buffering demand part of the GenStage docs GenStage — gen_stage v1.3.2. It includes a QueueBroadcaster which shows how to manage demand and back pressure. In the case of a web API the caller can make calls any time they choose. You would need to provide some reply they interpret as rejecting input that they would be responsible for resubmitting at a later time. This would be similar to how the public APIs like google provide rate limits. The request gets an error that is interpreted as hitting a limit.

jeroenvisser101

jeroenvisser101

There’s also an example in the gen_stage repo for rate limiting that you might want to check out.

Last Post!

elvanja

elvanja

Excellent, seems to be on the right track.
Thank you very much!

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement