Should I use Socket.IO or PubNub

Marvin jude
Sep 23, 2019 · 3 min read

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

Image for post
Image for post
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.

Image for post
Image for post
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

Thanks for reading!

Charisol Community

A renegade techies hub for sharing lessons, struggles and…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store