0
0
AWScloud~10 mins

SNS and SQS integration pattern (fan-out) in AWS - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - SNS and SQS integration pattern (fan-out)
Message published to SNS topic
SNS topic receives message
SNS fans out message to multiple SQS queues
SQS Queue 1
Consumers read messages independently
A message is sent to an SNS topic, which then copies and sends it to multiple SQS queues. Each queue can be processed separately by different consumers.
Execution Sample
AWS
Publish message to SNS topic
SNS fans out to SQS queues
Each SQS queue receives the message
Consumers poll SQS queues
Process messages independently
This shows how a single message sent to SNS is delivered to multiple SQS queues for parallel processing.
Process Table
StepActionSNS Topic StateSQS Queue 1 StateSQS Queue 2 StateSQS Queue 3 StateConsumer Processing
1Message published to SNS topicMessage receivedEmptyEmptyEmptyNo processing yet
2SNS fans out message to SQS queuesMessages deliveredMessage receivedMessage receivedMessage receivedNo processing yet
3Consumer 1 polls SQS Queue 1Messages deliveredMessage in flightMessage receivedMessage receivedConsumer 1 processing message
4Consumer 2 polls SQS Queue 2Messages deliveredMessage in flightMessage in flightMessage receivedConsumer 1 and 2 processing messages
5Consumer 3 polls SQS Queue 3Messages deliveredMessage in flightMessage in flightMessage in flightAll consumers processing messages
6Consumers delete messages after processingMessages deliveredEmptyEmptyEmptyAll consumers done
7No more messagesEmptyEmptyEmptyEmptyNo processing
ExitAll messages processed and queues emptyNo messagesNo messagesNo messagesNo messagesIdle
💡 All messages processed and deleted from queues, SNS topic has no pending messages
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6Final
SNS Topic Messages01000000
SQS Queue 1 Messages0010 (in flight)0 (in flight)0 (in flight)00
SQS Queue 2 Messages0011 (in flight)0 (in flight)0 (in flight)00
SQS Queue 3 Messages00111 (in flight)0 (in flight)00
Consumers ProcessingNoneNoneNoneConsumer 1Consumer 1 & 2All 3NoneNone
Key Moments - 3 Insights
Why does each SQS queue get its own copy of the message?
Because SNS fans out the message to all subscribed queues independently, as shown in execution_table step 2 where all queues receive the message.
What happens if one consumer processes its message slower than others?
That queue's message stays 'in flight' until processed and deleted, while other queues can process their messages independently, as seen in steps 3 to 5.
Does deleting a message from one SQS queue remove it from others?
No, each SQS queue holds its own copy. Deleting from one queue does not affect messages in other queues, as shown in step 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What is the state of SQS Queue 2?
AEmpty
BMessage received
CMessage in flight
DMessage deleted
💡 Hint
Check the 'SQS Queue 2 State' column at step 2 in the execution_table.
At which step do all consumers start processing their messages simultaneously?
AStep 3
BStep 4
CStep 5
DStep 6
💡 Hint
Look at the 'Consumer Processing' column to see when all consumers are active.
If the message is deleted from SQS Queue 1 at step 6, what happens to the message in SQS Queue 3?
AIt remains until processed
BIt moves to SQS Queue 1
CIt is also deleted
DIt is duplicated
💡 Hint
Refer to the key moment about message deletion and independent queues.
Concept Snapshot
SNS and SQS fan-out pattern:
- Publish message to SNS topic
- SNS sends copies to all subscribed SQS queues
- Each SQS queue holds its own copy
- Consumers poll and process messages independently
- Deleting from one queue does not affect others
Full Transcript
This visual execution shows how a message published to an SNS topic is copied to multiple SQS queues. Each queue receives the message independently and holds it until a consumer processes and deletes it. Consumers can work in parallel without affecting each other. SNS delivers the message asynchronously to all subscribed queues. This pattern enables scalable, parallel processing of the same message by multiple consumers.