Designing Fan-In, Fan-Out and Stateful Stream Processing
This lesson explains how streaming architectures are described by how data converges and spreads, fan-in and fan-out, and by whether processing must remember earlier records, and how both choices decide which services and settings fit.
Learning outcomes
After completing this lesson, you will be able to:
- Design fan-in from many producers into one stream.
- Design fan-out to many independent consumers.
- Distinguish stateless from stateful processing and choose a service for each.
Fan-in
Fan-in means many producers sending data into one destination, such as thousands of devices writing to a single Kinesis data stream, or log groups in many accounts sending to one central stream through CloudWatch Logs subscription filters and a cross-account destination. Fan-in simplifies downstream processing, because consumers read one stream, but the destination must absorb the combined throughput.
The design concerns are capacity and distribution. The total write rate decides how many shards or partitions are needed, or whether on-demand mode should scale them automatically. The partition key must spread records evenly, because a key shared by many producers creates a hot shard. Producers can batch records, for example with the Kinesis Producer Library's aggregation, to use each shard's 1,000-records-per-second limit efficiently. EventBridge provides fan-in for events, with rules on a central event bus receiving events from other accounts.
Fan-in design
Fan-out
Fan-out means one stream of data delivered to many consumers, each processing it independently. With Kinesis Data Streams, standard consumers share each shard's 2 MB per second of reads, so enhanced fan-out is used when several consumers each need full throughput and low latency. With Amazon MSK, each consumer group reads the whole topic independently. For messages and events, SNS fans one message out to many SQS queues, Lambda functions and endpoints, and an EventBridge rule can send one event to up to five targets. The following table compares the mechanisms.
| Pattern | Mechanism | Notes |
|---|---|---|
| Fan-in of records | Many producers into one Kinesis stream or MSK topic | Size for combined throughput; spread partition keys |
| Fan-in of logs | CloudWatch Logs subscription filters to a cross-account destination | Centralises logs from many accounts |
| Fan-out of records | Kinesis enhanced fan-out; MSK consumer groups | Each consumer reads at full throughput |
| Fan-out of messages | SNS topic to many SQS queues (SNS-to-SQS fan-out) | Each subscriber gets its own durable copy |
| Fan-out of events | EventBridge rule with several targets | Content-based routing to up to five targets per rule |
The following diagram shows a retail stream that combines fan-in from 2,000 stores with fan-out to three consumers, one of which is stateful.

Fan-out mechanisms
Stateless and stateful processing
Stateless processing handles each record on its own, using only the data in that record: filtering out invalid records, masking a field, converting a format or enriching a record from a lookup. Because no record depends on another, stateless work scales simply by adding parallel workers, and a failed record can be retried in isolation. A Lambda function triggered by a stream, or a Firehose transformation, is typically stateless.
Stateful processing keeps information across records: counting events per user in five-minute windows, joining two streams, deduplicating by event ID or detecting a sequence of events. The state must survive failures, so stateful engines store it in checkpoints. Amazon Managed Service for Apache Flink keeps keyed state with exactly-once checkpoints, Spark Structured Streaming in Glue or EMR checkpoints to S3, and Lambda offers limited state through tumbling windows of up to 15 minutes. The same terms apply to transactions: a stateless transaction carries everything it needs, while a stateful one depends on context held from earlier steps, such as a session. The following table summarises the difference.
Stateless or stateful?
One stream, three teams
Two thousand retail stores send sales events to one Kinesis data stream in on-demand mode, using the store ID and register as the partition key so writes spread evenly (fan-in). Three teams consume the stream: fraud detection, a real-time dashboard and an archive. Fraud detection and the dashboard register for enhanced fan-out so each has its own throughput (fan-out), while Firehose archives to S3. Fraud detection must compare each card's transactions over the last ten minutes, which is stateful, so it runs on Managed Service for Apache Flink with keyed state; the dashboard's per-record formatting is stateless and runs in Lambda.
How is one message delivered to many independent subscribers, each with its own retries?
Show answer
With SNS-to-SQS fan-out: an SNS topic publishes to one SQS queue per subscriber.
Exam Tips
Remember for the exam
- Fan-in: many producers into one stream; size for combined throughput and spread partition keys.
- Several consumers each needing full Kinesis throughput: enhanced fan-out.
- One message to many independent subscribers: SNS-to-SQS fan-out.
- Windows, joins and deduplication are stateful; use Managed Service for Apache Flink or Spark Structured Streaming.
- Per-record filtering, masking and format conversion are stateless and scale by adding workers.