Search code examples
ruby-on-railsredissidekiqstaging

Will 2 servers running Rails + Sidekiq, using the same redis server cause unexpected behavour?


I'm planning to migrate my 2 sidekiq instances to use 1 Redis database. I'm concerned there may be issues with race conditions. Is it safe to do this or not?

I currently have 2 rails servers in production behind a load balancer. Each server is cloned, running a rails app, sidekiq, and a redis database.

The staging environment has the same setup. However, I have connected both sidekiq instances to a single Redis database.

So far I have had no problems, but the staging environment does not see much traffic to see any noticeable effects.


Solution

  • You should at least use different redis databases for staging and production so that tasks from one environment do not end up being run in the other.

    In your current setup tasks from one server are executed solely by the same server, but it's not necessary - you can have sidekiq instances pool shared between servers (sidekiq is designed to run fine this way) as long as they have same or compatible code versions (there may be problems while rolling out new versions when task for new version ends up picked by older one).

    This setup is actually better - if one sidekiq instance has all threads busy, tasks from correcponding server can be still run on the other.