# Fan Out Pattern

## Basics

* When a message needs to be send to multiple SQS queues, this pattern is useful.
* A message is first pushed to an SNS topic and SQS queues are subscribers to these topics.
* Due to this fan out pattern,
  * One can easily add new queues as subscriber
  * Application architecture becomes fully decoupled as there is no data loss.
  * Allows for data persistence, delayed processing and introduce retries.
* Make sure your SQS queue access policy allows for SNS to write.
* Cross-Region Delivery: SNS Topics in one region can send message to SQS queues in other region/s provided access has been given.

## Diagram

![SQS-SNS\_Fanout](/files/RR3BrqPEjcXKdqtmYotq)

## Applications

### S3 and Fanout Pattern

* One of the application of this pattern is for combination of event type and prefix, you can use only one S3 Event Rule.
* If you want to send the same S3 event to many SQS queues, use Fan-Out pattern.

![S3 And Fanout Integration](/files/TGu2mDM4UfJOFLz7g4oJ)

### SNS -> Kinesis Data Firehose -> S3 Kinesis

* SNS can be directly integrated to Kinesis Data Firehose.
* This integration can be leveraged to send data to S3.

![SNS and S3 Integrations](/files/7KfnESYRfzMtGkyAHRKo)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anon-coders-notes.gitbook.io/techwriterdev/cloud/aws/developerassociate/services/14_messaging/02_fanout.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
