How to know once all the SNS subscribers received the message?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Amazon Simple Notification Service (SNS) is a highly available, durable, secure, fully managed pub/sub messaging service that enables you to decouple microservices, distributed systems, and serverless applications. However, one common challenge with SNS, or any pub-sub messaging system, is determining whether all subscribers have successfully received a message. This article explores strategies and considerations for ensuring message delivery to all SNS subscribers.
Understanding SNS Basics
SNS allows you to publish messages to a topic. Multiple subscribers can subscribe to the topic and receive messages. Subscriber types can include AWS Lambda, Amazon SQS, email, SMS, or HTTP endpoints, among others. When you publish a message, it gets sent to all subscribers of the topic.
Confirming Message Receipt
Unlike some messaging systems, SNS does not natively confirm if every subscriber has received a message. To ensure all subscribers receive their messages, consider the following solutions:
1. Subscriber Acknowledgment
Implement an acknowledgment mechanism within each subscriber. After processing a received message, the subscriber should send an acknowledgment back to your system. This can be achieved by making an API call to a database or another service where acknowledgments are logged.
2. DLQ for Failed Messages
Set up Dead Letter Queues (DLQs) for subscribers (where applicable, e.g., Lambda, SQS). If SNS fails to deliver a message to a particular subscriber after several retries, the message can be directed to a DLQ. You can monitor and handle messages in the DLQ to ensure they are eventually processed.
3. CloudWatch Monitoring
Utilize AWS CloudWatch to monitor the NumberOfNotificationsDelivered and NumberOfNotificationsFailed metrics. While these metrics don’t verify deliveries to each subscriber, they provide high-level delivery metrics.
4. SNS Delivery Status Logging
Enable SNS Delivery Status Logging to log the delivery status of messages to subscribers. You can analyze these logs to monitor and verify deliveries.
5. Custom Application Logic
Build a custom layer in your application to manage and verify message deliveries. For example, after publishing a message, the system could check that all required acknowledgments are received within a certain timeframe.
Ensuring Reliable Delivery
To increase the reliability of message delivery, consider the following settings and designs:
- Quality of Service Settings: Adjust the retry policies and message retention durations to align with your application needs.
- Subscriber Health Checks: Regularly check the health and availability of subscribers and automate recovery or alerts in case of failures.
- Redundancy: Use multiple channels or subscribers to provide redundancy. For critical messages, consider sending the same message through different mediums.
Technical Example
Below is an example of setting up an acknowledgment mechanism using AWS Lambda and Amazon DynamoDB:
In this example, after the Lambda function processes the SNS message, it logs an acknowledgment to a DynamoDB table. Monitoring tools can then check this table to ensure every message has been acknowledged.
Summary Table
| Strategy | Description | Considerations |
| Subscriber Acknowledgment | Subscribers confirm message receipt via an external system | Requires additional implementation at the subscriber level |
| Dead Letter Queues | Unprocessed messages are redirected to a DLQ for further handling | Setup DLQs for each subscriber type capable of using them |
| CloudWatch Monitoring | Monitor delivery metrics through AWS CloudWatch | Provides only aggregated metrics, not specific delivery confirmations |
| SNS Delivery Status Logging | Logs the status of message delivery in CloudWatch Logs or S3 | Good for auditing and historical analysis but increases operational overhead |
| Custom Application Logic | Custom logic in your application to track and confirm message delivery | Most flexible, but requires additional development and maintenance |
By employing one or multiple of these strategies, you can enhance the reliability of your SNS message delivery, ensuring all subscribers receive necessary messages effectively and promptly.

