I'm developing my first medium/big application in elixir and I'm trying to get familiar with the common patterns in elixir system design and architectures.
At this moment I'm trying to implement an input queue (currently implemented using the erlang :queue), exposed through and API and I want to have consumers from that queue performing some processing and storing the data.
I have created the queue using an Agent and I have implemented a genStage that queries the queue for elements and a genstage consumer for performing all the processing that I need. In summary something like this
Queue Agent -------> GenStage producer ---------> GenStage consumer -----> database
My questions are the following:
- Is this pattern valid for Elixir?
- Is a valid pattern the polling that the GenStage producer is performing on the Queue, asking everytime that consumers requests for new elements?
- Are there any performance implication in this pattern, specially are there any possible blocking implications in the Queue Agent?
After some comments and reading documentation I realised that
GenStage
is based onGenServer
and I have the possibility to manage the internal state from outside theGenStage
.After this I refactored the code and now I have the
:queue
as part of theGenStage
state, so I don't need to polling any queue outside theGenStage
and I also have the possibility to add elements into the queue using thehandle_cast
method.Now I have the Queue working as a
GenStage
producer and I have been able to connect my database service as a consumer