All Case Studies Design Development Interviews Our Way Project Management

Things to Remember When Working with Sidekiq

Even though the free version of Sidekiq lacks a few useful features, it’s still the most popular background processing gem for Ruby on Rails apps thanks to its performance and reliability. In Netguru it’s mostly used for time consuming tasks such as sending emails to customers or long database queries. There are few things you must remember about when working with Sidekiq.


TIP: Keep jobs parameters simple!

Sidekiq jobs can receive parameters of any format, but the more complex they are, the more likely they are to become corrupted. The parameters are serialized and stored in Redis until the queued job is run. It’s a good practice to pass only the most basic data types: integers (database IDs) or strings.


TIP: Don’t expect jobs to be completed in fixed time.

It’s essential to design the application to be independent of the jobs completion time. Even when jobs are mostly run in two seconds, they may always get enqueued for a long time, especially if the application scales up.


TIP: Binding.pry works with Sidekiq in development environment.

Even though the jobs are run in different thread, the binding.pry works fine. Developers tend to think that it doesn’t because of lack of code autoreload. You need to restart Sidekiq after every change in the code.


TIP: Remember about Redis namespaces.

When Redis is shared with many containers or apps, Sidekiq needs to be configured to use namespaces to avoid running jobs from other applications. You can use a gem called "redis-namespace" and setup a proper namespace in config/initializers/sidekiq.rb:

Sidekiq.configure_server do |config|
 config.redis = { url: AppConfig.redis.url, namespace: AppConfig.redis_namespace }
end

Sidekiq.configure_client do |client|
 client.redis = { url: AppConfig.redis.url, namespace: AppConfig.redis_namespace }
end

 

TIP: Remember to clear the retries queue.

Don’t forget about jobs that fail during the development. They are put in the retires queue and rerun every few minutes, even after you fix your code. By spamming the Sidekiq output with continuous failures, they may make you think that the job doesn’t work properly. Remember to clear them in /sidekiq/retries.


I hope that these few tips make your developer’s life easier. Take care!

Follow Netguru
Join our Newsletter

READ ALSO FROM Dev
Read also
Need a successful project?
Estimate project or contact us