0

I’m looking for a design architecture to synchronize stopping SQS consumption across all ECS tasks when a process is running and start them at the end of process

I initially considered a design that involves publishing a message to an SNS topic, with all the tasks subscribing to this topic. However, this approach doesn’t work at all, because when the first task consumes the message, the other tasks can’t consume it (because it’s already consumed).

In my current solution, I store the states of the ECS tasks in an RDS table to track whether they are consuming SQS messages or not (I’m using MessageListenerContainerRegistry, which works pretty well).

Does anyone have ideas for a better solution? Or a totally different design? I want to avoid polling the RDS for a table that tracks the state of SQS consumption.

Thanks!

6
  • 1
    Your description of SNS doesn't make sense. If each server is subscribed separately to the SNS topic, then each one would get the message. SNS sends the message to each subscriber. If you have SNS sending a message to a load balancer they are all behind, or something like that, then yes that won't work. Commented Oct 11, 2024 at 18:18
  • Any sort of "push" solution, like SNS or something similar, is going to be fragile for this I think. Especially if your servers are auto-scaled. I know you want to avoid polling the RDS table, but I genuinely think some sort of polling solution is going to be your best bet. You are already polling SQS, you could just check the DB before each SQS polling request, and do some sort of wait/pause for a while if the DB says to not consume messages. Commented Oct 11, 2024 at 18:22
  • Hello Mark,Thank you very much for your answers. Actually, never mind about SNS. I was mistaken because I thought that messages would always be available on the topic for each consumer, meaning consumers with the same subscription. But no, once a message is consumed by a subscriber, it’s no longer available. I could use SQS as well. Actually, I want to create this SQS switch for a very rare processing event, so it would be unfortunate to use a polling solution for this use case. However, I do recognize that it would be a simpler approach. Commented Oct 12, 2024 at 9:16
  • Anyway, I think I found a (somewhat complicated) solution using two SQS queues: one (A) to start the SQS target and another (B) to stop the SQS target. When a task initiates the computation, it stops the SQS target. At the same time, I switch off queue B and switch on queue A, then send the same event, allowing the other tasks to chain as well. During this time, I check an RDS table to see if all tasks have stopped their consumption. If they have, I proceed with the computation. At the end, I restart the SQS target using the same logic. Commented Oct 12, 2024 at 9:31
  • 1
    I don't think you understand how SNS works. Your descriptions continue to sound incorrect. SNS is a "push" service, while SQS is a "pull" service. SNS pushes the message simultaneously to every consumer that has registered with the topic. I don't see how your SQS solution will work, since sending a "stop" message to the other topic will only be received by one of the consumers, not all of them. SQS is for sending a message to one consumer, SNS is for sending a message to all consumers. Anyway, good luck with whatever you are doing. Commented Oct 12, 2024 at 13:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.