Realtime notifications – Pusher

Recent webapps keep pushing into realtime notifications, starting from web chat (for example Facebook Chat), notifications of new items (Twitter), progress status update (for example encoding a file).

The first solution was to provide an ajax poll; which can’t scale easily (a bad implementation could lead to your app to a DDoS) and will have a delay between updates.

On the server side are starting a lot of libraries/servers to provide a solution for this. The great news is WebSockets will be the standard and solution for the realtime notification from browser and server side. The bad news is that WebSockets is changing a lot and is not yet stable across major browsers (Firefox, Safari and Chrome implements it, but different versions)

A good approach has been cloud implementations which removes all the problems of programming and maintaining server resources for this task.

So far I’ve tested two implementations: Beaconpush (which I liked for fast implementation and low message sending, but now it’s planned to close in following months and only allow installed setups) and Pusher

Pusher.com is really a great solution to realtime notifications. The team is very responsive and want to help you all times.

I will detail some advantages and some main problems you could face if you need to make a choice.

Advantages:

  • Cheap, specially if you are going to send a lot of messages
  • Easy to implement in server and client side
  • Uses websockets available in most browsers (it uses the recently Mozilla implementation for example and never had a problem of connection in different versions of Safari/Chrome)
  • Has auth mechanisms which allows to secure your messages (In Beaconpush it was easy to eavesdrop if you don’t hide the user id)
  • Has presence channels which mean you can know the other users in channel without handling at server side
  • You can store data when user is authorized (for example html parsed data) so you can use to render/store in your client side
  • Webhooks which let you know when the channel is empty or occupied (logged/offline if you use an “user channel”)

Disvantages

  • Not sure if they really limit user connections, because if you have a large site with few notifications you could easily hit limits of user connections (I see really low those limits)
  • All is channels, you don’t handle user id, even the solution is easy if you create “user channels” (private channels only for user id and handle authorization)
  • They don’t have api for batch sending a message to multiple channels
  • From server side you cannot get list of users logged in a channel (even will be hard to find as you don’t have user id param, you need to match with a socket_id they provide)
  • Webhooks are great for ajax pages, but won’t work “out of the box” if your user browses several pages as will be get a lot of notifications of user login/logout (they have a solution for client side, but server side you need to implement your own solution)
  • In my dev setup if I left the normal settings I got a delay on connection up to 10 seconds; if I force to use secure sockets worked faster and fine:
    new Pusher(applicationKey, {encrypted: true});

I really think Pusher is a great solution from small to medium sites; since it will allow to make a faster development and realtime notifications have a very good impact on your application.

 

 

Share
  • Tt

    111