Notifications
POST /notifications
req :
{
userId,
template{
type,
verison
}
variables[],
scheduledTime?,
idempotentKey
}
POST /notifications/bulk - max 100 per batch
req:
{
users[],
template{
type,
verison
}
variables[],
scheduledTime?
}
GET /notifications/{id}/status
User Device token
POST /users/{id}/device - create device and add token
PUT /users/{id}/device/{id} - use for updating device status/remove device
PUT /device/{id}/token - update token
Acts as the entry point for all client requests.
Responsibilities:
Distributes traffic across multiple instances of all services to improve scalability and availability.
Notification Service
Responsibilities
Email/SMS/Push Queue
Email/SMS worker
Push Worker
Scheduler
Device Service
Devide DB/TempalteDb/NoticaitonDB/User PrefrecnesDB
I would use a hybrid approach. Notification delivery data is high-volume and mostly key-value access, so I would use NoSQL like Cassandra for user preferences, device tokens, notification requests, and notifications. For template managemen which is admin managed and where versioning and consistency matter, I would use SQL like PostreSQL.
UserPreferecnes
userId
notificaitonType
sms
push
Device
deviceId
userId
devideToken
status -> Active/InActive
NotificationRequest
-------------------
requestId
clientId
idempotencyKey
type (SINGLE/BULK)
status -> Accepted, processing, completed, failed
scheduledTime?
createdAt
Notification
notificationId
notificationrequestId
userId
noticiaotnType
channel
status -> Pending, sent, failed
createdAt
Template
id
notificationType
content
channel
status
version
now we will deep dive into this topics
Kafka acts as durable event broker giving at-least once delivery gurantee.
Registering Device
Updating TOken
FLOW:
user installs app -> Generate/Update device token -> App -> Device service -> Device DB
-> For bulk,
-> The main differnce is our service is not respoinbile for fanning out to millions of user in just one request, for eg: A yotube channel posted a video -> notified all of its subsciber which could be millions,
-> Our serviec wont handle this mainly because, for that to happen, our service will then need to know the relationships/data of clients, so its better cleints coem up with strategies for batch procesisng and use our bulk endpoint for that.
For scheduled
Failure Handling
Consumer/Worker failer ->
Duplicate processing
Provider failure -> retries with expotential backoff
Scalability
The system scales horizontally by partitioning Kafka topics, using stateless channel workers, sharding high-volume notification storage by userId/time, and autoscaling workers based on queue depth.