title: Chat with REST and PubNub push Architecture
body: <p>My main use case for a chat application is that one agent will typically talk to one guest. At most I am planning on supporting a low-single-digit number of guests and agents, but the use of such a feature would be very low. More importantly though, the sender would not need to receive their own message since HTTP status would confirm receipt of the message.</p>
  
  <p>I am considering using PubNub for "push only". So, each client would send messages to the application web server via a HTTP (PUT/POST) and only receive messages via it's own PubNub subscription channel.</p>
  
  <p>When the web server application receives an HTTP chat message, it maps <em>which clients</em> the message goes to and publishes the message to those <em>specific clients' channels</em>. So a loop with a call to <code>PubNub.publish(client_channel_id, the_message)</code>.</p>
  
  <p>This way, each client must only subscribe to one channel instead of multiple channels and every client only receives messages that are meant for it (i.e. no global channels and no filtering on the client).</p>
  
  <p>(I am also considering using Redis to hold the map of which clients are chatting in which rooms. So, every time the web app receives a chat message, it <em>may</em> (with local caching) have to check in Redis first to map the message's destination channel...)</p>
  
  <h3>Potential Problems</h3>
  
  <ul>
  <li>Using a single PubNub connection server-wide probably won't scale well. A pool of connections will probably work better. Since we're only broadcasting off these connections and not subscribing, it should be simple though, right?</li>
  </ul>
  
  <p>Can you see any other potential problems with this design? Other comments?</p>