Petrescu Silviu
Petrescu Silviu

Reputation: 247

NodeJS matchmaking across servers

I'm trying to create a game similar to QuizUp.

From the start I've considered scalability (via AWS Beanstalk or multiple machines) so I was thinking of implementing it this way:
- X servers with load balancer in from of them
- Back server with Redis + MongoDB

All servers would connect to the same back server (the one with Redis/MongoDB) to set/get data so the matchmaking would work across servers.

Scenario:
- User 1 connects to Server A. Server A checks Redis to see if there are any users searching. Because there are none, he adds User 1 to the searching_users Redis set.
- User 2 connects to Server B. Server B checks Redis to see if there are any users searching. Because he finds User A he sends a response back to the client to say he found User A.

The question here is how does User 1 get informed that he was found?

One answer of course is that User 1 periodically checks if someone found him.
Another answer would be that the matchmaking is done via sockets.io (I'm doing it via HTTP now) and if the users would be on the same server they would be informed via Socket. In this case could the socket connected to another server be informed? (Server B informs the socket of User 1 connected on Server A - Besides opening a connection to that server and broadcasting)

Upvotes: 4

Views: 1827

Answers (1)

With socket.io, you will just use socket.io-redis adapter which enables every instance of your server but with the same redis. It is important to use 1 redis so that every server is subscribe to one redis.

Upvotes: 1

Related Questions