Redis PUBLISH/SUBSCRIBE limits

mistagrooves picture mistagrooves · Jun 28, 2011 · Viewed 9k times · Source

I'm considering Redis for a section of the architecture of a new project. It will consist of a lot of clients (node.js connections) SUBSCRIBING to particular keys with one process PUBLISHING to those keys as needed.

I'm curious about the limits of the PUBLISH/SUBSCRIBE commands and how to mitigate those. An obvious limit is the amount of file descriptors open on the machine with Redis so at some point I'll need to implement Master-Slave or Consistent Hashing to multiple Redis instances.

Does anyone have any solutions about how to scale this architecture with Redis' PubSub?

Answer

Kamiel Wanrooij picture Kamiel Wanrooij · Jun 28, 2011

Redis PubSub scales really easily since the Master/Slave replication automatically publishes to all slaves.

The easiest way is to load balance the connections to node.js with for instance HAProxy, run a Redis slave on each webserver that syncs with a single master that publishes the messages.

I can't give you exact numbers since that greatly depends on the underlying system, but this should scale extremely well. And you don't need to manage the clients and which server they connect to manually. You obviously need some way to handle session state, so you might need to do that anyway, but that's a lot easier to do in the load balancer than in your application.