Scaling Signaling with Rooms and Redis
Learn to scale a WebRTC signaling server horizontally using room-based message routing and a Redis pub/sub adapter so peers on different server instances can still connect.
Scaling Signaling with Rooms and Redis is a free Real-Time Streaming Systems (WebRTC + Live Data) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Real-Time Streaming Systems (WebRTC + Live Data) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
One Server Is Not Enough
You have built, deployed, and tested a signaling server. As users grow, a single instance becomes a bottleneck. This lesson covers scaling signaling horizontally across multiple instances using rooms and Redis.
The Room Concept
Signaling messages should only reach the right peers. A room groups the participants of one call so offers, answers, and ICE candidates are routed only to members of that room.
Joining a Room
When a client connects, it joins a room identified by a call id. The server tracks which sockets belong to which room.
io.on('connection', (socket) => {
socket.on('join', (roomId) => {
socket.join(roomId);
socket.to(roomId).emit('peer-joined', socket.id);
});
});Routing Within a Room
Signaling messages are relayed only to other members of the sender's room, never broadcast to everyone.
socket.on('signal', ({ roomId, data }) => {
socket.to(roomId).emit('signal', { from: socket.id, data });
});The Multi-Instance Problem
With several server instances behind a load balancer, two peers in the same call may connect to different instances. Instance A does not know about a room member on instance B, so signaling fails.
Pub/Sub to the Rescue
A shared Redis pub/sub layer lets instances forward messages to each other. When instance A emits to a room, Redis publishes it so instance B delivers it to its local members.
Adding the Redis Adapter
Socket.IO offers a Redis adapter that handles cross-instance routing transparently, so your room code stays unchanged.
const { createAdapter } = require('@socket.io/redis-adapter');
const { createClient } = require('redis');
const pub = createClient({ url: 'redis://localhost:6379' });
const sub = pub.duplicate();
await Promise.all([pub.connect(), sub.connect()]);
io.adapter(createAdapter(pub, sub));Sticky Sessions
For long-lived WebSocket connections, configure the load balancer for sticky sessions so a client stays on one instance for the life of its connection, avoiding handshake breakage.
Tracking Presence
Store room membership in Redis so any instance can answer who is in a call and clean up when a client disconnects.
socket.on('join', async (roomId) => {
await pub.sAdd('room:' + roomId, socket.id);
});
socket.on('disconnect', async () => {
// remove from all rooms it belonged to
});Handling Disconnects
Notify remaining peers when someone leaves so they can tear down the corresponding peer connection cleanly.
socket.on('disconnect', () => {
socket.rooms.forEach((roomId) => {
socket.to(roomId).emit('peer-left', socket.id);
});
});Scaling Strategy Summary
To scale signaling: group peers into rooms, run multiple stateless instances, connect them with a Redis adapter, enable sticky sessions, and track presence in Redis. The signaling layer then grows horizontally while calls keep connecting.
Quick Check
Test your understanding of scaling signaling.
Recap
You learned to scale signaling:
- Rooms route messages only to call participants
- Multiple instances need a Redis pub/sub adapter to share rooms
- Sticky sessions keep WebSocket connections stable
- Presence tracking and disconnect handling keep state consistent
This architecture supports many concurrent calls reliably.
Frequently asked questions
Is the “Scaling Signaling with Rooms and Redis” lesson free?
Yes — the full text of “Scaling Signaling with Rooms and Redis” is free to read here on the web, and the Real-Time Streaming Systems (WebRTC + Live Data) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Real-Time Streaming Systems (WebRTC + Live Data) course, upgrade to CoddyKit PRO.
What will I learn in “Scaling Signaling with Rooms and Redis”?
Learn to scale a WebRTC signaling server horizontally using room-based message routing and a Redis pub/sub adapter so peers on different server instances can still connect. You practise Real-Time Streaming Systems (WebRTC + Live Data) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Real-Time Streaming Systems (WebRTC + Live Data)?
No prior experience is required. Real-Time Streaming Systems (WebRTC + Live Data) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Scaling Signaling with Rooms and Redis” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Real-Time Streaming Systems (WebRTC + Live Data) lesson?
Yes. Every Real-Time Streaming Systems (WebRTC + Live Data) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Choosing a Backend for Signaling
- Implementing Signaling Logic
- Deploying and Testing Signaling
- Scaling Signaling with Rooms and Redis