Design pattern : notification system

Create a system queue, each message added to this queue has a list of “consumers” and the content. The main message pump processes each message and sends the message to all consumers.

Lets say 2 people befriend each other. You add a message to the main system queue that A is friends with B and consumers are both A and B. When your message “pump” (processor) sees this message it adds it to the queue of A and the queue of B. So now user A and user B have a new message that they are friends. In turn each user has a message processor, so when it sees a message called “I am friends with [someone]” it processes this as add a new entry to the “wall” visible to friends of A that “A is friends with B”, etc.

This is overly simplistic but hopefully shows how message queues can be used for this (very similar system is used as the windows UI framework) so there is already an existing example and there are plenty of synchonized message queue patterns you can use.

Rest is up to you to design.

Leave a Comment