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.
https://github.com/loucash/eqm 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!