I’m trying to put together a plan for a library that I am working on whereby I need to provide an interface that allows the client to asynchronously call out to external APIs (HTTP endpoints in this case). I also need to make sure that this is rate limited to adhere to the rate limiting on the externals APIs.
From what I have read GenStage sounds perfect for this and using a ConsumerSupervisor I would be able to dynamically start workers for each request as they come in and let GenStage limit the number of workers it will start concurrently.
Does anyone know of any good examples of this type of setup in practice?
I am trying to get my head around how this all fits together and feel a real world example would help me out here.
Discord published a blog post covering how they use genstage to buffer calls to Firebase APIs. It has some code examples as well as performance statistics.
In addition to the discord article linked above, I came across this talk which is probably the best explanation and demo of an end to end genstage setup I have come across.
Well worth a watch (especially if you’re new to genstage)
From my basic understanding so far I would say yes there is. Genstage looks to be a great fit for when you’re having to deal with external forces such as networking for example (rest apis, databases, etc…).
It allows the workers to dictate how much work they are given which prevents the likely important part of the system being overloaded and to remain free to do its thing and cause the backup of events further up the stack.
Someone please correct me if I have got that wrong.
Ok, this sounds cool. Is there any example of how you write GenStage server for example for User CRUD module? I don’t have an idea how you manage those actions in GenStage server.
I would suggest definitely take the 40 minutes to watch that talk as that will probably answer your question better than I could.
The demo is a restruant simulation which demonstrates the full cycle of tables placing an order (that’s processed through genstage) and then receiving thier food all within strict timeouts. Akin to sending CRUD data into genstage and receiving some data when it’s finished.
Just watched the talk and it was really nice. What I missed there, that there was no real diving in code and how to structure everything, so CRUD module would work under gen_stage.