0

I am developing a little project using Node.js. I am using mongoose for models, therefore i am using MongoDb. And i keep sessions in MongoStore. Also i want to use socket.io running several processes of Node. From socket.io docs:

    The MemoryStore only allows you deploy socket.io on a single process. 
If you want to scale to multiple process and / or multiple servers 
you can use our RedisStore which uses the Redis 
NoSQL database as man in the middle.

So i think i need Redis too. I am new in Node and i want to know - is it normal to use two databases to manage different parts of application. Or is there a way to work with socket.io when running several processes of Node and use only MongoDb

Alex Emelin
  • 814
  • 1
  • 9
  • 19

2 Answers2

4

Just recently a solution that uses MongoStore with pub/sub functionality using mubsub (Pub/sub for Node.js and MongoDB) has appeared.

It can be attached to socket.io in almost the same way as you would with RedisStore:

io.configure(function() {
    io.set('store', new MongoStore({host: 'localhost', port: 27017, db:'session_db'}));
});

More information and source at: https://github.com/kof/socket.io-mongo

Koen.
  • 25,449
  • 7
  • 83
  • 78
  • 1
    On a side note, I didn't manage to get it working with multiple processes running, it kept handshaking. So if you got it working, please let me know! – Koen. Jul 11 '12 at 08:24
2

The Redis store is already built into Socket.IO, but more importantly has 2 important features that are particularly needed for Socket.IO:

1) Publish-subscribe (to communicate between processes)
2) Key-value store (to store all the info about connections)

While the key-value store part can be done with MongoDB, it doesn't provide the pub-sub functionality.

Bottom line, IF you need to scale beyond one process (meaning you are expecting more than some thousand concurrent request) than RedisStore is the solution.

Resources:

Community
  • 1
  • 1
alessioalex
  • 62,577
  • 16
  • 155
  • 122