Event-driven architecture on AWS: the patterns and when to use each
Queue, topic, bus, stream or workflow: choose by who must know an event happened and what breaks if it arrives twice, late or never. SQS, SNS, EventBridge, Kinesis and Step Functions compared by what each one promises when a consumer fails.
ON THIS PAGE
Choose between a queue, a topic, a bus, a stream and a workflow by answering two questions: who must know that the event happened, and what breaks if it arrives twice, late or never. One worker that must eventually do the job wants an SQS queue. A short list of consumers you own wants an SNS topic with a queue behind each. Consumers you have not met yet want an EventBridge bus. Readers that need history in order want a Kinesis stream. And when the order of the steps is the business rule, you want a Step Functions workflow, not events at all.
Twice is the default; late and never are the choice#
Almost everything here delivers at least once. SQS Standard and Lambda event source mappings can deliver duplicates. SNS delivery and EventBridge retry behaviour depend on the endpoint and bus type. Keep the side effect safe to repeat, even when a broker deduplicates sends. Powertools for AWS Lambda shows how to store an idempotency key for each operation.
That leaves late and never, and this is where the five really differ.
The five, by what each one promises#
- Queue (SQS). Holds a message for up to 14 days until one consumer deletes it. A consumer that is down for an hour comes back to a backlog, not a gap. After a set number of failed receives the message moves to a dead-letter queue, where an alarm can find it.
- Topic (SNS). Pushes a copy to each matching subscriber. Configure a dead-letter queue per subscription for failed deliveries. SNS FIFO topics can also archive messages for replay.
- Bus (EventBridge). Matches each event against rules on its content and sends it to whichever targets match. The producer never learns who listens, which is the point. On a Classic bus, delivery is unordered, the default retry policy allows up to 185 retries over 24 hours, and an optional archive lets you replay. The newer Custom event bus can deliver in order per group through FIFO subscribers.
- Stream (Kinesis Data Streams). An ordered log per shard, kept for 24 hours by default and up to 365 days. Every reader keeps its own position and can go back. Nothing is deleted when it is read.
- Workflow (Step Functions). Not a message channel: one execution owns the sequence. Standard workflows run each step exactly once, unless you add retries, for up to a year, with 90 days of history you can query. Express workflows run for up to five minutes. Asynchronous Express is at least once, while Synchronous Express is at most once.
Only one of them turns never into late on its own#
With a standard topic or a Classic bus, failed target deliveries can be lost when the retry window closes. Set a dead-letter destination. A queue holds the message until a consumer deletes it or its retention expires. A queue is useful even when a bus does the routing. The bus decides where an event goes, and the queue in front of each consumer makes sure it is still there when that consumer recovers.
A stream fails the other way. A standard queue can move other messages while one is failing. A stream keeps the order, so by default Lambda retries the failing batch until it succeeds or the records expire, and that shard stops moving. One malformed record can hold up every record behind it for a day. If you choose a stream for its ordering, tell the mapping what to do with a record that will never succeed:
aws lambda create-event-source-mapping \
--function-name settle-payments \
--event-source-arn "$STREAM_ARN" --starting-position LATEST \
--bisect-batch-on-function-error \
--maximum-retry-attempts 3 \
--destination-config '{"OnFailure":{"Destination":"'"$FAILED_QUEUE_ARN"'"}}'Bisection splits failing batches to isolate bad records. The SQS destination receives metadata about the discarded batch. Choose S3 as the destination if you need AWS to preserve the full invocation payload. On a queue the equivalent is reporting partial batch failures, so that one bad message does not send nine good ones back for another try.
Choreography or a workflow#
Events suit work where each consumer can act without knowing what the others did. When the third step must not run unless the second succeeded, and a refund must undo the charge if shipping fails, you are writing a workflow in event handlers. Each service then holds a piece of the state, and the question "where is order 42?" needs four log searches. A Step Functions execution answers it in one place. The usual mix is a bus between teams and a workflow inside one: events say what happened, and the workflow decides what happens next. archhy’s invoice pipeline shows the event side at scale.
On Google Cloud and Azure#
The five shapes exist on every cloud, under different names. On Google Cloud, Cloud Tasks is the queue, Pub/Sub is topic and queue in one (each subscription keeps its own copy), Eventarc routes events to destinations, Managed Service for Apache Kafka is the stream and Workflows orchestrates. On Azure, Service Bus queues and topics cover the first two, Event Grid is the router, Event Hubs is the stream, and Durable Functions or Logic Apps run the workflow.
The diagram#
One producer and the five channels side by side, each labelled with who receives the event and what happens when the consumer fails. Open it in archhy and press Make a copy to adapt it.
Reference documentation: EventBridge retry policy, Custom event bus ordering, SNS FIFO archiving, Step Functions workflow types, Kinesis event source errors, Cloud Tasks and Pub/Sub, Azure messaging services.
