6

After using Node.js and socket.io for a while, I understand that if I want my application to support up to 1 million concurrent users I need to scale it, So I started using Redis to PUB/SUB messages between sockets and running a lot of socket.io servers instances, in the same machine and on other machines but all my socket.io servers works with the same Redis server.

This makes me think: what's the point? Will I need a few more redis servers and scale between them? My point is that their will always be a bottleneck on the top server.

My question is, is it possible to scale Redis? And if yes, how will all my sockets that connected to different socket.io server be able to PUB/SUB between the Redis servers?

Zoe
  • 27,060
  • 21
  • 118
  • 148
udidu
  • 8,269
  • 6
  • 48
  • 68
  • please, do you use the same connection for the pub/sub ? thanks –  Aug 20 '12 at 23:43
  • No, creating 2 clients for each connected client – udidu Aug 21 '12 at 06:45
  • terribly sorry, I would like say for **no** the pub/sub. So ? thank you –  Aug 21 '12 at 13:19
  • You read this post of mine @ http://stackoverflow.com/a/4446424/11926 ? That example can be written much better! Then one instance of redis can scale all your socket.io servers! – Alfred Aug 21 '12 at 14:25

2 Answers2

2

I think what you're looking for is Redis Cluster. It is mentioned on that page as "being worked on" and "hopefully for this summer".

There's a presentation here. It's basically hashing + single master and slaves for redundancy. But it's not ready yet. Your best bet for more information is to hit up the forums and IRC for those products.

If someone is doing something similar, they will be on those channels.

Gates VP
  • 44,957
  • 11
  • 105
  • 108
  • 1
    Or, if you're app is the only client requesting from Redis, roll your own by doing client-side hashing. Quick search for lib in Node.js to help you: https://github.com/bnoguchi/node-hash-ring. (read up on the referenced blogpost if you're unfamiliar with the term 'consistent hashing' which basically allows you to elastically scale your servers with minimum overhead and rehash occordingly, instead of having to define the nr of servers a priori). BTW: this only takes care of sharding. Replication/HA has to be taken care of as well. – Geert-Jan Aug 20 '12 at 23:13
  • 2
    Yep, Redis Cluster is the way to go with this. I've been using it since April 2012 for other things and pub/sub, and it works just great :) I wrote a nodejs module that helps you deal with Redis Cluster and does the client-side hashing for you, all you have to do is provide an address to one of the nodes and it will discover the other nodes for you if you configured the cluster correctly: https://github.com/joaojeronimo/node_redis_cluster – João Pinto Jerónimo Aug 22 '12 at 06:38
0

For further readers, using socket.io with its redis adapter is not scalable (at least for now). Under the hood, redis adapter uses pub/sub to broadcast. Here's a discussion about that: https://github.com/redis/redis/issues/2672

1 thing to highlight: Redis Cluster is not the answer (discussed in the issue above or see youtube link below to get more detail)

I found one interesting solution on scaling Redis pubsub here: https://redislabs.com/wp-content/uploads/2018/04/Redis-Day-TLV-2018-Scaling-Redis-PubSub.pdf

Watch youtube: https://www.youtube.com/watch?v=6G22a5Iooqk&ab_channel=RedisLabs

Duc Trung Mai
  • 2,141
  • 1
  • 24
  • 23