Sub topic 1
Clarifying requirements and scope
A notification system looks simple until you try to size it. Before you draw any boxes, you need to agree on what the system must do and how well it must do it. This chapter covers that first step.
Prerequisites
This chapter assumes you know the following:
- Client-server basics and HTTP APIs.
- How databases and key-value stores differ.
- What a message queue is and why work is processed asynchronously.
- How to read short Python snippets.
Why requirements come first
"Send a message to a user" hides many decisions. Does the message go by push, SMS, email or in-app? Must it arrive in seconds or can it wait an hour? Is a duplicate acceptable? Each answer changes the design. If you skip this step, you will build the wrong thing, or build the right thing at the wrong scale.
Functional requirements
Functional requirements describe what the system does. For a notification system, a reasonable list is:
- Accept notification events from other services.
- Deliver through push, SMS, email and in-app channels.
- Honor each user's preferences, opt-outs and quiet hours.
- Fill message templates with event data, in the user's language.
- Track delivery status for each message.
The system should also say what it does not do. A good scope statement might exclude marketing campaign design, analytics dashboards and two-way chat. Writing exclusions down prevents scope creep.
Non-functional requirements
Non-functional requirements describe how well the system works. They drive most of the architecture.
| Requirement | Question to ask | Typical effect on design |
|---|---|---|
| Latency | How fast must urgent messages arrive? | Separate priority queues |
| Throughput | How many events per second at peak? | Horizontal workers, partitioned queues |
| Reliability | Can a message be lost? | Durable queues, retries |
| Duplicates | Is sending twice acceptable? | Idempotency keys |
| Availability | What if a provider is down? | Failure isolation, fallbacks |
| Compliance | Which consent rules apply? | Preference and audit storage |
Most teams choose at-least-once delivery. Messages are retried until they succeed, so a user may occasionally see a duplicate, and you add deduplication to reduce that. Exactly-once delivery across third-party providers is not realistic.
A worked estimate
Suppose the product has 10 million daily active users and sends 5 notifications per user per day.
daily_users = 10_000_000
per_user_per_day = 5
seconds_per_day = 86_400
peak_factor = 10 # peak load vs. average
daily_events = daily_users * per_user_per_day
average_rate = daily_events / seconds_per_day
peak_rate = average_rate * peak_factor
print(f"daily events: {daily_events:,}")
print(f"average rate: {average_rate:,.0f}/s")
print(f"peak rate: {peak_rate:,.0f}/s")This gives 50 million events per day, about 579 per second on average, and about 5,787 per second at peak. The peak number is the one to design for. A flash sale or breaking news can produce bursts far above the daily average.
Common mistakes
- Designing for average load instead of peak load.
- Treating all notifications as equal. A password reset code and a promotion have very different urgency.
- Ignoring user preferences until late, then having to retrofit them.
- Forgetting that providers fail, throttle and return errors.
Next step
With requirements fixed, the next chapter compares the channels, because each one has different cost, speed and reliability.
Exercise
A team says, "We need exactly-once delivery of every notification." Why is this a risky requirement, and what would you propose instead?
Show answer
Providers are external systems that can time out after accepting a message, so the sender cannot always know whether it was delivered. Guaranteeing exactly-once across that boundary is not realistic. Propose at-least-once delivery with retries, plus idempotency keys to suppress most duplicates.
Exercise
Using the worked estimate, what peak rate results if each user receives 8 notifications per day and the peak factor is 10?
Show answer
Daily events are 80,000,000. Dividing by 86,400 gives about 926 per second on average, so the peak is about 9,259 per second.