title: Chat / System Communication App (Nodejs + RabbitMQ)
body: <p>So i currently have a chat system running NodeJS that passes messages via rabbit and each connected user has their own unique queue that subscribed and only listening to messages (for only them). The backend can also use this chat pipeline to communicate other system messages like notifications/friend requests and other user event driven information.</p>
  
  <p>Currently the backend would have to loop and publish each message 1 by 1 per user even if the payload of the message is the same for let's say 1000 users. I would like to get away from that and be able to send the same message to multiple different users but not <strong>EVERY</strong> user who's connected. </p>
  
  <p>(example : notifying certain users their friend has come online).</p>
  
  <p>I considered implementing a rabbit queue system where all messages are pooled into the same queue and instead of rabbit sending all user queues node takes these messages and emit's the message to the appropriate user via socket connections (to whoever is online).</p>
  
  <p><a href="http://i.stack.imgur.com/2Gl9C.jpg" rel="nofollow">Proposed - infrastructure</a></p>
  
  <p>This way the backend does not need to loop for 100s and 1000s of users and can send a single payload containing all users this message should go to. I do plan to cluster the nodejs servers together.</p>
  
  <p>I was also wondering since ive never done this in a production environment, will i need to track each socketID.</p>
  
  <p>Potential pitfalls i've identified so far:</p>
  
  <ul>
  <li>slower since 1000s of messages can pile up in a single queue.</li>
  <li>manually storing socket IDs to manually trasmit to users.</li>
  <li>offloading routing to NodeJS instead of RabbitMQ</li>
  </ul>
  
  <p>Has anyone done anything like this before? If so, what are your recommendations. Is it better to scale with user unique queues, or pool all grouped messages for all users into smaller (but larger pools) of queues.</p>