Real-Time Architecture

Since there are a lot of projects that require real-time functionality we have selected relevant technologies that help us implement real-time features. Rails/Django are not the best tools for this kind of job so for real-time features if project requirements allow us to use 3rd party services we use Firebase. If project requirements specify not to use 3rd party services we implement real-time features using Node.js. In rare cases when Node.js doesn’t fit well we look for other alternatives (Elixir for example).

Firebase

Firebase provides a variety of services like Cloud Messaging, Realtime database, Storage, Hosting, Crash Reporting, Notifications, App Indexing, Dynamic Links, AdWords. For real-time related functionality, we use Cloud Messaging and Realtime database. Firebase Realtime database is a NoSQL database which is synced across all clients in real-time. It provides web, iOS, and Android clients. Firebase provides offline support out of the box because Firebase Realtime Database SDK persists data to client device storage. Once connectivity is reestablished, the client device receives any changes it missed and synchronizes those changes with the current server state.

Node.js

Socket.io is currently the most popular Node.js library for real-time solutions. It is based on Engine.io that implements a WebSocket-like API. Socket.io provides a Redis adapter for scaling to multiple nodes. It also provides various fallbacks: XHR long polling, JSONP, etc. Socket.io has iOS, Android, and web clients.

If Socket.io is not suitable for a particular project there are other Node.js libraries:

  • uWebSockets - one of the most lightweight, efficient & scalable WebSocket & HTTP server implementations available.
  • ws - simple to use, blazing fast, and thoroughly tested WebSocket client and server implementation.