Notification Design with Amazon SNS - Topic and Subscription Patterns
Learn how to choose between Standard and FIFO topics, implement the SQS fan-out pattern, and use subscription filters for conditional routing.
Topic Design and Subscriptions
SNS topics come in two types: Standard and FIFO. Standard topics provide virtually unlimited throughput with best-effort message ordering. FIFO topics provide strict ordering per message group ID and deduplication via message deduplication IDs. FIFO topic subscribers are limited to SQS FIFO queues. Subscription protocols support SQS, Lambda, HTTP/HTTPS, email, SMS, and Kinesis Data Firehose. By attaching message attributes, you can enable conditional routing through subscription filter policies.
Fan-Out Pattern Design
The SNS + SQS fan-out pattern subscribes multiple SQS queues to an SNS topic, delivering messages to all queues with a single publish. Each queue's consumer processes independently, so a failure in one consumer does not affect others. This pattern is typically used in order processing systems, where a single order event is simultaneously delivered to an inventory update queue, email notification queue, and analytics recording queue. There is no practical limit on fan-out targets (the per-account subscription quota is 12,500,000), and adding new processing only requires adding a subscription without any changes to the publisher. For cross-account fan-out, the topic policy allows Subscribe from SQS queues in other accounts, keeping microservices loosely coupled.
Subscription Filters and Delivery Guarantees
Subscription filter policies come in two types: attribute-based and payload-based. Attribute-based filters define conditions on message attributes (exact string match, prefix match, numeric comparison, exists check). Payload-based filters execute filtering against JSON paths in the message body, supporting nested fields. Filters are evaluated on the SNS side, so messages that don't match conditions are never delivered to subscribers, reducing downstream processing costs and noise. Retry policies for delivery failures vary by protocol; HTTP/HTTPS endpoints use exponential backoff (up to 23 days) for retries. Messages that cannot be delivered after retries are sent to a dead-letter queue (DLQ) for later investigation or reprocessing. The DLQ redrive feature allows redelivering messages to the original subscription after the issue is resolved.
FIFO Topics and Message Attributes
FIFO topics provide message ordering guarantees and deduplication, achieving strict ordered processing when combined with FIFO SQS queues. Message group IDs logically group messages, guaranteeing order within each group. Message attributes attach metadata (event type, priority, source), and subscription filter policies implement attribute-based routing. Message data protection automatically detects PII (personally identifiable information) and lets you configure policies for masking or rejection. To gain a deeper understanding of notification design integration patterns, specialized books (Amazon) can be helpful.
Design Pitfalls and Operational Considerations
The maximum SNS message size is 256 KB; for larger payloads, store the content in S3 and send only a pointer via SNS using the Extended Client Library pattern. FIFO topic throughput is limited to 300 messages per second per message group (3,000 with batching), so high-throughput use cases require distributing message group IDs. As filter policy complexity grows, debugging becomes difficult - keep filter conditions to 5 attributes or fewer per subscription, and consider EventBridge for complex routing. HTTP/HTTPS endpoint subscriptions will not receive messages until subscription confirmation is complete, so handling the confirmation token must be part of the endpoint implementation. Enabling message encryption (SSE) requires the subscriber's IAM role to have KMS decrypt permissions, which is often overlooked.
SNS vs. EventBridge - When to Use Which
Both SNS and EventBridge are core to event-driven architectures, but they have different strengths. SNS excels at simple fan-out and protocol diversity (SQS, Lambda, HTTP, SMS, email), with low message delivery latency. EventBridge excels at complex rule matching against event structure (100+ field patterns), schema registry for type safety, and SaaS integrations. As a practical guideline, use SNS for in-application fan-out (order → multiple queues) and EventBridge for inter-service event routing (complex conditional branching, external SaaS events). SNS supports a vastly larger number of delivery targets per topic (12,500,000 subscriptions), while EventBridge is limited to 5 targets per rule but scales through the number of rules.
SNS Pricing
Publishing to SNS Standard topics costs approximately $0.50 per million requests. FIFO topics cost approximately $0.30 per million requests. Delivery to HTTP/S endpoints costs approximately $0.60 per million notifications, while delivery to SQS is free. SMS delivery uses per-message pricing that varies by destination country. Message filtering is available at no additional charge, reducing unnecessary message delivery and optimizing downstream costs.
Summary
SNS is a topic-based Pub/Sub messaging service that provides flexible message routing through fan-out patterns and subscription filters. FIFO topics deliver ordering guarantees and deduplication, while message data protection enables automatic PII detection and masking. Combined with SQS, it builds reliable asynchronous processing pipelines, with DLQs ensuring delivery failures are reliably captured.