Single SQS to handle multiple types of message or having one sqs queue for each message type

3.1k views Asked by At

I am using one AWS SQS for sending the emails. The listener receives the json of the email and directly processes it. Now, I also need to send one more message type (lets say otp or alert) and these will have its own json structure.

Can I use the same SQS Queue for posting these different type of messages as my volume is very low or should I go ahead and create multiple SQS Queue for each message type.

3

There are 3 answers

0
Marcin On

If you want to use one queue, you need a lambda function which is going to do the actual filtering of these messages. And then based on the filter outcomes, the lambda function would take further actions, e.g. send some notifications using SNS.

0
Yogesh_D On

This is very subjective:

a. Is your receiver able to handle both types of messages.

b. Would you need to scale the receivers separately for different types of messages in the future.

c. And most imp are all messages on the queue of equal importance/priority, assume you have a ton of emails related jsons in the queue and then a OTP/Alert based message comes in. Is it ok for that message to be processed after the email related messages. If not it makes sense to have a separate high priority queue for these kind of messages.

0
Register Sole On

Using SQS, 1 queue is sufficient, but then you need a Lambda for filtering and routing the events to the corresponding action (such as if event A -> send email, else if event B -> send OTP). You can use multiple SQS queues, as you suggested, then you don't need the routing Lambda. But either way it involves creating a lot of resources.

Instead, a better option is AWS EventBridge (previously known as CloudWatch Events). See this article for examples. Basically, EventBridge lets you create rules to filter published events and route the matching events to trigger a target. Hence, instead of having to maintain an SQS queue (or multiple as you suggest) and a routing Lambda, you just need to use EventBridge, which is much easier to maintain.

You only need to code the Send Email Lambda, Send OTP Lambda, and Send Alert Lambda.