1

I'm working on a web app where users enter a "room." The state of these rooms is loaded in the server's memory at all times, and is synchronized with the clients via websockets. What's the best way to handle rooms when there are multiple instances of my web app?

Should I...

A. Have some kind of load balancer that knows which instances are handling which rooms and directs connections accordingly?

B. Have the web app instances communicate with each other internally, so that all instances that have clients connected to a room are synchronized?

C. Something else?

  • didnt you ask before? databases ftw – Ewan Oct 1 at 18:04
  • We're already using postgres for storing user data, but making database queries every time the room state updates would be really inefficient, and it would not scale well. – Carson McManus Oct 1 at 23:18
  • it will scale better than having a server per room. try it – Ewan Oct 2 at 6:17
  • I never said anything about having 1 server per room. Servers can have many rooms – Carson McManus Oct 2 at 13:51
0

Don't know if "best", but "possible": use a shared REDIS. You need to map your room state and operations to state and operations supported by REDIS, of course.

If your servers are geographically dispersed, you need to decide how to handle this. Some options are:

  • use a single REDIS instance and live with the network latency

  • use replicated REDIS instances to improve read performance. Writes still need to address the master instance.

  • let each server cluster have its own REDIS instance handling a subset of the rooms, and redirect clients to the appropriate server cluster

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.