Skip to content
Ignacio Perales

Real-time with Socket.IO

I build real-time features with Socket.IO that keep working when the app runs on more than one instance.

At Eniax, real-time dashboards built on Socket.IO show analytics and KPIs to clients. On a private community video platform I co-own, a "who's watching" presence feature runs over Socket.IO with a Redis adapter, so it works across instances.

Where I've used it

Eniax

Health-tech company, Chile

Employer2022-06 → now

Clients follow their analytics and KPIs as the numbers change.

Built

  • Real-time dashboards over Socket.IO that show analytics and KPIs to clients.
  • Socket.IO

Private community video platform

Anonymized · no name or link

Own

Members watch videos on a platform that runs on more than one instance.

Built

  • A real-time "who's watching" presence feature over Socket.IO, using the Redis adapter so it works across instances.
  • Socket.IO
  • Redis
  • NestJS

Architecture

Dashboards. Clients follow their analytics and KPIs on dashboards that receive updates over Socket.IO instead of polling.

Presence. Members of the video platform see who is watching. The platform runs on more than one instance, so a member's socket may land on any of them. The Socket.IO Redis adapter relays events between instances, which keeps presence consistent no matter where each member is connected.

Eniax · Dashboards

    • Socket.IOpushes updates
    • Client dashboardsanalytics and KPIs

Video platform · Presence

    • Memberswho's watching
    • Instances with Socket.IONestJS
    • Redis adapterrelays events between instances
  • Service
  • Message broker
  • Several instances
  • External

Client dashboards receive analytics and KPI updates over Socket.IO instead of polling. On the video platform, a member's socket may land on any instance, and the Socket.IO Redis adapter relays events between instances so presence stays consistent.

Demo

Demo planned

Live presence on this page

See who else is reading this page right now, with a simulated fallback when the live server can't be reached.

Coming soonThis demo isn't built yet. The title and description above say what it will show.

Decisions & lessons

  1. Plan for more than one instance from the start. Socket.IO rooms are local to a process by default. The Redis adapter is what lets presence work across instances.
  2. Push, don't poll. For numbers that change while someone is looking at them, pushing updates over a socket is simpler for the client than asking again and again.

Stack

  • Socket.IO
  • Redis
  • NestJS