🎓 A1Learner
🔍
0 of 42 lessons completed

Design a Notification System: The Ask

A notification system is the service that tells a user something happened, like a new like or a password change. This lesson clarifies the ask, the first step of the interview method.

Which events trigger a notification

Each event on the list either triggers a notification or stays silent. The printout counts how many events trigger one.

events = [
    ("like", True),
    ("comment", True),
    ("profile view", False),
    ("password change", True),
    ("app open", False),
]

sent = 0
for name, triggers in events:
    if triggers:
        sent += 1
        print(name, "triggers a notification")
    else:
        print(name, "triggers nothing")
print(sent, "of", len(events), "events trigger a notification")

The channel split in a small batch

A batch of ten notifications follows the same channel split as the whole system. Push takes the largest share and text message the smallest.

batch = ["push"] * 7 + ["email"] * 2 + ["text message"] * 1

counts = {"push": 0, "email": 0, "text message": 0}
for channel in batch:
    counts[channel] += 1

for channel in ["push", "email", "text message"]:
    print(channel, counts[channel], "of", len(batch))

What delivered can honestly mean

A notification passes through stages on its way to the user. The system can confirm the early stages but not the final appearance on the device.

stages = ["queued", "handed to the provider", "shown on the device"]
confirmed = ["queued", "handed to the provider"]

for stage in stages:
    if stage in confirmed:
        print(stage, "- the system can confirm this")
    else:
        print(stage, "- the system cannot confirm this")
print("the honest promise stops at:", confirmed[-1])

Example

preferences = {
    "Ana": {"push": True, "email": True, "text message": False},
    "Ben": {"push": False, "email": True, "text message": False},
    "Cy": {"push": False, "email": False, "text message": False},
}
order = ["push", "email", "text message"]

for user in ["Ana", "Ben", "Cy"]:
    chosen = "none - opted out of every channel"
    for channel in order:
        if preferences[user][channel]:
            chosen = channel
            break
    print("like event for", user, "->", chosen)

Key points

  • Notification channels: the routes a notification can travel, which are push notification, email and text message.
  • Trigger: the event that causes a notification, like a like, a comment or a password change.
  • Preferences: the channels a user has switched on or off for each kind of event.
  • Opt-out: a user choice that stops a kind of notification completely.
  • Delivered: a word that honestly means the message was handed to the provider, not that it appeared on the device.
  • Scale: the system sends 200,000,000 notifications a day, which is 2,315 per second on average.
  • Channel split: push carries 140,000,000 a day, email carries 40,000,000 and text message carries 20,000,000.

In this example, one like event reaches three users and each user's preferences pick the channel. Ana gets a push notification, Ben gets an email, and Cy gets nothing after opting out of every channel.

Note

a good clarification names what the system will not promise, not only what it will.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which question belongs to clarifying a notification system?