Marvin jude
Sep 23 · 3 min read

Recently, I tried socket.io so I decided to share my thoughts while comparing it with PubNub.

Photo by Veri Ivanova on Unsplash

It’s quite normal to get confused about what technology to use for a project especially when the technologies are functionally equivalent. Understanding the strength and weakness of one tech in relation to the other may help you make better decisions.

I’ve used PubNub in a number of projects, One is a slim WhatsApp group clone that I recently open-sourced. Yeah, it’s one of those fun projects take a look. The code is available on Github.

WhatsApp group clone with PubNub

Let’s dive right into the key differences between these technologies!

PubNub, Socket.io

PubNub provides realtime messaging-as-a-service. This means you’ll never have to manage your own server to do real-time stuff in your application. They also provide APIs for more specific use-cases like chats. It’s quite easy to get started with PubNub, you just need to sign up, grab the SDK and plug it into your code. With PubNub you can send a message (PUBLISH) as large as 32KB to any client application sitting anywhere in the world within 1/4 of a second, but usually much faster (30–40ms). The network has multiple points of presence on every inhabited continent, allowing messages to be sent using the shortest network path, for the lowest latency.

PubNub is already built for scale, you don’t need to worry about load balancing or creating a resiliency layer with Redis, your message is guaranteed to get delivered as fast as possible no matter where the sender/receiver is in the world! It also sparks joy that an increase in your customer base wouldn't lead to failure or increased latency since PubNub is actually built for this. PubNub Removes the need for a server back-end so you can focus on building your apps.

Socket.io is a NodeJS library that powers real-time applications. It’s also fairly easy to get started with socket.io only that the publish/subscribe model from PubNub stuck better with me 😜. Socket.io also has a client library that would be needed to connect to the server (since you’ll be managing one). Socket.IO allows you to emit and receive custom events. It has reserved events like connect, message, disconnect, reconnect, ping, join and leave which are all internally controlled.

With socket.io you’ll have set up a NodeJS server, install socket.io, handle load balancing to make sure your application is ready to scale. Generally, you’ll have to do a lot of orchestration, especially in a multitenant space. And hey you just have to make sure you’re doing things the right way.

Code Sample

For demonstration, I built a very simple group chat app with each these technologies. You will need to sign for PubNub and add your API keys for the PubNub example to work :)

PubNub group chat example

here is the socket.io example

Socket.io client

The socket.io server

Summarily

  • It’s quite easier to manage users in a multitenant space with PubNub.
  • PubNub is already built for scale, just write your code and forget about servers. Think about PubNub as real-time without the server clusters.
  • PubNub zero-in-on more specific use-cases that you may not find in socket.io.

Thanks for reading!

Charisol Community

A renegade techies hub for sharing lessons, struggles and stories of the African tech world to the global audience

Marvin jude

Written by

Software Engineer. React • JavaScript • Full-stack @PubNub Ambassador #Always bet on Javascript,

Charisol Community

A renegade techies hub for sharing lessons, struggles and stories of the African tech world to the global audience

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade