Skip to content

The Basics

Mike Perham edited this page Oct 13, 2015 · 15 revisions

Sidekiq is a framework for background job processing. It allows you to scale your application by performing work in the background. This requires three parts:

Client

The Sidekiq client runs in your web application process (typically a Rails unicorn or passenger process) and allows you to push jobs into the background for processing. There are two ways to create a job in your application code:

MyWorker.perform_async(1, 2, 3)
Sidekiq::Client.push('class' => MyWorker, 'args' => [1, 2, 3])  # Lower-level generic API

These methods create a Hash which represents the job, serializes that Hash to a JSON string and pushes that String into a queue in Redis. This means the arguments to your worker must be simple JSON datatypes (numbers, strings, boolean, array, hash). Complex Ruby objects (e.g. Date, Time, Active Record models) will not serialize properly.

Redis

Redis provides data storage for Sidekiq. It holds all the job data along with runtime and historical data to power Sidekiq's Web UI.

Server

Each Sidekiq server process pulls jobs from the queue in Redis and processes them. Like your web processes, Sidekiq boots Rails so your jobs and workers have the full Rails API, including Active Record, available for use. The server will instantiate your worker and pass the arguments. Everything else is up to your code.

Previous: Getting Started Next: Best Practices