Building a Notification Service with AWS Services
In this article, we will explore how to build a service that can send notifications as email, SMS, and push notifications and how to automate the sending of these notifications based on pre-defined system events.
Business Requirements
- Notification type: Notification can be send as email, sms and push notifications.
- Event Based and manual trigger:
- The notifications should be automated, triggered by pre-defined system events, such as sending a welcome notification to the user after the registration process has been completed.
- Notification should be send manual. - Template Based: Notifications were template-based and could vary depending on the type of events or input.
Tech Stack
- Programming Language: JAVA, Python, Other languages
- AWS Services: Amazon Pinpoint, SQS, SES, SNS
- Database: Mongo DB
- Notification Types:
Email: AWS SES
SMS: AWS SNS
Push Notification: FCM, APNs
Setup Prerequisites
I am assuming you have AWS account.
- Setup AWS Credential
- Create and configure a Amazon Pinpoint project
- Create Amazon Pinpoint message templates for each notification event with required notification channel.
- Create a collection in Mongo DB to store the notification events details. For example, we need to send email and sms notifications to the user after the registration complete, so create notification event for this event
notificationEvents:{ “notificationEvent”: “userRegistered”, “notificationTypes”: [ {“type”: “email”, “pinpointTemplateName”: “user_registered”, “templateAttributes”: [“firstName”] }, {“type”: “sms”, “pinpointTemplateName”: “user_registered”, “templateAttributes”: [“firstName”] } ] }
Service Architecture
Notification Service Internal Work Flow
Architecture Overview
Event Consumer: This component responsible for the listens messages on the SQS queue and extracts the necessary information from the message. It then passes the information to the event handler.
Event Handler: This will contain the logic for sending notifications based on pre-defined events that are stored in MongoDB.
Notification Controller: This component will be responsible for handling incoming requests from the client. This will contain the necessary REST endpoints for sending notifications.
Repository Interface: This component will interact with the database to store and retrieve pre-defined events and settings.
Notification Service: This component will contain the business logic for sending notifications.
Notification Channel Service: This component is responsible for sending notifications to the appropriate channels, such as email, SMS, or push notifications. It will call the appropriate method from the Pinpoint client to send a specific type of notification.
Pinpoint Client: This component is responsible for interacting with the Amazon Pinpoint service to send notifications.
Conclusion
In this article, we have discussed how to build a service for sending notifications via email, SMS, and push notifications. We have used Amazon Pinpoint to send notifications, and we have used MongoDB to store pre-defined events and settings. With this microservice, you can easily add notification functionality to your application and provide a better user experience.