Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

In Node.js what storage technologies are available for real time games

In Node.js what storage technologies are available for real time games


I am planning on experimenting with Realtime game development using html5 and node.js. I previously made a game using polling to simulate real-time updates in a game. My real-time game would use AJAX to keep the game synchronized across multiple clients. Basically whenever a change in game state occurred, I would update a field last_updated in the database row concerned. Whenever a client polled the server, it would check for any updates that occurred since its last poll returning any relevant updates (doing this by comparing the previous poll time to the last_updated fields).

In my new version of the game where I instead use node.js (and web-sockets) I would like to avoid a mechanism like this where I have to continually do searches to a database to find if there were updates. I was wondering if there were alternative methods to storing important game state information, without the use of a database in this mannor.

I would really like to be able to setup events to fire on all clients when game state is changed instead of having to continually check for changes as this would save a large amount of processing / querying. I don't really know if an event fired on one client can be sent to other clients also connected to my node.js running server. I have always used a database for this sort of thing, but I am really hoping there are other better alternatives?

Cheers, Josh

Problem courtesy of: Josh Mc


First of all you need something like Socket.IO to handle the websockets (and long-polling etc if WS not available).

After that you need Redis or ZeroMQ to scale Socket.IO (by scaling I mean multiple processes even multiple servers). You could also use CouchDB's _changes event for that. (which could let you know when an insert/update has occurred)

As for the storage engine, I suggest you use either MongoDB (really good for writes, that's what you need) or a combination of Redis (reading from memory) and CouchDB (for writes).

All of them have Node.js libraries, which you can checkout on the modules page or you can find them on their websites (on the dbs websites).

Solution courtesy of: alessioalex


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

In Node.js what storage technologies are available for real time games


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription