Migrating From Sidekiq To Solid Queue: Simpler and Cheaper
ruby on rails
Sidekiq Is Great!
Sidekiq has been the go-to choice for Ruby on Rails applications for years. And for good reason ā itās packed with incredible features.
Huge shoutout to the team for open-sourcing such a powerful tool!
Why Make The Switch To Solid Queue?
Late last year, DHH unveiled Solid Queue - a new gem to leverage your existing database to handle background jobs. And the results speak for themselves: 37signals is processing about 5.6 million jobs daily with it.
Solid Queue, the new DB-based backend for Active Job in Rails, has made its premiere! We're running millions of jobs through it every day, and replaced a plethora of Resque gems to get the introspection and features we need. Check it out: https://t.co/lxqrl2vjoK
— DHH (@dhh) December 18, 2023
Simplifying our codebase like that is incredibly appealing, so naturally, I had to dive deeper into it.
The setup was a breeze, and we wrapped up the entire migration, including testing, in a single day.
Hereās my take on Solid Queue compared to Sidekiqāwhat I love and what I donāt.
š Reduced Redis Usage
Sure, Redis wasnāt breaking the bank on our cloud bill, but it was pulling double duty as our job scheduler and cache store.
By ditching Redis for Sidekiq, we get two wins:
- A leaner, cheaper Redis setup
- More room for our cache, which means fewer evictions, more cache hits, and snappier responses.
š Built-in Cron Runner
Before, when using Sidekiq, we had to scramble for a job scheduler since Sidekiq doesnāt come with a built-in cron feature.
Take this for example: we had to install the Whenever gem to handle job scheduling. And because weāre deploying via a Dockerfile to Fly.io, we also needed to install cron and set up Supercronic as our job runner.
But with Solid Queue, all that hassle is gone! Now, we can manage everything right in the solid_queue.yml file. Itās streamlined, and it just works.
š Less Processes ā Cost Savings
Previously, using Sidekiq meant spinning up a separate machine for each process handling different queues. This was inefficient, as these machines often sat idle, wasting resources. For instance, we had to deploy four processesāone for cron jobs and three for Sidekiq.
# We are using Flu.io, thus defining processes within fly.toml
# Reference: https://fly.io/docs/reference/configuration/
[processes]
cron = "supercronic ./crontab"
sidekiq_1 = "bundle exec sidekiq -c 100 -q logging -q default -q llm"
sidekiq_2 = "bundle exec sidekiq -c 10 -q mailers -q scrapers"
sidekiq_3 = "bundle exec sidekiq -c 1 -q refresh_salary_views"
With Solid Queue, all workers run on the same machine. Plus, with Cron now integrated, thereās no need for a separate machine for cron jobs. Weāve reduced our hardware requirements from four machines to just oneāan efficient and cost-effective solution!
# solid_queue.yml
workers:
- queues: [logging, default, llm]
threads: 100
- queues: [mailers, scrapers]
threads: 10
- queues: [refresh_salary_views]
threads: 1
š āMission Controlā Can Be Improved
This isnāt a deal breaker by any means, but my greedy desires show up here.
Unlike Sidekiq, SolidQueue doesnāt come with a built-in dashboard. Youāll need to install a separate gem called Mission Control for that. No biggie.
And for the most part, Mission Control does a solid job at mimicking Sidekiqās dashboard.
But itād be fantastic if it also included charts to quickly visualize the number of jobs processed and the average time taken for each type. That kind of insight can be pretty useful for debugging and optimization.