How to design a scalable notification system?
Posted
by
Trent
on Programmers
See other posts from Programmers
or by Trent
Published on 2012-12-01T13:22:57Z
Indexed on
2012/12/01
17:16 UTC
Read the original article
Hit count: 441
I need to write a notification system manager.
Here is my requirements:
I need to be able to send a Notification on different platforms, which may be totally different (for exemple, I need to be able to send either an SMS or an E-mail).
Sometimes the notification may be the same for all recipients for a given platform, but sometimes it may be a notification per recipients (or several) per platform.
Each notification can contain platform specific payload (for exemple an MMS can contains a sound or an image).
The system need to be scalable, I need to be able to send a very large amount of notification without crashing either the application or the server.
It is a two step process, first a customer may type a message and choose a platform to send to, and the notification(s) should be created to be processed either real-time either later.
Then the system needs to send the notification to the platform provider.
For now, I end up with some though but I don't know how scalable it will be or if it is a good design.
I've though of the following objects (in a pseudo language):
a generic Notification
object:
class Notification {
String $message;
Payload $payload;
Collection<Recipient> $recipients;
}
The problem with the following objects is what if I've 1.000.000 recipients ? Even if the Recipient
object is very small, it'll take too much memory.
I could also create one Notification per recipient, but some platform providers requires me to send it in batch, meaning I need to define one Notification with several Recipients.
Each created notification could be stored in a persistent storage like a DB or Redis.
Would it be a good it to aggregate this later to make sure it is scalable?
On the second step, I need to process this notification.
But how could I distinguish the notification to the right platform provider?
Should I use an object like MMSNotification
extending an abstract Notification
? or something like Notification.setType('MMS')
?
To allow to process a lot of notification at the same time, I think a messaging queue system like RabbitMQ may be the right tool. Is it?
It would allow me to queue a lot of notification and have several worker to pop notification and process them. But what if I need to batch the recipients as seen above?
Then I imagine a NotificationProcessor
object for which I could I add NotificationHandler
each NotificationHandler
would be in charge to connect the platform provider and perform notification.
I can also use an EventManager
to allow pluggable behavior.
Any feedbacks or ideas?
Thanks for giving your time.
Note: I'm used to work in PHP and it is likely the language of my choice.
© Programmers or respective owner