Dung (Donny) Nguyen

Senior Software Engineer

Fanout Pattern with AWS SNS + SQS

The fanout pattern (also called publish-subscribe fan-out or simply fan-out) using AWS SNS and SQS is one of the most common and powerful messaging patterns for building decoupled, scalable, event-driven architectures on AWS.

Core Idea

One producer publishes a single message → SNS fans it out (duplicates and pushes it) → to multiple subscribers (in this case, multiple SQS queues) → each queue is processed independently by different consumers.

This gives you parallel asynchronous processing without the producer knowing or caring how many or which consumers exist.

Architecture Overview

                ┌───────────────────────┐
                │     Producer          │
                │ (e.g. Order Service,  │
                │  Image Upload, Event) │
                └───────────┬───────────┘
                            │
                     Publish once
                            ▼
                ┌───────────────────────┐
                │     SNS Topic         │
                │   (central fan-out    │
                │       point)          │
                └───────┬───────┬───────┘
           ┌──────────┘       │       └──────────┐
     Subscribe          Subscribe          Subscribe
           ▼                ▼                  ▼
┌────────────────┐ ┌────────────────┐ ┌────────────────┐
│  SQS Queue A   │ │  SQS Queue B   │ │  SQS Queue C   │
│ (e.g. emails)  │ │ (fulfillment)  │ │ (analytics)    │
└────────┬───────┘ └────────┬───────┘ └────────┬───────┘
         │                   │                   │
   ┌─────▼─────┐       ┌─────▼─────┐       ┌─────▼─────┐
   │ Consumer A │       │ Consumer B │       │ Consumer C │
   └───────────┘       └───────────┘       └───────────┘

Key Components & Responsibilities

Component AWS Service Role Key Properties
Publisher Any Sends one message (Publish) Doesn’t know receivers
Fan-out hub SNS Topic Receives message → duplicates → pushes to all subscriptions Push-based, high fan-out capacity
Buffer/Queue SQS Queue Receives copy of message, stores durably Pull-based, retries, visibility timeout, DLQ
Consumer Lambda, ECS, EC2, etc. Polls / receives from its own SQS queue and processes Independent scaling & failure isolation

Why SNS + SQS Together? (instead of SNS alone or SQS alone)

Scenario SNS alone SQS alone SNS + SQS (fan-out)
Multiple consumers? Yes (push) No (single queue hard to share) Yes — best of both worlds
At-least-once delivery? Yes Yes Yes
Independent retries? Limited per subscriber Excellent (per queue) Excellent — each queue controls retries
Consumer can be offline? No — push fails after retries Yes — message stays in queue Yes — very durable
Scaling consumers Hard (push rate limits) Easy (multiple pollers) Very easy
Message ordering No guarantee FIFO possible Standard: no / FIFO queues possible

This combination is often called the “topic-queue-chaining” pattern.

Typical Real-World Use Cases

Important Setup Details (2025–2026 era)

Summary — When to Use SNS + SQS Fanout

Use it when you need:

It’s one of the foundational patterns for microservices and serverless applications on AWS — reliable, battle-tested, and very cost-effective at moderate-to-high scale.