Skip to main content

Sidekiq how and when to use different sidekiq queue

Sidekiq gives us options to prioritize jobs as needed. We currently have 5 queues defined, and we may add more down the line.

:queues:
- [form_response, 5]
- [default, 4]
- [external_api, 2]
- [apps, 2]
- [admin, 1]

Here, higher number means higher priorities. If you just trigger a sidekiq job, everything is going to be handled by default, meaning there may be 30/40 K jobs on default queue at a time which other queues are at 0. This will delay our emails (password reset, email confirmation) and other that needs to be taken care of asap. So the best practice should be to assign different queue based on priority.

Here is an example:-

# SomeApiWorker..perform_async(app_id)

class SomeApiWorker
include Sidekiq::Worker
sidekiq_options queue: :external_api

def perform(app_id)
# make api call
end
end

If you have a library, class or module

# SomeApiLibrary.delay(queue: 'form_repsponse').make_some_request(app_id)

module SomeApiLibrary
def self.make_some_request(app_id)
puts 'making some request'
end
end