G. Alves
G. Alves

Reputation: 33

Amazon SNS topic with multiple instances of same application

I'm currently facing a problem when thinking about a event driven arch using SNS to decouple some applications.

Imagine a SNS Topic, and I have application A producing messages to it and application B will listen and consume messages from this topic.

This application B has a autoscaling group attached to it, so it can scales to more than one instance. How will SNS handle when application B scales? If now I got 2 instances of application B, SNS will send the message for all of them or it can realize that they are the same application and just send the message to one of them?

Upvotes: 0

Views: 1735

Answers (2)

aherve
aherve

Reputation: 4070

Think of SNS as a radio broadcast: Everyone who is listening will get your message. Meaning that every single of your subscribed servers will get notified.

SQS, on the other hand, is more like a todo list. Many subscribers can also listen to it, but every message is distributed to at least someone. Meaning that usually, only one server will get triggered. If that suits you better, then you might consider using SQS instead of SNS.

Upvotes: 1

bjrnt
bjrnt

Reputation: 2822

I'm not sure what your desired outcome is here, so I'm splitting the answer into two parts:

a) You only want to process each message once: A common pattern in this case is to subscribe an SQS queue to the SNS topic, and then have N application servers polling from this queue. That way, you can make sure that you process each message only once.

b) You want to process each message once on each server: In this case, you can create one subscription for each server to the SNS topic. Each message published to the topic will be delivered once to each subscription.

Upvotes: 1

Related Questions