当前位置: 首页 > news >正文

CHAPTER 10: DESIGN A NOTIFICATION SYSTEM

Step 1 - Understand the problem and establish design scope

Candidate: What types of notifications does the system support?
Interviewer: Push notification, SMS message, and email.
Candidate: Is it a real-time system?
Interviewer: Let us say it is a soft real-time system. We want a user to receive notifications as soon as possible. However, if the system is under a high workload, a slight delay is acceptable.
Candidate: What are the supported devices?
Interviewer: iOS devices, android devices, and laptop/desktop.
Candidate: What triggers notifications?
Interviewer: Notifications can be triggered by client applications. They can also be
scheduled on the server-side.
Candidate: Will users be able to opt-out?
Interviewer: Yes, users who choose to opt-out will no longer receive notifications.
Candidate: How many notifications are sent out each day?
Interviewer: 10 million mobile push notifications, 1 million SMS messages, and 5 million emails.

Step 2 - Propose high-level design and get buy-in

• Different types of notifications
• Contact info gathering flow
• Notification sending/receiving flow

Different types of notifications

在这里插入图片描述
Android push notification
在这里插入图片描述
SMS message
在这里插入图片描述
Email
在这里插入图片描述
在这里插入图片描述

Contact info gathering flow

在这里插入图片描述
在这里插入图片描述

Notification sending/receiving flow

在这里插入图片描述
Three problems are identified in this design:
• Single point of failure (SPOF): A single notification server means SPOF.
• Hard to scale: The notification system handles everything related to push notifications in one server. It is challenging to scale databases, caches, and different notification
processing components independently.
• Performance bottleneck: Processing and sending notifications can be resource intensive.
For example, constructing HTML pages and waiting for responses from third party
services could take time. Handling everything in one system can result in the system
overload, especially during peak hours.

High-level design (improved)

• Move the database and cache out of the notification server.
• Add more notification servers and set up automatic horizontal scaling.
• Introduce message queues to decouple the system components.
在这里插入图片描述

Step 3 - Design deep dive

Reliability

How to prevent data loss?
persists notification data in a database and implements a retry mechanism.
在这里插入图片描述
Will recipients receive a notification exactly once?

Although notification is delivered exactly once most of the time, the distributed nature could result in duplicate notifications.

we introduce a dedupe mechanism and handle each failure case carefully.

When a notification event first arrives, we check if it is seen before by checking the event ID. If it is seen before, it is discarded.

Additional components and considerations

Notification template
Notification setting
Before any notification is sent to a user, we first check if a user is opted-in to receive this type of notification.

Rate limiting
Retry mechanism
Security in push notifications
Monitor queued notifications

A key metric to monitor is the total number of queued notifications. If the number is large, the notification events are not processed fast enough by workers. To avoid delay in the notification delivery, more workers are needed.

Events tracking
在这里插入图片描述

Updated design

在这里插入图片描述

Step 4 - Wrap up

Besides the high-level design, we dug deep into more components and optimizations.
• Reliability: We proposed a robust retry mechanism to minimize the failure rate.
• Security: AppKey/appSecret pair is used to ensure only verified clients can send
notifications.
• Tracking and monitoring: These are implemented in any stage of a notification flow to
capture important stats.
• Respect user settings: Users may opt-out of receiving notifications. Our system checks
user settings first before sending notifications.
• Rate limiting: Users will appreciate a frequency capping on the number of notifications
they receive.

相关文章:

  • C/C++统计满足条件的4位数个数 2023年5月电子学会青少年软件编程(C/C++)等级考试一级真题答案解析
  • python装13的一些写法
  • flume安装及实战
  • 数据库选型参考
  • 数据分享|R语言生态学种群空间点格局分析:聚类泊松点过程对植物、蚂蚁巢穴分布数据可视化...
  • 【Linux】Linux环境基础开发工具使用
  • 多线程带来的的风险-线程安全
  • MySQL集群高可用架构之MMM
  • 设计模式-代理模式
  • 【python爬虫】—星巴克产品
  • 【C语言】指针经典笔试题(上)
  • [Linux入门]---git命令行的基本使用
  • pytorch生成CAM热力图-单张图像
  • Python实现简单的爬虫功能
  • CListCtrl设置只显示单列
  • RabbitMQ配置文件_修改RabbitMQ MQTT的1883端口
  • OJ练习第180题——颠倒二进制位
  • 我的创作纪念日
  • 多维时序 | MATLAB实现WOA-CNN-GRU-Attention多变量时间序列预测(SE注意力机制)
  • 怎么实现一个登录时需要输入验证码的功能
  • 五一假期首日,多地党政主官暗访督查节日安全和值班值守工作
  • 民营经济促进法出台,自今年5月20日起施行
  • 人民日报:在大有可为的时代大有作为
  • 顺利撤离空间站,神十九乘组踏上回家之旅
  • 中国人保聘任田耕为副总裁,此前为工行浙江省分行行长
  • 呼伦贝尔市委常委、组织部长闫轶圣调任内蒙古交通集团党委副书记