title: Pub-Sub Design Pattern
body: <p>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. </p>
  
  <p>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. </p>
  
  <p>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).</p>
  
  <p>The data is sent by JSON format.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>For example:</p>
  
  <pre><code>  // call when transaction event happens
      function foo(transactionData) {
        Loggly.send('Transaction', transactionData);
        Mixpanel.send('Transaction', transactionData);
      }
  </code></pre>
  
  <p>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?  </p>
  
  <p>What is the right way of doing this?</p>
  
  <p>Thanks for your help.</p>