0

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.

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.

When the web server application receives an HTTP chat message, it maps which clients the message goes to and publishes the message to those specific clients' channels. So a loop with a call to PubNub.publish(client_channel_id, the_message).

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).

(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 may (with local caching) have to check in Redis first to map the message's destination channel...)

Potential Problems

  • 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?

Can you see any other potential problems with this design? Other comments?

Craig Conover
  • 4,710
  • 34
  • 59
Wayne Bloss
  • 5,370
  • 7
  • 50
  • 81

1 Answers1

0

The method you described here is good for creating a chat application securely. I recommend creating a randomly generated channel each user session in order to provide additional security rather than using a channel such as user_id_1234. Each time a user log's in, generate a new channel name such as: YTM0NZomIzI2OTsmIzM0NTueYQ and have the authenticated user connect to that channel. So in Redis, you will have a simple key/value associated with the user object. Perhaps an HKEY with Key field pubnub_channel which updates every new session ID. http://redis.io/commands/hset

Stephen Blum
  • 6,498
  • 2
  • 34
  • 46