teluzia.Cloud Engineer · Day 67
CHAPTER 10 · SERVERLESS AND MESSAGING

SNS and pub/sub

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

SNS is an announcement board: one publication reaches many interested subscribers, each responsible for its own delivery and processing behavior. An SNS topic gives publishers one destination and distributes messages to subscribed endpoints. Subscribers can include queues, functions, or other supported transports. Publishing does not mean every consumer has finished its work. Subscription confirmation, endpoint policies, and delivery permissions determine whether the intended receiver actually accepts the message. Subscription filter policies decide which messages a subscription receives, using configured attribute or body filtering. Each consumer can select relevant events without making publishers maintain separate delivery lists. A filtered-out event is intentionally not delivered, so the filter configuration is part of the data contract and deserves tests.

Think of it this way

SNS is an announcement board: one publication reaches many interested subscribers, each responsible for its own delivery and processing behavior.

TOPIC 01 / 03Step by step

Topics, publishing, and subscriptions

An SNS topic gives publishers one destination and distributes messages to subscribed endpoints. Subscribers can include queues, functions, or other supported transports. Publishing does not mean every consumer has finished its work. Subscription confirmation, endpoint policies, and delivery permissions determine whether the intended receiver actually accepts the message. For example, an order-created topic fans out to an inventory queue and an audit queue; the producer does not know each worker’s address.

WORKED EXAMPLE
An order-created topic fans out to an inventory queue and an audit queue; the producer does not know each worker’s address.

A catalog service announces that a product changed. It publishes once to an SNS topic rather than individually calling search, analytics, and cache services. SNS evaluates the topic's subscriptions and attempts delivery through their respective protocols. Each receiver then handles its own processing; a successful publish response does not mean every index or cache has finished updating.

A publisher produces notifications. A topic is their shared distribution destination. A subscription connects that destination to an endpoint. Some endpoint types require confirmation, and permissions can prevent delivery even when the subscription exists. Start diagnosis by checking accepted publication, subscription confirmation where required, endpoint authorization, then receiver behavior. Fan-out improves independence, but creates eventual consistency: search and cache may update at different times. Include an event identifier and schema version so consumers can diagnose duplication or incompatible messages without forcing the publisher to know each consumer's internal implementation.

Why this matters

Fan-out reduces producer coupling and lets independent consumers evolve without rewriting the order service whenever another team needs the same business event.

A common trap

Assuming a successfully accepted publish proves every subscriber processed the message hides unconfirmed subscriptions, denied queue delivery, and downstream worker failures or backlogs.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Topics, publishing, and subscriptions

An SNS topic gives publishers one destination and distributes messages to subscribed endpoints. Subscribers can include queues, functions, or other supported transports. Publishing does not mean every consumer has finished its work. Subscription confirmation, endpoint policies, and delivery permissions determine whether the intended receiver actually accepts the message. For example, an order-created topic fans out to an inventory queue and an audit queue; the producer does not know each worker’s address.

WORKED EXAMPLE
An order-created topic fans out to an inventory queue and an audit queue; the producer does not know each worker’s address.

A catalog service announces that a product changed. It publishes once to an SNS topic rather than individually calling search, analytics, and cache services. SNS evaluates the topic's subscriptions and attempts delivery through their respective protocols. Each receiver then handles its own processing; a successful publish response does not mean every index or cache has finished updating.

A publisher produces notifications. A topic is their shared distribution destination. A subscription connects that destination to an endpoint. Some endpoint types require confirmation, and permissions can prevent delivery even when the subscription exists. Start diagnosis by checking accepted publication, subscription confirmation where required, endpoint authorization, then receiver behavior. Fan-out improves independence, but creates eventual consistency: search and cache may update at different times. Include an event identifier and schema version so consumers can diagnose duplication or incompatible messages without forcing the publisher to know each consumer's internal implementation.

Why this matters

Fan-out reduces producer coupling and lets independent consumers evolve without rewriting the order service whenever another team needs the same business event.

A common trap

Assuming a successfully accepted publish proves every subscriber processed the message hides unconfirmed subscriptions, denied queue delivery, and downstream worker failures or backlogs.

Subscription filtering

Subscription filter policies decide which messages a subscription receives, using configured attribute or body filtering. Each consumer can select relevant events without making publishers maintain separate delivery lists. A filtered-out event is intentionally not delivered, so the filter configuration is part of the data contract and deserves tests. For example, the billing subscription accepts eventType=order-paid, while inventory accepts eventType=order-created; both use the same overall event topic.

WORKED EXAMPLE
The billing subscription accepts eventType=order-paid, while inventory accepts eventType=order-created; both use the same overall event topic.

Suppose a topic carries account events with attributes accountTier and operation. A premium-support subscription accepts accountTier=premium, while a billing subscription accepts operation=invoice. Publishing an event with only a body field named tier does not automatically satisfy an attribute-based accountTier filter. The event can be accepted and correctly delivered to other subscribers while premium support receives nothing.

A filter policy belongs to a subscription. Filter-policy scope determines whether filtering inspects message attributes or the message body. The schema is the agreement about names, types, and values that publishers and filters expect. Treat a filter change like a contract change: test one event that should match and one that should not. Broadening a filter temporarily may help diagnosis but can substantially increase downstream load or expose irrelevant events. Attribute renames should be coordinated, often with a transition period supporting both representations instead of assuming every consumer updates instantly.

Why this matters

Filtering reduces needless worker execution and makes consumer boundaries visible, which helps predict load and prevent unrelated events from entering sensitive business workflows.

A common trap

Renaming an event attribute without updating filter policies can silently stop expected deliveries even though the topic still accepts every publication successfully.

SNS with SQS for durable fan-out

SNS publishes notifications; SQS buffers work until a consumer handles it. Combining them allows each subscriber its own durable backlog and retry behavior. The queue policy must allow the intended topic to send messages, preferably constrained by source ARN. Consider SNS envelopes versus raw delivery when defining consumer parsing. For example, inventory is offline for an hour; its subscribed queue holds notifications while the audit queue’s worker continues independently processing its own backlog.

WORKED EXAMPLE
Inventory is offline for an hour; its subscribed queue holds notifications while the audit queue’s worker continues independently processing its own backlog.

An inventory team cannot process notifications during maintenance. Direct notification delivery to its worker gives limited buffering behavior governed by the chosen delivery protocol. Subscribing its own SQS queue instead allows messages to accumulate while an audit team's separate queue continues being drained. When inventory returns, its workers process that queue at their own pace.

Fan-out means one publication creates independent deliveries. Buffering stores pending work across consumer unavailability. Backpressure describes consumers falling behind incoming work. The SNS-to-SQS connection needs an appropriate queue resource policy, preferably constrained to the intended topic source. The consumer also needs to know whether its body is the raw published message or an SNS notification envelope whose Message field contains the business payload. Independent queues improve isolation but introduce queue retention, duplicate handling, backlog alarms, and cost. Monitor age as well as message count: a small number of very old messages may be more serious than a short large burst.

Why this matters

Independent buffers prevent one slow consumer from dictating every subscriber’s pace and make recovery measurable through queue age, depth, and worker error evidence.

A common trap

Using the wrong SNS envelope shape in a worker parser produces missing-field errors; raw message delivery and default wrapped delivery have different bodies.

KEEP THESE WITH YOU

Today’s takeaways

Topics, publishing, and subscriptions: An SNS topic gives publishers one destination and distributes messages to subscribed endpoints. Subscribers can include queues, functions, or other supported transports. Publishing does not mean every consumer has finished its work. Subscription confirmation, endpoint policies, and delivery permissions determine whether the intended receiver actually accepts the message.

Subscription filtering: Subscription filter policies decide which messages a subscription receives, using configured attribute or body filtering. Each consumer can select relevant events without making publishers maintain separate delivery lists. A filtered-out event is intentionally not delivered, so the filter configuration is part of the data contract and deserves tests.

SNS with SQS for durable fan-out: SNS publishes notifications; SQS buffers work until a consumer handles it. Combining them allows each subscriber its own durable backlog and retry behavior. The queue policy must allow the intended topic to send messages, preferably constrained by source ARN. Consider SNS envelopes versus raw delivery when defining consumer parsing.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed