scottyscripts

scottyscripts

Maximize concurrency w/ GenStage pipeline using SQS FIFO queue

Hello!

I am designing a GenStage pipeline using a FIFO queue from Amazon SQS.
I just want to say right up front that unfortunately I can’t use Broadway SQS based on my use case.

I have a

  • producer (receiving messages from SQS)
  • producer_consumer (to normalize incoming messages)
  • consumer (want to perform operations for a group of messages)

My end goal is to

  1. take incoming messages
  2. group them by an attribute on that message (Message Group Id), while maintaining original message order
  3. process messages in batches/groups

In my producer consumer, I’d like to dynamically spin up a new consumer process for each batch of messages (events).

For example, I have 10 messages received.

  • 7 messages have message group ID “a”
  • 3 messages have message group ID “b”

After initial processing in my producer_consumer, I would like to spin up 2 (n) consumer processes, one for processing messages w/ group “a” and another process for spinning up messages with group “b”.

I was looking at making my consumer use ConsumerSupervisor, but this spins up a new consumer process per event.

I’m also considering the issue where I receive 7 messages from group “a” and then receive 3 more messages from group “a” (SQS only allows 10 messages in flight for a given Message Group ID). I need to make sure they are processed in the original order they were received. (Processing these in different consumers opens up this potential race condition)

My current idea is to do some sort of check in my producer consumer to see if a consumer process exists for message group “a”

  • if it does, push new messages (genstage events) to this consumer process to be processed next
  • otherwise create a new consumer process for group “a” and process all incoming messages for a certain window.
    This idea feels like I’m going to far away from what was intended with GenStage.

Any ideas to maximize concurrency in my situation while keeping true to GenStage pattern?

Marked As Solved

kokolegorille

kokolegorille

Did You look at Flow? The main difference with GenStage is its ability to group…

Also Liked

kokolegorille

kokolegorille

There is a flow diagram in this video…

… at about 39min 50sec

Where Next?

Popular in Questions Top

Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
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
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement