Scaling real-time Node.js applications

Since our chat messages are being relayed via the server, clients can currently only communicate with other clients connected to the same server. This is a problem if we want to scale our application horizontally across many servers.

This is easy to fix, but tricky to demonstrate. To do so, we need to have two separate instances of our application running. This will be more realistic and more useful if they are also using the same shared databases for persistence. So we need to start up MongoDB and Redis, then start two instances of our application on different ports (so that they don't collide).

This means running all of the following commands (replacing the dbpath of MongoDB as appropriate for your setup): ...

Get Learning Node.js for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.