Mohammed Al Ashaal
alash3al
Published in
2 min readFeb 9, 2018

--

Building a real-time service like pusher from scratch

Everyone knows pusher the real-time messaging service, the concept behind it is very very useful as you can use that concept to build a real-time chatting, notifications, ... etc.

I was maintaining a web service that has a near real-time approach based on ajax and long-poll, at some point of time I was forced to convert it to WebSocket based without touching any code, so I created a tool that works like a reverse proxy, it accepts WebSocket connection and it will poll the back-end each x of seconds, so the client just uses one WebSocket connection, but under the hood the polling logic itself moved to another layer.

After that, I developed that tool for my own usage and called it wsify.

I rebuilt it from scratch to let it to expose any redis channel to any websocket client, in another words, allowing browsers, mobile phones, ... etc to listen on any redis channel.

But there was an issue which is related to the authorization, because I don't want to let anyone listen on any channel except for certain users, so I improved the tool to add web-hooks support into it, so when someone wants to connect,subscribe and even subscribe from a channel the web-hook get notified and respond with HTTP status code 200 OK which means “Yes you are allowed”, and anything else means “Sorry, you aren’t allowed to do that action”, also when someone disconnects from a channel, the web-hook get notified.

With that approach, you can build your own business login in any programming language you prefer, i.e, you can create the logic of who is online/offline without the need of any external API.

All of that is call wsify it is a tiny websocket server with built-in support for pub/sub for building any type of real-time apps, it could be found at: https://github.com/alash3al/wsify

Hope this tool will help you, and if you have any recommendation just open an issue there.

--

--

Mohammed Al Ashaal
alash3al

A problem solver, who doesn’t learn tools, but just learn concepts.