通知系统概念(Notification System Concepts)
一、通知渠道
-
Email(电子邮件) 提供方:SendGrid、Mailgun、AWS SES、Postmark。 使用场景:事务性通知(收据、密码重置)、营销(简报、促销)、系统告警(安全、账单)。 注意事项:送达率(SPF、DKIM、DMARC);退信处理;退订管理;模板渲染。
-
SMS(短信) 提供方:Twilio、Vonage、AWS SNS、MessageBird。 使用场景:2FA/OTP 验证码、订单更新、预约提醒、紧急告警。 注意事项:字符限制(160 GSM-7,70 Unicode);送达回执;选择加入/退出(TCPA 合规);每条消息成本。
-
Push Notifications(推送通知) 平台:FCM(Firebase Cloud Messaging,Android/Web)、APNS(Apple Push Notification Service,iOS)、Web Push(PWA)。 使用场景:实时更新、重新召回用户、突发新闻、聊天消息。 注意事项:设备 token 管理;静默与可见通知;角标计数;操作按钮。
-
In-App Notifications(应用内通知) 类型:Toast/snackbar(瞬时)、Banner(持续至关闭)、Badge(图标上的计数)、Feed(通知中心)。 使用场景:功能公告、活动更新、社交互动、系统消息。
二、通知架构
资料给出如下结构示意:
┌──────────────┐ │ Application │ └──────┬───────┘ ↓ ┌──────────────────────────────────┐ │ Notification Service │ │ ┌────────────────────────────┐ │ │ │ Channel Router │ │ │ └────────────────────────────┘ │ │ ↓ ↓ ↓ │ │ ┌────────┐ ┌────────┐ ┌────────┐│ │ │ Email │ │ SMS │ │ Push ││ │ │Provider│ │Provider│ │Provider││ │ └────────┘ └────────┘ └────────┘│ └──────────────────────────────────┘ ↓ ↓ ↓ Mailgun Twilio FCM
三、通知数据模型
Notification 字段: id: UUID userId: string type: enum(transactional、marketing、system) channel: enum(email、sms、push、in_app) template: string data: JSON(模板变量) status: enum(pending、sent、delivered、failed、read) scheduledAt: timestamp(null 表示立即) sentAt: timestamp deliveredAt: timestamp readAt: timestamp metadata: JSON
Template 字段: id: string channel: enum subject: string(仅电子邮件) body: string(含占位符) locale: string
四、用户偏好
资料给出偏好示例 JSON,包含 userId、channels(email 的 enabled/address/verified;sms 的 enabled/number/verified;push 的 enabled/tokens 列表,含 platform 与 token)、preferences(marketing、orderUpdates、securityAlerts,以及 quietHours 的 enabled、start、end、timezone)。示例值:user-123,邮箱 user@example.com,号码 +1234567890,iOS/Android token 示例 xxx/yyy,时区 America/New_York。
五、投递策略
-
基于优先级的路由 Critical(安全告警):1. Push(立即)2. SMS(回退)3. Email(总是) Transactional(订单更新):1. 若有则 Push 2. Email 总是 Marketing:1. 仅 Email 2. 遵循用户偏好
-
批量 Individual:立即发送——密码重置、OTP 验证码。 Batched:聚合后发送——社交通知(“5 人赞了你的帖子”)、活动摘要。 Scheduled:在最佳时间发送——营销活动、每周摘要。
六、追踪与分析
需追踪的指标:发送率(尝试)、送达率(确认)、打开率(email/push)、点击率(链接)、退信率(email)、退订率、退出率。 事件:notification.created、notification.sent、notification.delivered、notification.opened、notification.clicked、notification.bounced、notification.failed。
七、最佳实践
内容: ✅ 清晰、可操作的标题 ✅ 个性化(姓名、上下文) ✅ 移动端友好的格式 ✅ 退订链接(电子邮件) ❌ 误导性标题 ❌ 过度频繁 ❌ 未经同意发送
技术: ✅ 幂等发送 ✅ 带退避的重试 ✅ 按用户限流 ✅ 模板版本化 ❌ 硬编码内容 ❌ 同步发送 ❌ 忽略退信
八、相关技能
notifications-spring:Spring Boot 通知实现 apigen-architecture:整体系统架构