Trevor
Trevor

Reputation: 2457

How do you handle sockets when you have multiple servers

Trying to figure out how to set up sockets with multiple different api servers.

I have 1 api server running on nodejs (v14) currently, which a client can connect to via a socket. I'm adding multiple servers (for now 2, maybe more later). If I add another how will sockets stay synchronized?

i.e. User A connects to Server 1 via socket. User B connects to Server 2 via socket. User A triggers an update event, Server 1 updates all clients. How does Server 1 notify Server 2 to update to all clients?

Upvotes: 0

Views: 173

Answers (1)

Karimov
Karimov

Reputation: 359

one word make a custom load balancer to distribute incoming socket connection among your servers. You to answer the second part of your question you can solve it by a Pub/sub . It's a messaging pattern where different components publish and subscribe to each other to notify and send data to each other. Just make all the servers a subscriber then if one server publish then all the servers get a notification. cheers.

Upvotes: 1

Related Questions