
One Event, Three Jobs: What SNS Fan-Out Taught Me About Decoupling
How publishing one order event to an SNS topic gave each downstream job its own retries, pace, and failures — and what I wish I had known about idempotency, ordering, and filter policies first.
The first version of my order flow had one Lambda doing everything. A user placed an order, and that single function sent the confirmation email, updated the search index, and logged the event for analytics — all in one try/catch block, one after the other.
It worked until it didn't. One day the email provider was slow, the function timed out halfway through, and the search index never got updated. The order itself was saved, but nothing downstream knew about it. I had coupled three unrelated jobs together and given them one shared fate: if any one of them failed, all of them failed.
That was when I rebuilt the flow around SNS fan-out, and it changed how I think about decoupling.
What fan-out actually looks like
The idea is simple. Instead of the order service calling three things, it publishes one message to one SNS topic — something like order-placed — and then it is done. Three separate subscribers listen to that topic: an SQS queue that feeds the email worker, another queue for the search indexer, and a Lambda that records analytics.
Each subscriber gets its own copy of the message and works at its own pace. The publisher does not know who is listening, and it does not care. If I want to add a fourth job later — say, a fraud-check worker — I subscribe it to the topic. The order service never changes.
That last part was the real win for me. Before, adding a step meant editing the one big function and re-testing everything it did. Now adding a step means wiring up one new subscriber. The blast radius of a change shrank from "the whole order flow" to "one small worker."
Failure isolation is the point
The deeper benefit is that failures stop cascading. When the email queue backs up now, the search index still updates and analytics still records, because they are separate subscribers with separate retries. One slow downstream no longer holds the others hostage.
SQS queues in front of each subscriber make this practical. A failed email delivery retries from its own queue with its own dead-letter queue, instead of failing the whole order flow. I already had DLQs from an earlier lesson — fan-out is what finally gave each job its own.
But fan-out is not free, and the trade-offs are worth knowing before you use it.
Three things I wish I had known first
First, delivery is at-least-once, not exactly-once. A subscriber can receive the same message twice. My email worker learned this the embarrassing way when a customer got the same confirmation twice. Every subscriber now has to be idempotent — I check the order ID against a small record before doing the work, so a duplicate delivery is a no-op instead of a second email.
Second, ordering is not guaranteed on a standard topic. For order events that did not matter, because each message carried everything its subscriber needed. But the one place it did matter was inventory: two events for the same product arriving out of order could have miscounted stock. That flow uses an SNS FIFO topic with a message group ID per product, which preserves order within a group. Standard topics for most things, FIFO only where order actually matters — FIFO costs more and is slower, so I do not reach for it by default.
Third, filter policies keep subscribers sane. Without them, every subscriber gets every message on the topic and has to ignore the ones it does not want. A filter policy — for example, only messages where event_type equals order_placed — means each subscriber only sees what it should act on. It is a small configuration detail that keeps the whole design honest: the topic routes, the subscriber acts.
My takeaway
Fan-out taught me that decoupling is not about using more services. It is about giving each job its own fate. One publisher, one topic, and as many independent subscribers as I need — each with its own retries, its own pace, and its own failures that stay its own.
If you have a function that does three things in sequence and any one of them can break the other two, that function is quietly asking to become a topic.
What is the one place in your system where a single failure still takes down jobs that had nothing to do with it?
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article