Rails + Sidekiq: Do I need a separate service for background jobs only?

The docs are a little confusing – I hope someone can clarify.

Currently, my workers sit in my main Rails app, which I have deployed to Render as a “Web Service”. I also added Redis service and connected it to my main app via ‘REDIS_URL’. OK, so that’s 2 services running so far.

Now, do I still need to deploy a separate “Background Worker” service for my background jobs? (The docs show this setup.) If yes, why? Why can’t I just have workers executing from my main web service?

If it’s required to have a standalone service for background jobs, do I just select the same repo as my main Rails app? Or do I need to rewrite the code and extract the background workers from my main app’s logic and then deploy?

Hey there,

The short answer is exactly as your last point - deploy the same code again but select a background worker as the instance type, you’ll also need to give it the same configuration as the web service - DB URL, Redis URL etc but have your start command run sidekiq as opposed to rails.

The longer answer is, that each instance you create runs one command (the start command) in the resource it has available, for a starter webservice, that’s 512Mb - with a separate instance, that full 512Mb can be used by the web service so with a separate background instance, it too has it’s own 512Mb and runs entirely isolated, so should you need to scale either of these vertically, giving it more compute resource you can. Similarly, if you background process is resource hungry, CPU and RAM then that doesn’t impact your web service.

I hope that makes sense,

John B
Render Support, UTC :uk: