RHRipan Halder Résumé ↓

AWS & Platform

SNS, SQS and Lambda Fan-Out: When to Combine Them

How publish/subscribe, durable queues and serverless consumers work together for independent asynchronous workflows.

Production lens

This note focuses on design reasoning, failure behavior and operational evidence—the parts that matter in code review, system design and incident response.

Why this problem matters

One event may need several independent reactions: email, analytics, audit and downstream integration. Calling each consumer synchronously couples availability and latency. SNS provides fan-out, while SQS gives each consumer durable buffering and independent retry behavior.

A useful mental model

The publisher sends one message to an SNS topic. Each subscription delivers to its own SQS queue. Lambda or another consumer processes each queue independently. A slow email path does not block analytics, and each queue can have its own dead-letter policy and scaling behavior.

Design principles

The following principles are useful because each one creates a boundary that can be reviewed, tested and observed. They are not independent checkboxes: together they define the behavior of the system under normal load and partial failure.

Create one queue per independent consumer responsibility

Treat this as an architectural constraint rather than a cleanup item. Put the boundary in code, configuration or the data model so a reviewer can see exactly where it is enforced.

Use queue policies that allow only the intended SNS topic

The benefit becomes visible when timing changes under load or failure. Define the limit explicitly and make the fallback, rejection or recovery behavior observable.

Set visibility timeout longer than normal processing time

Ownership matters here. The component that owns the invariant should also own the validation, compatibility rule and operational response when the assumption is violated.

Configure redrive to a dead-letter queue with operational ownership

Prefer the smallest mechanism that preserves correctness. Add sophistication only after measurements show that the simpler design cannot meet the workload.

Make Lambda handlers idempotent because delivery is at least once

Convert this principle into an automated test, deployment check or runbook step. Otherwise it will drift as dependencies, traffic and team ownership change.

How to validate: Verify the design with change sets, least-privilege review, deployment rollback and controlled infrastructure failure. A diagram is incomplete until recovery has been exercised.

Key trade-offs

Good engineering makes the cost of a choice visible. For this topic, the most important trade-offs are:

Managed simplicityManaged services reduce undifferentiated work but still require limits, IAM and failure planning.
PortabilityMore portability can introduce a larger platform surface and higher operating cost.
Blast radiusStack and account boundaries should match how the system is deployed and recovered.

Concrete example

The example below is intentionally small. Its purpose is to expose the control point or data flow that the design depends on, not to present a complete framework implementation.

BillCreated topic
  ├─ email-queue → Lambda → SES
  ├─ audit-queue → audit consumer
  └─ analytics-queue → warehouse loader

When applying this pattern, define what happens immediately before and after every durable boundary. That is where duplicate work, stale state, lock duration, timeout overlap or deployment risk usually enters the design.

Common failure modes

Failure modes are more useful than generic “best practices” because they describe the condition the design must survive. Review each one as a concrete test scenario.

  • Subscribing Lambda directly when durable buffering and replay are required. The usual consequence is hidden backlog, duplicate work or state that can no longer be explained. Add a bounded guardrail and reproduce the condition under load.
  • One shared queue for unrelated consumers. This often passes unit tests because the timing, cardinality or dependency behavior is too clean. Test it with realistic concurrency and an intentionally slow or failing dependency.
  • Visibility timeout shorter than processing time, causing concurrent duplicate delivery. During restart or replay, the defect can turn a recoverable incident into inconsistent state. Preserve enough context to detect, stop and safely resume the workflow.
  • No policy for poison messages. The safest mitigation is to make the assumption explicit in a constraint, deadline, queue limit or state transition, then alert when the boundary is approached.

What to measure

Production behavior should be visible before a failure becomes a customer complaint. Metrics should connect a technical symptom to a workload, business state or recovery objective.

  • Approximate age of oldest messageUse this as an early saturation signal and define what healthy, warning and overloaded behavior look like.
  • Queue depthBreak this down by service version, endpoint, partition or tenant so aggregate averages do not hide one failing path.
  • Lambda concurrency and throttlesCorrelate this with user-visible latency and error rate to distinguish harmless internal work from customer impact.
  • DLQ countTrack both the level and the age of the condition; an old small backlog can be more serious than a brief large spike.
  • End-to-end event latencyReview this after deployments and failure drills so the dashboard proves recovery, not only steady-state health.

Interview-ready explanation

A strong explanation starts with the invariant: state what must remain true even when requests repeat, dependencies slow down or instances restart. Then describe the mechanism that preserves it, the failure mode that mechanism introduces and the signal that proves it is working.

For SNS, SQS and Lambda Fan-Out: When to Combine Them, avoid listing tools first. Explain the workload and boundary, walk through the normal path, introduce one realistic failure and show how the system recovers. Finish with the metric or test that validates the claim. That structure demonstrates senior engineering judgment more clearly than naming patterns without context.

Review checklist

Use this checklist during design review, implementation planning or incident follow-up:

  1. Separate consumers by queue.
  2. Set visibility timeout.
  3. Add DLQs.
  4. Make handlers idempotent.
  5. Trace event IDs end to end.
A sound design is not the one with the most patterns. It is the one whose invariants, limits and recovery paths are explicit—and can be demonstrated.