The Fan-Out Pattern with SNS
Learn the fan-out messaging pattern using Amazon SNS to deliver one event to many independent Lambda consumers in parallel.
The Fan-Out Pattern with SNS is a free Serverless AWS Lambda Development lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Serverless AWS Lambda Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What is Fan-Out?
Fan-out means a single event is delivered to many subscribers at once, each processing it independently and in parallel.
Why Not Call Each Directly?
Calling each downstream function from your producer tightly couples them. Adding a consumer means changing the producer. Fan-out decouples this.
SNS as the Hub
Amazon SNS is a pub/sub topic. Publishers send a message once; SNS delivers a copy to every subscriber, including multiple Lambdas.
Publishing a Message
The producer publishes to the topic ARN. It does not know or care who is subscribed.
import boto3, json
sns = boto3.client('sns')
sns.publish(
TopicArn='arn:aws:sns:us-east-1:123:orders',
Message=json.dumps({'orderId': 42})
)The SNS Event Shape
Each subscribed Lambda receives the message wrapped in an SNS records envelope.
{
"Records": [{
"Sns": {
"Message": "{\"orderId\": 42}",
"TopicArn": "arn:aws:sns:us-east-1:123:orders"
}
}]
}A Consumer Handler
Each consumer parses the message from the record and does its own job: one emails a receipt, another updates inventory.
import json
def handler(event, context):
for record in event['Records']:
msg = json.loads(record['Sns']['Message'])
print('Processing order', msg['orderId'])Fan-Out plus SQS
For reliability, subscribe SQS queues to the topic and let Lambda poll the queues. This buffers spikes and gives each consumer its own retry and DLQ.
Message Filtering
SNS filter policies let a subscriber receive only messages matching attributes, so not every consumer processes every event.
{
"eventType": ["order.created"]
}SNS vs EventBridge
SNS is simple, high-throughput pub/sub. EventBridge adds richer routing, schemas, and many SaaS sources. Choose SNS for raw fan-out, EventBridge for complex routing.
Ordering Caveat
Standard SNS topics do not guarantee order or exactly-once delivery. Use SNS FIFO topics when ordering and deduplication matter.
Idempotent Consumers
Because a message may be delivered more than once, each consumer should be idempotent so duplicates do not cause double effects.
Quick Check
Test your fan-out knowledge.
Recap
You learned the fan-out pattern: publish once to SNS, deliver to many parallel consumers, add SQS for durability, filter messages, and keep consumers idempotent.
Frequently asked questions
Is the “The Fan-Out Pattern with SNS” lesson free?
Yes — the full text of “The Fan-Out Pattern with SNS” is free to read here on the web, and the Serverless AWS Lambda Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Serverless AWS Lambda Development course, upgrade to CoddyKit PRO.
What will I learn in “The Fan-Out Pattern with SNS”?
Learn the fan-out messaging pattern using Amazon SNS to deliver one event to many independent Lambda consumers in parallel. You practise Serverless AWS Lambda Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Serverless AWS Lambda Development?
No prior experience is required. Serverless AWS Lambda Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The Fan-Out Pattern with SNS” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Serverless AWS Lambda Development lesson?
Yes. Every Serverless AWS Lambda Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Asynchronous Lambda Invocations
- Dead Letter Queues (DLQ) for Failures
- Orchestrating with AWS Step Functions
- The Fan-Out Pattern with SNS