Blog

How to Add a Notification System to your MVP

Troy GoodeTroy GoodeJuly 01, 2021
how-to-create-notifications-for-mvp-header

At the MVP stage, you're finding product-market fit. That means trying functionality that might create value, and spending less time on each experiment than the one before, until something works.

Notifications usually end up in that mix, because they're how users learn that something in your product needs them while they're away from it. The system that sends them at this stage should be small enough to build quickly and shaped so it can grow when the product does.

The main components of a notification system

Here's the architecture of a simple notification system:

mvp-stage notification system

Architecture diagram for a simple notification system.

It's functionally limited, but it has the components that let it extend to future use cases: a set of notification triggers, one central place for all notification decision logic, a simple templating system, and connections to providers.

The code below implements each part in Node.js. It starts on the right of the diagram, where the components are most specific, and works left, where they get more abstract.

Sending email through an email API

Sending an email through an email API takes three steps: connect to the provider with its JavaScript SDK, build the message with the parameters it requires, and send it.

This example uses Amazon SES as the email provider. You'd get a similar result with another provider.

Install the SES client from the AWS SDK for JavaScript v3 (it needs Node.js 20 or later):

Terminal
npm install @aws-sdk/client-ses

Then use it to send an email through SES:

JavaScript
// notify.js
const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses");

const ses = new SESClient({ region: "us-east-2" });

async function notify_email(subject, message, email_address) {
  const { MessageId } = await ses.send(
    new SendEmailCommand({
      Destination: { ToAddresses: [email_address] },
      Message: {
        Body: { Text: { Charset: "UTF-8", Data: message } },
        Subject: { Charset: "UTF-8", Data: subject },
      },
      Source: "patrician@disc.world",
    })
  );
  console.log("SES message ID:", MessageId);
  return MessageId;
}

This sends a text-only email and skips the HTML version. The source address is hard-coded, on the assumption that every email comes from the same sender on your side. You can change any of these assumptions as the product grows.

Message templates

You can send emails now, but handcrafting every email at each place in the codebase that triggers a notification won't scale.

Message templates let you parameterize your notifications with user data. Here's a simple templating "system":

JavaScript
// notify.js
function template_activity(channel, props) {
  switch (channel) {
    case "email":
      return `Hello ${props.first_name}, there's an interesting post you can check out here:

https://disc.world/activity`;
  }
}

Once your notifications get more complex, you can move from template literals to a templating library like mustache.js.

This example has one template. Templates for HTML email, push notifications, or chat notifications can follow in the same function.

Notification decision logic

With sending and templates in place, you need to decide whether to notify a user about a given event. The simplest approach is a function that switches on the notification type:

JavaScript
// notify.js
async function maybe_notify(event, props) {
  switch (event) {
    case "activity":
      // todo: check notification preferences
      // todo: check unsubscribe list
      console.log("Sending activity notification to user:", props.id);
      return notify_email(
        "Something interesting on the Discworld!",
        template_activity("email", props),
        props.email_address
      );
  }
}

The function picks the template and channel for the notification type, and logs a line so you can debug issues later.

You won't always want to notify someone about new activity, so the TODOs mark where preference and unsubscribe checks go.

Notification trigger

Finally, wire everything together and send an activity notification:

JavaScript
// notify.js
maybe_notify("activity", {
  id: 123,
  email_address: "rincewind@disc.world",
  first_name: "Rincewind",
}).catch((err) => {
  console.error("Notification failed:", err);
  process.exitCode = 1;
});

Here the function is called directly in the same file. If notifications get triggered from several services, this call would come over an HTTP or RPC API instead.

Running the example

Configure your AWS credentials and verify the sender address in SES. A new SES account starts in the sandbox, where you can only send to verified addresses, so verify the recipient too while you test. Then run the script:

Terminal
node notify.js
Text
Sending activity notification to user: 123
SES message ID: 010f017a15621a86-ac305fa4-919a-4178-8362-7faf64e10cc8-000000

The resulting email shows up in your email client:

email example

The resulting email in our email client.

It's a very simple system that's quick to set up, and it still has the components you'll build on when your MVP moves to the next stage.

What should you leave out of an MVP-stage notification system?

With an MVP-stage system, the goal is notifications that work well enough for everyone involved, without spending more time on them than they're worth.

That doesn't mean skimping on error handling and unit tests. Keep the amount of functionality small and the quality high: follow best practices and test every code path.

Features to exclude from an MVP

To decide which features go into an MVP-stage notification system, think about what you're trying to achieve with the MVP.

You've likely defined one or more metrics for the MVP's success (if you haven't, consider doing so). For a new product, say you're measuring daily active users.

How do notifications tie into daily usage? If you build a good-enough notification system, how will it help you hit that goal?

In this example, a notification is how your users learn about something that needs their attention. If they haven't signed in on a given day, a notification is the only way to tell them about the activity they missed. In that scenario, you could reasonably credit notifications with a direct increase in daily active users (DAUs).

How you build your notifications affects their impact on DAUs. Going from zero notification channels to one (for example, email) can make a real difference to your MVP metrics.

Would adding a second channel (for example, mobile push) make enough of a difference?

That depends. If your app relies on real-time interaction, a push notification on the user's phone does more than an email they might read later.

If you're building a B2B application where synchronous action matters less, email alone will probably do.

Here are a few features to consider leaving out of an MVP if they don't directly drive its metrics:

  • Additional notification channels.
  • Additional types of notifications.
  • Non-essential efficiency and performance improvements.

What you shouldn't skip even in an MVP system

Even once you've settled on the functionality that's critical to your MVP's success, a few things apply to any MVP-stage system, whatever you're building:

Item 1: Polished experience for a limited set of notifications. Typos in your templates, call-to-action buttons that don't work, and email designs that break on mobile all affect how your early users feel about the product. You'll have a limited number of channels, so the ones you pick should contribute to a good experience. Spend some time testing the look and feel of your MVP notifications, manually, with automated tests, or both.

Item 2: Right notification, at the right time. You're building notifications to alert users to an event that merits their attention. Getting the mechanics right matters most when you only have one or a few channels. Document the logic for when a notification should and shouldn't be sent, and keep that logic consistent across your application.

Item 3: Reliability and consistency. Few things are more frustrating than notifications that arrive inconsistently. If your MVP system skips even 10% of the notifications it should send, your users miss interactions and decide your notifications "don't work," then disable or ignore them. Trust with early users is critical, so add monitoring to your notification system. You need to find issues before they cause damage.

Common gotchas when building MVP notification systems

By now you've hopefully settled on the functionality for your MVP notification system. Here are a few pitfalls to avoid when you build a basic notification system.

Shortcuts taken now can be painful in the future

Some shortcuts make sense in the MVP phase, like supporting fewer channels at first. Still, consider how today's choices affect what's possible for your product later.

For example, modeling all your notifications around one email API makes it harder to switch email providers or add SMS later.

Define your own schema for what a notification object looks like. That layer of abstraction makes it easier to add other notification types later.

Remember that you're serving multiple categories of users

Your customers aren't the only people using your notification system. You're a user of it too, and if it keeps breaking, your team loses time to it.

Your content editors and marketing team will want to change individual notifications and tweak the copy. They might not have the technical know-how to edit the codebase and open pull requests.

When you build an MVP system, think about what the notification experience looks like for every group, internal and external. It doesn't need to be perfect for each group (and probably can't be, in an MVP), but if you're prioritizing one group over another, make that choice explicit and talk it through with your team.

You won't go far without deliverability

A notification that isn't delivered doesn't do its job or move your metrics. Operational issues with your notification system can hurt deliverability, but there are other factors too.

For email, authenticate your sending domain with SPF and DKIM, and publish a DMARC record. Gmail, Yahoo, and Outlook require all three, with an aligned From domain, from anyone sending more than 5,000 messages a day to their users, and every sender needs at least SPF or DKIM. Email sender requirements covers the full set of rules.

For mobile push, a device being off or offline isn't the main risk. FCM stores a message and keeps trying to deliver it for up to four weeks by default, and APNs stores one notification per app for an offline device and delivers it when the device comes back online. The bigger risk is stale device tokens. When FCM returns UNREGISTERED or APNs returns 410, delete that token. Retry 429 and 5xx responses with exponential backoff (honor Retry-After when FCM sends it). Other errors mean the request needs fixing before a retry can work.

Quickly build an MVP-stage notification system with Courier

Building an MVP notification system from scratch doesn't need to be complicated. Think through the metrics you want notifications to drive, and which channels matter most to your internal and external users.

Courier covers the pieces you built above: templates you can edit without a deploy, one send call that routes to email, SMS, push, or chat with automatic provider failover (through Amazon SES or another provider you connect), user preferences checked at send time, and delivery logs with a status for every message. Here's the same activity notification as a Courier send, from an ES module (notify.mjs):

JavaScript
import Courier from "@trycourier/courier";

const courier = new Courier({ apiKey: process.env.COURIER_API_KEY });

const { requestId } = await courier.send.message({
  message: {
    to: { user_id: "123", email: "rincewind@disc.world" },
    template: "activity-notification",
    data: { first_name: "Rincewind" },
  },
});

console.log("Courier request ID:", requestId);

activity-notification is an alias you set in the template's settings, and the Design Studio template reads the name as {{data.first_name}}. Copy changes become template edits, and adding a channel becomes a routing change, so maybe_notify stays the same size.

The Developer plan includes 10,000 messages a month free. Send your first email walks through the setup, and if you've already built your own system, Migrate from an in-house system moves it over one notification type at a time.

Illustration by Rebekka Dunlap