views:

71

answers:

1

I'm interested in using Node.js as a socket server for stream-based communication with tens of thousands of clients. Clients will be sending votes for particular pieces of content, and receiving near-realtime updates of aggregated vote tallies from the server.

The datastore needs to support:

  1. Storing the votes
  2. Summarising the votes in near-realtime
  3. Preventing multiple votes within an arbitrary time period (e.g. clients can only vote once for a piece of content every 1 minute)

Something that already has client libraries for Node.js would be preferable.

+2  A: 

I would highly recommend Redis. It is a key/value store with set and list operations. It also supports atomic operations for counters. There is a client for Redis for Node.js available on github. Here is how I would implement your features:

Storing the votes

INCR votes:option:<option>

Summarizing the votes

MGET votes:option:<option1> votes:option:<option2> ... votes:option:<optionN>

Preventing multiple votes (create an expiring lock key for client IP)

EXPIRE lock:<encoded ip> 60
jakemcgraw
+1 for using redis, other alternatives would be here: [Database Modules for Node.js](http://wiki.github.com/ry/node/modules#database)
Maushu