I'm currently on the process of creating a website/webapp.

My application is based on Node JS with the express framework.

My core backend concept consists of

  • routers: handle http request. Like [POST] /api/team
  • controllers: business logic behind routers
  • model: interface between database and controller

I'm not sure if this follows any best practice patterns as MVC. It started as a very small personal project with business logic in routers. At some point I had to refractor my app (especially considering DRY) so I added controllers.

So let's say one can create an team with his account. The router will validate the request (user is authenticated, has permissions, ...) and forward the task to the controller. The controller will validate the form data, create a new database entry and return the new entry. The router will render the template and respond the request.

I think so far everything should be pretty straight forward.

Now the team is created and the user can invite other users to his team. Pretty much the same procedure as before.

Now we come to my actual question.
The invited user gets an notification. Currently I create notifications at the same place as I call the model to create a new entry for the invite.

I don't like that notifications after at the same place. Notifications are a side effect and just decrease readability of the actual task.

So my idea was to use events. The team controller should emit an event when someone got invited.

The event handler will create the actual notification. But in my current concept there is no component which would fit the role of handling the event in my opinion.
The notification controller could listen for events on the team controller. But this could end in ring-dependencies (the current example is not the best example for this situation).

So my question is: WHO should listen for events and complete side tasks?

1 Answer 1


This is typically the responsability of an event bus or command bus. You would raise events from somewhere within your application and hand these off to a command bus. The bus then resolves the appropriate event handlers or command handlers for the event that was raised and hands the event off for processing.

You can implement this in a number of different ways. Some application write events to an event store (which can be a simple database table) and have an asynchronously running component handle these events by polling the event store at an interval to check if new events are present and handle those. This can also be synchronous: the events are only kept in-memory and at the end of an operation or a number of operations the events are handled. For a web application, you could have a handler that runs as the very last operation in every request handle events.

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.