Fan-Out & Message Filtering

Combine SNS with SQS for reliable parallel processing, and send each subscriber only what it needs.

1 min read

The fan-out pattern

Publish once to SNS, and subscribe several SQS queues. Each queue gets its own copy and is processed independently at its own pace, with its own retries and DLQ.

How it flows
  1. 1Order placed

    Publish to SNS topic

  2. 2SNS topic

    Copies to every subscriber

  3. 3Queues

    billing / shipping / analytics

  4. 4Workers

    Each processes independently

Why not have SNS call each Lambda directly? Queues add buffering, retries, and DLQs, so a slow or broken consumer never affects the others.

Subscription filter policies

By default, every subscriber receives every message. A filter policy on a subscription lets it receive only matching messages, based on message attributes (or the message body):

JSON
{
  "noteType": ["todo", "meeting"],
  "wordCount": [{ "numeric": [">", 500] }]
}

This subscription only receives todo or meeting notes with more than 500 words.

Tip

Filtering in SNS is better than "receive everything and ignore most of it". You avoid wasted invocations and cost.

FIFO topics

Need strict ordering and deduplication across fan-out? SNS FIFO topics deliver to SQS FIFO queues in order.

Key takeaways

  • Fan-out: SNS topic → multiple SQS queues, each processed independently.
  • Filter policies let each subscription receive only relevant messages.
  • SNS FIFO topics + SQS FIFO queues preserve ordering.

Check your understanding

Pick an answer to see the explanation.

  1. 1. Your analytics team only wants 'refund' events from a busy orders topic. Best approach?