Member-only story
How to Use Sidekiq in Rails 6
A deep dive into a favourite background-processing system
Updated February 2021 for Ruby on Rails 6.1 and Sidekiq 6.1.3 while also adding a step-by-step guide for deploying to Heroku.

In September 2019, Sidekiq released version 6.x. Sidekiq comes in three flavours: the open-source version, Sidekiq Pro, and Sidekiq Enterprise.
Sidekiq uses threads to handle many jobs at the same time in the same process and is integrated tightly with Rails, although Rails isn’t a requirement. If you are looking for something language-agnostic, you should check out Faktory, also created by Mike Perham (the creator of Sidekiq).
At Organisely, we use Sidekiq for any long-running where the user doesn’t require immediate feedback. We also use Sidekiq for jobs that are likely to fail due to network errors and we want to leverage the automated retry mechanism.
Organisely sends a daily batch of text messages (using Twilio’s SMS API) as reminders for customers’ appointments. Although Twilio has insanely reliable APIs, network errors are inevitable and must be taken into account. We wrap each Twilio API call into a Sidekiq job that’ll retry if the API call is unsuccessful.

Setup
If you didn’t already install Ruby on Rails for development on macOS, check out this tutorial.
Install Sidekiq by adding the gem to your Gemfile.
gem 'sidekiq', '~> 6.1.3'
Sidekiq has only one dependency, and that’s Redis. If you are using a Mac, you can install Redis using Homebrew:
$ brew install redis
Create a new job in app/jobs
to process jobs asynchronously:
class MyJob
include Sidekiq::Worker
def perform(args)
# block that will be retried in case of failure
end
end
You can invoke this job as MyJob.perform_async(args)
.
Start the Sidekiq process with bundle exec sidekiq
.