-1

I am new to backend development and I was building a feature for my project where I can send notifications to various channels (for example slack).

I have a written notification class, which loads the service config from database and send the message.

The project I am building is managing users across various services (eq jira, github, vercel, sentry) from a common place

I am not sure how the best way to call this class.

For now let's say I have four notification events

  1. User is created
  2. User is deleted
  3. Integration is failing (ex token expired)
  4. Integration is connected

One way I was thinking was, that whenever create user api is called, after sending invites, I call this notification api and send message to slack (like simple function call).

but does anyone have any other suggestions besides this.

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Nov 25, 2023 at 19:27

1 Answer 1

1

I am new to backend development

Given that, I am going to suggest you start by following good design patterns. In this case the pattern you want is probably the "observer pattern" https://en.wikipedia.org/wiki/Observer_pattern

In that each of your notification channels are Observers they will all be registered with a single Subject you have a choice whether you define a single notify(event) method or multiple notify methods for each of the different event types you have. Try both options and evaluate for yourself what the pros and cons of each are.

There is more you could add to this, such as a queuing mechanism to decouple the event source from the notifications and an Inversion of Control framework to wire stuff up, however start out with good patterns and add to them as you need to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.