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

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
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
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
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
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement