Matchmaking with socket.io - rely on setInterval or socket calls?
<p>I'm developing a game where my backend is written in NodeJS and I use socket.io for realtime communication.</p>

<p>One of the features of my game is matchmaking. Basically, if more than two players are on matchmaking period, my application will create a game room (special socket.io room) for them and start the game.</p>

<p>There are two ways to do this:</p>

<ul>
<li><p>Create a setInterval on NodeJS. In the interval, check playersInMatchmaking array. If there are more than 2 players in the array, create the game room. I will loop as long as the server is online.</p></li>
<li><p>Instead of relying on setInterval, check playersInMatchmaking array each time I receive a call to <code>socket.on("matchmaking start")</code> or <code>socket.on("matchmaking stop")</code></p></li>
</ul>

<p>Is there any benefits of using certain approach? setInterval sounds easier as I can decouple matchmaking algorithm from socket logic, however it will be less performant as matchmaking algorithm will run in a loop as opposed to socket events.</p>

<p>What do you think? Do you have any other ideas that would work better?</p>