Sub topic 1
Clarifying requirements and scope
Every design starts with a question: what must this system do, and how well? A notification system looks simple. A service receives an event and sends a message. The hard parts only show up once you pin down volume, latency, channels, and failure behavior. This chapter covers how to turn a vague request into a short, testable list of requirements before you draw any boxes.
Prerequisites
This chapter assumes you have the following background:
- A basic understanding of client-server and HTTP APIs.
- Familiarity with databases and key-value stores.
- Basic knowledge of message queues and asynchronous processing.
- Enough Python to read short snippets.
You do not need to know any notification provider yet. Later chapters cover providers, queues, and retries in detail.
Why requirements come first
"Build a notification system" can mean many things. A team that sends a weekly email digest needs a very different system from a team that sends one-time passwords by SMS during login. The first system can tolerate delays of hours. The second fails if a code arrives after 30 seconds.
If you skip this step, you tend to make one of two mistakes:
- You over-build, adding multi-region queues and priority lanes for a system that sends 500 messages a day.
- You under-build, using a synchronous call to a provider inside a checkout request, which then fails whenever the provider is slow.
Requirements give you a way to judge each later decision. When you reach retries, rate limits, or storage, you can ask whether the choice serves a stated requirement.
Scoping the system
Start by deciding what is in the system and what is not. A useful boundary is this: the notification system takes an event that says "something happened that a user may care about" and delivers a message to that user through the right channels. It does not decide that the event happened.
The following table shows a common split.
| Concern | Inside the notification system | Outside it |
|---|---|---|
| Receiving events from producers | Yes | The producer decides when to emit an event |
| Choosing channels and honoring preferences | Yes | |
| Rendering message text from templates | Yes | |
| Calling push, SMS, and email providers | Yes | The providers run the actual delivery networks |
| Tracking delivery status | Yes | |
| Business rules such as "an order shipped" | No | Owned by the order service |
| Marketing campaign planning and audience selection | Usually no | Owned by a campaign tool |
Marketing campaigns are the most common scope dispute. Bulk campaigns send millions of messages with relaxed timing. Transactional messages send fewer, time-sensitive messages. Supporting both changes the design, so decide early and write the answer down.
Functional requirements
Functional requirements describe what the system does. For a notification system, ask these questions and record the answers.
- Which channels? Push, SMS, email, in-app, or a subset. The next chapter compares them.
- Who are the senders? Internal services only, or also external API clients.
- Who are the recipients? Individual users, groups, or segments.
- What controls do users get? Per-type and per-channel opt-outs, quiet hours, and language choice.
- Is scheduling needed? Messages sent now versus at a future time.
- Is content templated? Plain text from the producer versus managed templates with localization.
- What feedback is required? Whether the producer needs to know if a message was delivered, opened, or failed.
A first version might state it like this: "Internal services submit events for individual users. The system delivers push, email, SMS, and in-app messages, honors per-type channel preferences and quiet hours, and records delivery status."
Notice what this statement leaves out. It does not mention segments, A/B testing, or analytics dashboards. Naming exclusions is part of scoping. You can list them under a "not in scope for now" heading so nobody assumes they are included.
Non-functional requirements
Non-functional requirements describe how well the system behaves. They drive most of the architecture, so make them specific. A number is testable. "Fast" is not.
| Quality | Weak statement | Testable statement |
|---|---|---|
| Latency | "Messages should be quick" | Critical messages are handed to a provider within 5 seconds of the event at the 99th percentile |
| Throughput | "Handle lots of traffic" | Sustain 10,000 events per second, with bursts to 50,000 for 5 minutes |
| Availability | "Highly available" | The ingestion API accepts events 99.95% of the time |
| Delivery guarantee | "Don't lose messages" | No accepted event is lost once acknowledged |
| Duplicates | "No duplicates" | At most one send per event, user, and channel under normal operation |
| Freshness | "Not too late" | A one-time passcode is dropped if it cannot be sent within 2 minutes |
Several of these deserve a closer look.
Delivery guarantees
A distributed system can usually promise one of two things. At-most-once delivery never duplicates a message but may lose one. At-least-once delivery never loses a message but may send it twice. Exactly-once delivery across a network and a third-party provider is not something you can fully guarantee, because a provider can accept a request and then time out before you see the response.
Most notification systems choose at-least-once and then reduce duplicates with idempotency keys, which a later chapter covers. Losing a password reset message is worse than occasionally sending a shipping notice twice.
Latency is not the same for every message
A single latency target hides important differences. A security alert and a weekly digest do not deserve the same treatment. Define classes of priority early, for example critical, normal, and bulk, and assign a target to each. This sets up the prioritization chapter.
Freshness
Some messages become useless or harmful if late. A "your driver is arriving" push sent 20 minutes after arrival confuses the user. Decide, per message type, whether the system should drop an expired message or still send it. A time-to-live field on the event supports this.
Estimating scale
Rough numbers shape the design, and a quick estimate is enough. Suppose the product has 10 million daily active users, and each receives an average of 5 notifications per day.
daily_active_users = 10_000_000
notifications_per_user_per_day = 5
seconds_per_day = 24 * 60 * 60
per_day = daily_active_users * notifications_per_user_per_day
average_per_second = per_day / seconds_per_day
peak_factor = 10 # assumption: peak traffic is 10x the average
peak_per_second = average_per_second * peak_factor
print(f"per day: {per_day:,}")
print(f"average per second: {average_per_second:,.0f}")
print(f"peak per second: {peak_per_second:,.0f}")This prints about 50 million messages per day, 579 per second on average, and 5,787 per second at peak. The peak factor is an assumption you should replace with measured data. Notification traffic is bursty. A flash sale, a breaking news alert, or a midnight scheduled job can create a spike far above the average.
The estimate also shows where the pressure lands. A few thousand sends per second is modest for queues but can exceed what a provider accepts from a single account, so rate limiting becomes a real concern.
Constraints that shape the design
Some limits come from outside your control. Capture them as requirements too.
- Provider limits. Push services, SMS carriers, and email providers cap request rates and may throttle you.
- Cost. SMS costs money per message, while push is nearly free. Cost is a reason to prefer cheaper channels when a user has several enabled.
- Regulation. Consent rules for marketing messages and data residency rules affect what you store and when you may send.
- Existing infrastructure. If the company already runs a message broker and a key-value store, reusing them is often better than introducing new ones.
Turning answers into a requirements record
Keep the result short and structured so it can be reviewed. The following snippet shows one way to hold the decisions as data, which also makes later checks easy to automate.
requirements = {
"channels": ["push", "email", "sms", "in_app"],
"priorities": {
"critical": {"target_seconds": 5, "ttl_seconds": 120},
"normal": {"target_seconds": 60, "ttl_seconds": 3600},
"bulk": {"target_seconds": 3600, "ttl_seconds": 86400},
},
"delivery": "at_least_once",
"peak_events_per_second": 6000,
"out_of_scope": ["campaign audience selection", "A/B testing"],
}
for name, rule in requirements["priorities"].items():
print(f"{name}: send within {rule['target_seconds']}s, drop after {rule['ttl_seconds']}s")The record is small, but it forces decisions. Each later chapter returns to it: channels, queues, retries, and rate limits all trace back to a line here.
Common mistakes
- Treating all messages the same. A single queue and a single retry policy for OTP codes and newsletters will fail one of them.
- Ignoring user control. Adding opt-outs after launch is harder than designing for them. Preferences affect routing from the start.
- Promising exactly-once. State at-least-once and plan for duplicates.
- Leaving scope open. Without a written exclusion list, requests such as campaigns and analytics keep arriving.
- Skipping the estimate. Without numbers you cannot tell whether one worker or one hundred is needed.
How requirements connect to the rest of the design
The diagram below shows how the requirement areas feed the decisions in later chapters.
Exercises
Exercise
A team says its notification system must be "reliable and fast." Rewrite this as two testable non-functional requirements for a one-time passcode message, and name the delivery guarantee you would choose.
Show answer
Example: "99% of passcode messages are handed to the provider within 5 seconds of the event" (latency), and "a passcode that cannot be sent within 2 minutes is dropped" (freshness). Choose at-least-once delivery so a passcode is not lost, and use idempotency keys to limit duplicates. Other reasonable numbers are fine if they have a unit and can be measured.
Exercise
A service sends 2 million notifications per day. Assuming a peak factor of 10, what is the approximate peak rate per second, and why is the peak factor more useful than the average for sizing the system?
Show answer
The average is 2,000,000 / 86,400, about 23 per second, so the peak is about 230 per second. Capacity must handle the peak, not the average, because notification traffic is bursty. A system sized for the average would queue up or fail during spikes such as sales or alerts.