Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Why is traditional HTTP poorly suited for building a real-time multiplayer game or a live chat application?
💻 Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Real Time Chat with WebSockets pipeline. Include the setup and basic execution steps.
You are reviewing a Real Time Chat with WebSockets pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Broadcasting with io.emit() to every connected client instead of scoping to a Room
// Wrong: every connected user across every chat receives this
io.emit('new_message', data);
// Correct: only sockets in this specific room receive it
socket.join(chatId);
io.to(chatId).emit('new_message', data);The Solution //
io.emit() sends a message to literally every socket connected to the server, regardless of which chat or game session they're in. Without joining and targeting Rooms, a message meant for one conversation leaks to unrelated users — use socket.join(roomId) and io.to(roomId).emit() to scope broadcasts correctly.
The Error //
Running Socket.io across multiple server instances without the Redis adapter
// Wrong: works locally, breaks silently once you add a second server
const io = new Server(httpServer);
// Correct: adapter lets multiple instances share pub/sub events
const { createAdapter } = require('@socket.io/redis-adapter');
io.adapter(createAdapter(pubClient, subClient));The Solution //
Socket.io keeps each connected socket's state in the memory of the specific server process it connected to. When you scale horizontally (multiple Node instances behind a load balancer), User A on Server 1 and User B on Server 2 cannot see each other's broadcasts because io.emit() only reaches sockets known to that one process — you must wire up the Redis (or another) adapter so servers can relay events to each other.