Socket.IO Redis Adapter

Scale Socket.IO across multiple server instances by broadcasting events through Redis

Library
npm
v8.3.0
2,767 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
53 /100 Fair
Development Activity 12
Maintenance 20
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 80
Code Quality 82
Innovation 65
Learning Curve 78

@socket.io/redis-adapter is the official Socket.IO adapter that lets a single logical Socket.IO deployment span multiple Node.js server processes. By default, Socket.IO can only broadcast events to sockets connected to the same process; this adapter uses Redis Pub/Sub (or Redis’s newer sharded Pub/Sub for cluster mode) to relay emit() calls, room management, and acknowledgements across every server node, so clients connected to different instances still see each other’s real-time events.

It supports both the redis and ioredis client packages, standalone Redis and Redis Cluster topologies, and — since Socket.IO 4.1+ — inter-server communication features like broadcast acknowledgements and remote socket management. The README includes an explicit security notice: Redis Pub/Sub traffic is unauthenticated and unencrypted by the adapter itself, so Redis must be treated as trusted internal infrastructure, not exposed to untrusted networks.

What You Get

  • createAdapter(pubClient, subClient) for the standard Pub/Sub-based adapter, compatible with both redis and ioredis clients
  • createShardedAdapter() for Redis 7.0+ sharded Pub/Sub, designed to scale Pub/Sub usage in Redis Cluster deployments
  • Support for Redis Cluster topologies via createCluster/Cluster client configuration on either side
  • Inter-server broadcast acknowledgements and remote socket management (since adapter 7.0.0 / Socket.IO 4.1.0+)
  • Configurable options (key/channelPrefix, requestsTimeout, subscriptionMode) for tuning channel naming and cross-node request behavior

Common Use Cases

  • Horizontally scaling a Socket.IO-based real-time application across multiple Node.js server processes or containers
  • Running a chat or notification system behind a load balancer where clients may land on different backend instances
  • Coordinating room membership and presence across a multi-node Socket.IO deployment during rolling deploys or autoscaling
  • Migrating a growing Socket.IO app from a single-process deployment to a horizontally scaled architecture without changing application-level event code

Under The Hood

Architecture - The core implementation in lib/index.ts (~950 lines) extends Socket.IO’s base Adapter class, overriding broadcast, room-management, and acknowledgement methods to additionally publish serialized packets to Redis channels and process incoming messages from subscribed channels on other nodes. lib/sharded-adapter.ts implements a parallel adapter built on Redis’s sharded Pub/Sub (SSUBSCRIBE/SPUBLISH) introduced in Redis 7.0, which distributes Pub/Sub load across cluster shards instead of a single channel. lib/util.ts centralizes packet encoding/decoding shared by both adapters.

Tech Stack - Written entirely in TypeScript, published with compiled type declarations, and designed to work with either of the two dominant Node.js Redis clients (redis and ioredis) rather than bundling its own — the adapter only needs a pub/sub-capable client instance passed in.

Code Quality - Tests under test/ (index.ts, specifics.ts, custom-parser.ts, util.ts) run against a real Redis instance provisioned via the included docker-compose.yml, exercising actual pub/sub behavior rather than mocked Redis calls — an appropriate choice given how state- and timing-sensitive cross-node broadcast logic is. A compatibility table in the README explicitly maps adapter major versions to supported Socket.IO server versions, showing deliberate attention to avoiding breaking changes for existing deployments.

API Design - Integration is a single line — pass createAdapter(pubClient, subClient) (or createShardedAdapter) into the Socket.IO Server constructor’s adapter option — with all further usage identical to single-process Socket.IO code, so application logic doesn’t need to change when scaling out. The explicit security notice in the README about treating Redis as trusted infrastructure is a notable, responsible piece of documentation often missing from comparable adapters.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers