<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sahand Seifi</title>
    <description>The latest articles on DEV Community by Sahand Seifi (@_sahand).</description>
    <link>https://dev.to/_sahand</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F859918%2F1322643a-b76f-4e5e-b7b7-000aff332afe.jpg</url>
      <title>DEV Community: Sahand Seifi</title>
      <link>https://dev.to/_sahand</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_sahand"/>
    <language>en</language>
    <item>
      <title>The Developer's Guide to Google Bulk Sender Requirements</title>
      <dc:creator>Sahand Seifi</dc:creator>
      <pubDate>Mon, 05 Feb 2024 17:47:20 +0000</pubDate>
      <link>https://dev.to/notificationapi/the-developers-guide-to-google-bulk-sender-requirements-826</link>
      <guid>https://dev.to/notificationapi/the-developers-guide-to-google-bulk-sender-requirements-826</guid>
      <description>&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;Starting in February 2024, Google enforces new requirements for sending emails to its users.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Does this apply to me?
&lt;/h2&gt;

&lt;p&gt;Yes. The requirements can be split into 3 levels:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic requirements for any sender&lt;/li&gt;
&lt;li&gt;Bolder new requirements for domains that send more than 5000 emails per day&lt;/li&gt;
&lt;li&gt;One additional requirement for domains that send marketing emails&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Since it is unclear how Google recognizes your emails as transactional vs. marketing, we recommend that anyone sending more than 5k emails/day follow all the requirements.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Do NotificationAPI users need to take action?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.notificationapi.com"&gt;NotificationAPI&lt;/a&gt; users are automatically compliant.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 1 Requirements:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Any Sender
&lt;/h2&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h3&gt;
  
  
  1. SPF &amp;amp; DKIM
&lt;/h3&gt;

&lt;p&gt;You probably have one or both of these DNS records already setup:&lt;/p&gt;

&lt;p&gt;AWS SES: Verified domains use DKIM by default, you may need to verify SPF&lt;br&gt;
SendGrid: DKIM &amp;amp; SPF verified by default&lt;br&gt;
Mailgun: you need to check the "DKIM" option when configuring your domain&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to test:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Send an email to yourself in Gmail. Check your domain's verifications using the "Show Original" option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8eot346ghohxokqu5iz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8eot346ghohxokqu5iz.png" alt="Test SPF/DKIM/DMARC verification in Google&amp;lt;br&amp;gt;
" width="800" height="440"&gt;&lt;/a&gt;&lt;br&gt;
‍&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Spam rate &amp;lt; 0.1% - 0.3%
&lt;/h3&gt;

&lt;p&gt;This refers to how many of your outgoing emails are reported as spam by recipients. Google suggests keeping this below 0.1% (1 in 1000 emails) and avoiding 0.3%.&lt;/p&gt;

&lt;p&gt;We recommend signing up for &lt;a href="https://postmaster.google.com/"&gt;Google Postmaster Tools&lt;/a&gt;, which reports on your domain's email reputation and spam rates.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Generic requirements: PTR Record, TLS Connection, RFC 5322 Email Formatting
&lt;/h3&gt;

&lt;p&gt;If you use any modern email service, you shouldn't worry about these requirements.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 2 Requirements:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Senders with 5000+ emails/day
&lt;/h2&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h3&gt;
  
  
  4. DMARC record
&lt;/h3&gt;

&lt;p&gt;‍DMARC is a TXT record that has many configurations. Simply, it tells recipients how to treat emails from your domain that don't pass SPF/DKIM verification.&lt;/p&gt;

&lt;p&gt;Setting a strict DMARC configuration could block your emails. So be careful!&lt;/p&gt;

&lt;p&gt;We recommend that you start with a loose DMARC record, such as:&lt;/p&gt;

&lt;p&gt;Record Name: _dmarc&lt;/p&gt;

&lt;p&gt;‍Record Value: v=DMARC1; p=none;&lt;/p&gt;

&lt;p&gt;This record tells recipients that you want to follow DMARC standard v1 (recommended) but not to do anything (p=none) when they encounter an email from your domain that doesn't pass SPF/DKIM.&lt;/p&gt;

&lt;p&gt;Over time, you want to change the DMARC record to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Report back emails with faulty SPF/DKIM using the rua option,&lt;/li&gt;
&lt;li&gt;Fix the issues,&lt;/li&gt;
&lt;li&gt;And make the DMARC record more strict using the p option&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h3&gt;
  
  
  5. DMARC Alignment‍
&lt;/h3&gt;

&lt;p&gt;There are two "from" addresses for every email:&lt;/p&gt;

&lt;p&gt;Header From: the regular From address you see on an email, e.g. John Smith &lt;a href="mailto:john@smith.com"&gt;john@smith.com&lt;/a&gt;&lt;br&gt;
Envelope From: refers to the source of the email. For example, an email from &lt;a href="mailto:john@smith.com"&gt;john@smith.com&lt;/a&gt; may have an envelope header sendegrid.com.&lt;br&gt;
DMARC Alignment means Header From matching your Envelope From.&lt;/p&gt;

&lt;p&gt;Alignment could be 1) relaxed, where one From is the subdomain of the other from, or 2) strict, where the domains exactly match. Google is ok with either.&lt;/p&gt;

&lt;p&gt;In the image below, you see a spam email where the Header From differs from the Envelope From, and Gmail is bringing attention to it with the "via" keyword.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqra8edcy76sx1j9dg89.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqra8edcy76sx1j9dg89.png" alt="Gmail highlighting the difference of Header From and Envelope From" width="800" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 3 Requirements:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Marketing emails
&lt;/h2&gt;

&lt;p&gt;Recommended for Transactional Too!&lt;br&gt;
There is no way to know how Google categorizes your emails (marketing vs transactional), so we recommend doing this anyway.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h3&gt;
  
  
  6. One-Click Unsubscribe
&lt;/h3&gt;

&lt;p&gt;First, create an API end-point like the one below. The method must be POST, but the URL can be anything.&lt;/p&gt;

&lt;p&gt;Method: POST&lt;br&gt;
URL: &lt;a href="https://app.yourdomain.com/unsubscribe?email=user@gmail.com"&gt;https://app.yourdomain.com/unsubscribe?email=user@gmail.com&lt;/a&gt;&lt;br&gt;
Body: none&lt;br&gt;
You should unsubscribe the user from your email when this end-point is hit. For example, Google will call this end-point when the user hits the "Unsubscribe" button in Gmail's interface.&lt;/p&gt;

&lt;p&gt;The One-Click Unsubscribe mechanism in action&lt;br&gt;
Then, add the following headers to your outgoing emails:&lt;/p&gt;

&lt;p&gt;List-Unsubscribe-Post: List-Unsubscribe=One-Click&lt;br&gt;
List-Unsubscribe: &lt;a href="https://app.yourdomain.com/unsubscribe?email=user@gmail.com"&gt;https://app.yourdomain.com/unsubscribe?email=user@gmail.com&lt;/a&gt;&lt;br&gt;
Remember to replace it with actual values.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Compliance through NotificationAPI
&lt;/h2&gt;

&lt;p&gt;NotificationAPI provides the one-click unsubscribe option at no cost without writing a single line of code. Our account setup process also ensures your emails comply with SPF, DKIM, DMARC, and DMARC Alignment.&lt;/p&gt;

&lt;p&gt;So, all NotificationAPI users are compliant without additional effort.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Let us know what you think
&lt;/h2&gt;

&lt;p&gt;Do you have any questions or did we miss anything? Ping us on our &lt;a href="https://www.notificationapi.com/contact"&gt;contact page&lt;/a&gt;, and we'll send you some goodies for your contribution!&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://support.google.com/a/answer/81126?hl=en"&gt;High-Level Google Requirements&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://support.google.com/a/answer/10032169?sjid=2442999713009550434-NC"&gt;More on DMARC from Google&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Serverless Notification Service Design in AWS - with diagrams</title>
      <dc:creator>Sahand Seifi</dc:creator>
      <pubDate>Mon, 17 Oct 2022 14:12:42 +0000</pubDate>
      <link>https://dev.to/notificationapi/serverless-notification-service-design-in-aws-with-diagrams-5h42</link>
      <guid>https://dev.to/notificationapi/serverless-notification-service-design-in-aws-with-diagrams-5h42</guid>
      <description>&lt;h2&gt;
  
  
  Background and Motivation
&lt;/h2&gt;

&lt;p&gt;We discussed why some software development teams consider an internal or external notification service in our &lt;a href="https://www.notificationapi.com/blog/ultimate-guide-on-notification-services"&gt;Ultimate Guide to Notification Services&lt;/a&gt;, including reasons such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Complexity of notifications (number of channels, number of notifications) demanding a service-oriented approach&lt;/li&gt;
&lt;li&gt;Reliability and scalability&lt;/li&gt;
&lt;li&gt;Creating internal tools for observability and monitoring&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We also proposed a generic &lt;a href="https://www.notificationapi.com/blog/notification-service-design-with-architectural-diagrams"&gt;Notification Service Design&lt;/a&gt; compatible with any cloud provider, with critical technical constraints and business requirements. This article proposes a Serverless design for a notification microservice with AWS services, given the same objectives mentioned in the previous article.&lt;/p&gt;

&lt;h2&gt;
  
  
  High-Level Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tp82gs5Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hndfpup6i9edza1mbyyx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tp82gs5Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hndfpup6i9edza1mbyyx.png" alt="High Level Serverless Notification Service Design" width="880" height="987"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step-by-Step Architecture:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. POST /send
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The /send end-point is a Lambda function with AWS's new &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html"&gt;Function URL&lt;/a&gt; capability.&lt;/li&gt;
&lt;li&gt;The Function URL authorizes the incoming requests based on the IAM_ROLE of the caller. This allows you to skip API Gateway or write any authorization code. So, for example:

&lt;ul&gt;
&lt;li&gt;Your code runs on EC2 &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html"&gt;with a specific IAM Role&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/urls-auth.html"&gt;modify the policy on your EC2 role &lt;/a&gt;to allow invoking the /send end-point from your code&lt;/li&gt;
&lt;li&gt;When making an API call to /send from your code, you follow this article &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html"&gt;to sign your requests&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;The request to this end-point contains the userId of the user. This allows the service that sends the notification has no knowledge of your user's attributes.&lt;/li&gt;
&lt;li&gt;The request also contains a notificationId, which indicates the type of notification, such as alert or new_customer.&lt;/li&gt;
&lt;li&gt;The request to this end-point also contains all the channels the service wishes to send. These channels will get filtered in the next step based on user preferences.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Match Notification Preferences
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A DynamoDB stores records that indicate whether user should receive a specific notification on a specific channel. Record structure: KEY: user_id:notification_id, VALUE: [{channel: "email", state: true}, {channel: "sms", state: false}]‍&lt;/li&gt;
&lt;li&gt;If the send end-point reads a "false" value from the records, it will ignore that channel. If a record for a channel does not exist, it means the user has not explicitly set their preferences. In this case, you need to agree to a default.&lt;/li&gt;
&lt;li&gt;Notice how we allow users to update the data in this table directly. How does this work? You can allow your front-end to directly update records in a DynamoDB with &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/specifying-conditions.html"&gt;Fine-Grained IAM Policy for DynamoDB&lt;/a&gt;. For example, you only allow users to update records if the KEY contains their userId.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Get User Attributes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The /send end-point read the user's email address, phone number, ... from the Cognito User Pool.&lt;/li&gt;
&lt;li&gt;Notice that you can only make Cognito's getUser() request &lt;a href="https://docs.aws.amazon.com/cognito/latest/developerguide/limits.html"&gt;120 times per second&lt;/a&gt;. If you wish to send at higher scales, you may store this information in a DynamoDB.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Publish to Fanout
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The /send end-point forms a message similar to the image above (top-right) and sends it to SNS, only containing channels that the user is subscribed to.&lt;/li&gt;
&lt;li&gt;The SNS is configured to fanout this message to multiple queues.&lt;/li&gt;
&lt;li&gt;However, SNS is configured to filter destinations based on the list of channels in the message.
Example:

&lt;ul&gt;
&lt;li&gt;The caller requests sending a notification using email and SMS&lt;/li&gt;
&lt;li&gt;The /send end-point decides that the user is not subscribed to SMS using the DynamoDB, so it only includes the email data in the SNS message&lt;/li&gt;
&lt;li&gt;SNS looks at the channels in the message and only duplicates the message to the email queue&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Fanout to Job Processors
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The messages go into SQS queues until they are processed.&lt;/li&gt;
&lt;li&gt;You can configure complicated or straightforward failure and retry mechanisms at this stage.&lt;/li&gt;
&lt;li&gt;We recommend setting the retry to 1. We also recommend setting up a DLQ with a 24-hour time-to-live (TTL) window. It will hold onto failed messages to reroute them later when issues are resolved.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. Process Delivery Jobs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;These are simple Lambda functions that take the message from the queue and send it to the appropriate service. For example, the email sender lambda would read the message and send it to SendGrid or a similar service.&lt;/li&gt;
&lt;li&gt;You can limit the number of concurrent lambdas to avoid sending too many emails or SMS and getting throttled.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Further Improvements
&lt;/h2&gt;

&lt;p&gt;Here are a few things that are possible but we haven't covered. If you need any of these capabilities, read the next section.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In-App Notifications: They are complex. They require tables, APIs, and UIs&lt;/li&gt;
&lt;li&gt;Centralizing the notification UI elements and providing a visual editor on it&lt;/li&gt;
&lt;li&gt;Feature flags for notifications&lt;/li&gt;
&lt;li&gt;Monitoring and reporting&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  An external Notification-as-a-Service
&lt;/h2&gt;

&lt;p&gt;Building an internal notification service is a lot of (annoying) work. We know because we have built this a few times in our careers.&lt;/p&gt;

&lt;p&gt;That is why we made &lt;a href="https://www.notificationapi.com"&gt;NotificationAPI&lt;/a&gt;: a plug-and-play notification-as-a-service solution. It takes 10 minutes to configure and integrate and gives you much more functionality, including in-app notifications, feature flags, and logs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If I had to describe NotificationAPI in one word, it would be simple!&lt;br&gt;
-- Jacob Brown, Software Team Lead&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://www.notificationapi.com/blog/customer-interview-adopting-a-notification-service-at-milk-moovement"&gt;Watch Jacob's interview&lt;/a&gt;, discussing how they implemented their own notifications, then switch to NotificationAPI.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Notification Service Design - with diagrams</title>
      <dc:creator>Sahand Seifi</dc:creator>
      <pubDate>Mon, 09 May 2022 14:38:12 +0000</pubDate>
      <link>https://dev.to/notificationapi/notification-service-design-with-diagrams-2c77</link>
      <guid>https://dev.to/notificationapi/notification-service-design-with-diagrams-2c77</guid>
      <description>&lt;p&gt;In our &lt;a href="https://www.notificationapi.com/blog/ultimate-guide-on-notification-services" rel="noopener noreferrer"&gt;Ultimate Guide on Notification Services&lt;/a&gt;, we discussed if and when you should build a Notification Service. This article proposes a notification system architecture that you can use as your in-house notification system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;Notifications are a common culprit for code smells, technical debt, and endless HTML/CSS templates lying around your code-base. They usually end up with no tests, no oversight or ownership, and cause pains such as repeated notifications or banned email accounts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objective
&lt;/h2&gt;

&lt;p&gt;To design a notification service that can send product-to-user notifications across many channels at scale&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Send API: Expose an authenticated end-point so we can trigger sending notifications from any back-end and microservice&lt;/li&gt;
&lt;li&gt;Supported Channels: Support sending notifications to any channel that exposes an API, e.g., Email, SMS, Push&lt;/li&gt;
&lt;li&gt;User Preferences: Allow users to pick their user preferences on each notification and channel&lt;/li&gt;
&lt;li&gt;Respecting downstream service limits: Avoid getting throttled or suspended by your email or SMS service&lt;/li&gt;
&lt;li&gt;Scalable: Allow horizontal scaling for (theoretically) unlimited scaling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  High-Level Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9dct0i72n6xpugwlauf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9dct0i72n6xpugwlauf.png" alt="Notification Service Architecture Diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  A Quick Overview
&lt;/h2&gt;

&lt;p&gt;Let's imagine that your code should send a notification. The numbers below correspond with the numbers you see on the diagram.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your code calls the POST /send endpoint. The request contains the userId of the recipient, the type of the notification, and the contents of the notification for every supported channel.&lt;/li&gt;
&lt;li&gt;The /send end-point authenticates the request using &lt;a href="https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow" rel="noopener noreferrer"&gt;OAuth2's Client Credentials Flow&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;It then requests the user's notification preferences from the database. The preferences indicate whether the user is subscribed to a particular notification and channel or not.&lt;/li&gt;
&lt;li&gt;It will then read the user attributes such as email address or phone number from the database.&lt;/li&gt;
&lt;li&gt;This end-point will form a message object containing user attributes from step (4) along with the channels and content for each channel. However, it will exclude disabled channels based on step (3). Finally, the message is sent to a fan out service.&lt;/li&gt;
&lt;li&gt;The fanout service is configured to broadcast incoming messages to job queues. However, there is filtering in place to ignore job queues related to channels that are not listed inside the message.&lt;/li&gt;
&lt;li&gt;There is a job queue and processor per channel. The processor picks up the job and requests the appropriate service, e.g., a transactional email or SMS service.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Architecture Decisions:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  POST /sent
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You notice that the request to this end-point only contains the userId and not the email or phone number. This allows the services that send notifications have no knowledge of your users.&lt;/li&gt;
&lt;li&gt;The end-point is behind a load balancer to ensure scalability.&lt;/li&gt;
&lt;li&gt;The end-point is not protected with your regular user-facing authentication. Since the service that makes the request is a "program" itself, you need to use a different authentication mechanism known as the OAuth2 Client Credentials Flow used for server-to-server communication. Here are links to how to do this in &lt;a href="https://auth0.com/docs/get-started/architecture-scenarios/server-application-api" rel="noopener noreferrer"&gt;Auth0&lt;/a&gt; and &lt;a href="https://lobster1234.github.io/2018/05/31/server-to-server-auth-with-amazon-cognito/" rel="noopener noreferrer"&gt;Cognito&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;Do we need a whole end-point for this?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;There will be many parts of your application that will be issuing notifications. Implementing the send function as an end-point behind a load-balancer ensures that it is independently scalable and allows you to use it from virtually anywhere, e.g., from a new codebase or your build pipeline.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h3&gt;
  
  
  User Preferences
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use a highly scalable NoSQL or key/value pair database. Structure the records as: KEY: &lt;/li&gt;
&lt;li&gt;sample_user_id:sample_notification_id, VALUE: [{channel: "email", state: true}, {channel: "sms", state: false}]‍&lt;/li&gt;
&lt;li&gt;When the send end-point sees "false" values in the records, it will remove the related channel from the message sent to the fanout. If a record for a channel does not exist, it means the user has not explicitly set their preferences. In this case, you need to agree to a default.&lt;/li&gt;
&lt;li&gt;The information in the user_preferences table is updated by the user through your UI, through a normal end-point protected by your common authentication mechanisms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;Why do we need user preferences?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Not allowing users to control their notification preferences will only frustrate them and force them to mark your notifications as spam or mute your notifications. This will further damage your user experience and mark your account for suspension by email or SMS delivery services.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h3&gt;
  
  
  Fan Out
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Fanout takes a message and duplicates it to various places. They are cheap and highly scalable. In AWS, use SNS. In Google Cloud Platform, use Pub/Sub, and in Azure, use topics and subscriptions.&lt;/li&gt;
&lt;li&gt;You can configure filtering between the fanout and job queues to avoid sending unnecessary messages to job queues of channels that have been excluded. For example, in AWS SNS, you can specify that the email job queue should only receive the fanout message if the message contains the "email" property inside the "channels" property.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;Why do we need a fanout?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;You could write code that puts the same message into the necessary job queues, but fanout is cheaper, and writing less code is good. Another benefit of fanout is being able to easily add/remove queues, thus allowing you to refactor and extend your channels.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h3&gt;
  
  
  Job Processing
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Queues hold on to messages until your job processors process them. They are also cheap and highly scalable. Job processors are code that takes messages from the job queues and processes them. They can scale based on the number of messages in the queue.&lt;/li&gt;
&lt;li&gt;In our case, the job processor should make an API call to the appropriate service to send out the notification through a transactional email service.&lt;/li&gt;
&lt;li&gt;Most email, SMS, or similar delivery services have strict guidelines on the amount and quality of messages you send. You should also carefully review these and put proper systems in place. Here is &lt;a href="https://www.notificationapi.com/blog/how-to-prevent-aws-ses-review-and-suspension" rel="noopener noreferrer"&gt;our guide on how to prevent getting suspended on AWS SES&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;You can configure a max number of job processors to avoid hitting the rate limits of the delivery services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;Why do we need job queues and processors?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;‍Multiple reasons: A) External delivery services are generally slow. The queue mechanism allows you to process these dead jobs asynchronously from the rest of your code. B) The queue mechanism allows you to control the rate of your jobs, thus avoiding getting throttled. C) These external services could face outages. A job queue mechanism lets you decide what to do in cases of job failure without a single line of code, e.g., retry the job every 30 minutes for a maximum of 3 times.&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Improvements
&lt;/h2&gt;

&lt;p&gt;Here are a few things that are possible but we haven't covered. If you need any of these capabilities, read the next section.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The architecture of a scalable in-app notification service - they require their own APIs, tables, etc., so they deserve their own article&lt;/li&gt;
&lt;li&gt;Removing notification contents from the code and instead allowing your product and design team to edit the notifications visually without code change&lt;/li&gt;
&lt;li&gt;Dashboard for your team to enable/disable notifications or specific channels without code changes&lt;/li&gt;
&lt;li&gt;Collecting and displaying open/click report &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  A Quicker Approach
&lt;/h2&gt;

&lt;p&gt;There is so much work that goes into building a scalable notification service. That is precisely why we made &lt;a href="https://www.notificationapi.com" rel="noopener noreferrer"&gt;NotificationAPI&lt;/a&gt;: a plug-and-play notification-as-a-service solution. It takes 5 minutes to set up. It is scalable and has every feature you can imagine for your notifications, such as a dashboard for your team to design and configure notifications visually without developer involvement.&lt;br&gt;
‍&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;At its core, all engineering comes down to making tradeoffs between the perfect and the workable.&lt;br&gt;
-- Katie Hafner&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, we learned about the architecture of a scalable notification service. We used tools available in all the major cloud providers so that you can build your notifications based on this. Alternatively, you also learned of a notification-as-a-service product that could save you all the trouble. Software engineering, like any other engineering discipline, comes down to trade-offs. Perhaps the decision tree and table in our &lt;a href="https://www.notificationapi.com/blog/ultimate-guide-on-notification-services" rel="noopener noreferrer"&gt;ultimate guide on notification services&lt;/a&gt; can help you figure out what trade-offs you make.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>systems</category>
      <category>serverless</category>
      <category>microservices</category>
    </item>
  </channel>
</rss>
