Fernando Doglio
Sep 8, 2019 ⋅ 8 min read

Writing a working chat server in Node

Fernando Doglio Technical Manager at Globant. Author of books and maker of software things. Find me online at fdoglio.com.

Recent posts:

Using Defer In Angular 17 To Implement Lazy Loading

Using defer in Angular 17 to implement lazy loading

Angular’s new `defer` feature, introduced in Angular 17, can help us optimize the delivery of our apps to end users.

Lewis Cianci
Dec 4, 2023 ⋅ 10 min read

Using ElectricSQL to build a local-first application

ElectricSQL is a cool piece of software with immense potential. It gives developers the ability to build a true local-first application.

Rahul Padalkar
Dec 1, 2023 ⋅ 11 min read
Using Rust And Leptos To Build Beautiful Declarative User Interfaces

Using Rust and Leptos to build beautiful, declarative UIs

Leptos is an amazing Rust web frontend framework that makes it easier to build scalable, performant apps with beautiful, declarative UIs.

Eze Sunday
Nov 30, 2023 ⋅ 10 min read
5 Best JavaScript Multi-Dimensional Array Libraries

5 best JavaScript multidimensional array libraries

Learn more about the 5 best JavaScript libraries for dealing with multidimensional arrays, such as ndarray, math.js, and NumJs.

Pascal Akunne
Nov 30, 2023 ⋅ 4 min read
View all posts

3 Replies to "Writing a working chat server in Node"

  1. This is a nice breakdown of Socket chat servers. I’m currently doing something similar on a personal project. I also have events emitted when a user sends a friend request, accepts the request, etc.

    Do you recommend storing that Socket instance to user ID map in a service like Redis? I’m thinking of ways to scale up my current implementation.

  2. Hey O. Okeh, thanks for reading!
    In regards to your question, it depends. If what you’re looking for is scaling up to accommodate more users, you need more instances running. +
    I’m assuming you’ve created a dedicated chat service, which you should be able to clone.Then storing session information in Redis will help you more than storing the socket instance-user id map, because that way, your services can remain stateless, and clients can connect to any copy of your service (and any service will have access to the shared memory that Redis represents) without without losing session data.

    So my recommendation would be to use Redis as a shared memory if that is what you need, and keep cloning your chat services with a possible load balancer in front of them.

Leave a Reply