samedi 16 mars 2019

Pub-Sub Design Pattern

I've got two projects: one of them is a multi-processor project and the second is a single processor. Both of them are written in Node JS.

In addition, I'm using three systems - which are: Loggly, Mixpanel, e-Mail system. There are some events which are relevant to both projects - such as transaction of some products.

Once a transaction event happens - I need to do three main things: 1) Update Loggly about the transaction properties. 2) Update Mixpanel about the transaction properties. 3) Update e-Mail system (for example - to send a confirmation mail about the transaction).

The data is sent by JSON format.

In addition, some of the events are relevant for all three systems (Loggly, Mixpanel, eMail system), and some are relevant only for a part of them.

Each system is interested in a different part of the data. For example, some systems need all the data while others are using only a small part of the event's data.

The Question: Currently, in my project - once an event occurs - I'm sending directly the data from the two projects to the relevant systems. That means that my code is duplicate in 2 projects (and that's bad).

For example:

  // call when transaction event happens
    function foo(transactionData) {
      Loggly.send('Transaction', transactionData);
      Mixpanel.send('Transaction', transactionData);
    }

I'm looking for new architecture - which can solve the code duplication problem. What is the best architecture of doing this - combining Pub-Sub pattern and AWS tools?

What is the right way of doing this?

Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire