dimanche 22 janvier 2023

What design pattern to use for Notification Service?

I am designing a notification system for a e-commerce website. Here is the use-case:

The notification service receives a request to send notification to user and seller. The gateway queue request for notification and returns to caller to do other works. The Notification can be of two types,

  1. Email Notification
  2. Push Notification

Each of these two types have a field, Vendor(it can be Seller or User). Vendor type is used to set the priority of the notification.

The logic to consume from queue is quite clear to me. I have completed that part along with model classes for Email and Push notification.

The logic to create these notifications and pushing them to queue is confusing to me. Basically, at upper layer(Publisher), Notification can be of two types, either User or Seller. Both of these will have Email and Push notification. I can simply create two classes, one for seller and one for user and add two members, for Email and push.

Although this might work, the design seems pretty stiff to me. What if we have another requirement where we have to send both these notification to Project Manager too? What if We need to add some new Notification, like phone text. It will be hard to refactor.

Is there any way to make the publisher side flexible to changes like this? What design patterns should I use?

Aucun commentaire:

Enregistrer un commentaire