Resque is an open-source Ruby library for background job processing that stores jobs in Redis and executes them with separate worker processes. In job scheduling, Resque is a classic example of a queue-based worker system: an application pushes a small description of the work onto a named queue, and workers pull jobs and run them outside the web request cycle.
Resque was created at GitHub around 2009 to move slow tasks such as repository operations and notifications out of user-facing requests. Its defining design choice is the fork-per-job model, which trades throughput for strong isolation. Within the wider Automation subject, Resque belongs to the family of job queues alongside Sidekiq, Celery and BullMQ, and it influenced ports for PHP, Node.js and other languages.
How Resque queues and runs jobs
Resque works by serializing each job to JSON and pushing it onto a Redis list that represents a queue. A job is a Ruby class with a queue name and a class method named perform; enqueuing stores only the class name and its arguments, never the object itself.
A Resque worker is a long-running process that polls one or more queues in a defined priority order. When it pops a job, the parent process forks a child process, the child runs perform, and then exits. If the child crashes, leaks memory or is killed, the parent survives and continues with the next job.
The following table maps the main components to their responsibilities.
| Component | Responsibility | Implementation detail |
|---|---|---|
| Redis server | Stores queues, worker state and failures | Lists, sets and string keys |
| Job class | Defines the work and target queue | Class method perform with JSON arguments |
| Enqueuing code | Adds jobs from the application | Resque.enqueue call |
| Worker parent | Polls queues and supervises children | One process per worker |
| Forked child | Executes a single job | Exits after each job |
| Failure backend | Records exceptions and payloads | Failed list in Redis by default |
| Web dashboard | Shows queues, workers and failures | Sinatra application, resque-web |
Queues, priorities and worker configuration
Resque implements job priority through queue ordering rather than per-job priority values. A worker started with the queue list critical,default,low always empties critical before it checks default, so ordering is strict and lower queues can starve under sustained load.
Operators tune a small set of parameters that determine latency, throughput and resource use.
| Setting | Typical value | Effect |
|---|---|---|
| QUEUES | Ordered list or wildcard | Defines which queues a worker serves |
| INTERVAL | 1 to 5 seconds | Polling delay when queues are empty |
| COUNT (with resque-pool) | 2 to 20 workers per host | Sets parallelism on each machine |
| FORK_PER_JOB | Enabled by default | Isolation versus fork overhead |
| TERM_CHILD | Enabled in production | Graceful shutdown of running jobs |
Because concurrency comes from separate processes rather than threads, a host running ten workers needs memory for ten parent processes plus their children. Copy-on-write memory sharing after forking reduces this cost, but Ruby garbage collection gradually erodes the shared pages.
Scheduling, retries and the plugin ecosystem
Core Resque runs jobs as soon as a worker is free; it has no built-in timing, no automatic retries and no job dependencies. These features come from community plugins that hook into the job lifecycle.
- resque-scheduler adds delayed jobs and recurring jobs defined with cron expressions, using a separate scheduler process.
- resque-retry adds configurable retry counts and backoff before a job lands in the failed list.
- resque-pool manages a pool of workers per host from a single configuration file.
- Lifecycle hooks such as
before_performandaround_performenable locking, metrics and concurrency limits.
The scheduler process must be treated as a single point of coordination: running two schedulers without locking can enqueue each recurring job twice. Modern versions of resque-scheduler use a Redis-based master lock to elect one active instance.
Resque compared with other job queues
Resque is most often compared with Sidekiq, which uses the same Redis storage idea but runs jobs in threads inside one process. The comparison below highlights the trade-offs that usually decide between Ruby background job systems.
| Aspect | Resque | Sidekiq | Delayed Job |
|---|---|---|---|
| Storage | Redis | Redis | Relational database table |
| Concurrency model | Forked process per job | Threads in one process | Process polling the table |
| Isolation | Strong | Shared memory | Moderate |
| Throughput per host | Lower | Much higher | Lowest |
| Built-in retries | No, plugin required | Yes | Yes |
| Thread safety needed | No | Yes | No |
Resque also works as a backend for Active Job, the Rails abstraction for background work. This lets teams switch adapters without rewriting job classes, which is a common path when an application outgrows Resque throughput.
Operational risks and common mistakes
The most serious Resque risk is job loss during failures. When a worker pops a job from the list and the host dies before completion, the job is gone, because core Resque does not use reliable acknowledgment queues. Critical work therefore needs idempotent design and reconciliation checks.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Jobs vanish after a crash | No acknowledgment mechanism | Idempotent jobs and periodic reconciliation |
| Low-priority queue never drains | Strict queue ordering | Dedicated workers for that queue |
| Growing failed list | No retry policy | Add resque-retry with backoff |
| Duplicate recurring jobs | Two active schedulers | Enable the scheduler master lock |
| Jobs fail on stale records | Passing objects instead of IDs | Pass identifiers and reload data |
Another frequent mistake is placing large payloads in job arguments. Because every argument is stored in Redis, jobs should carry identifiers rather than data, and Redis itself should be sized and persisted with care.
Put simply
Resque is a to-do list for a web application. When the application has a slow task, such as sending an email or resizing a photo, it writes a note on the list instead of making the visitor wait.
Separate helper programs, called workers, pick notes off the list one by one and do the work in the background. Each task runs in its own fresh copy of the helper, so one broken task cannot spoil the next.
In practice
An online magazine built with Ruby on Rails lets editors upload photo galleries of up to 200 images. Generating five image sizes per photo inside the upload request took several minutes and caused browser timeouts.
The team moved resizing into a Resque job that receives only the gallery ID. Uploads now finish in a few seconds, and three servers each run eight workers on an images queue, with a separate mail queue served first so notifications are never delayed. resque-scheduler runs a nightly job at 02:00 that cleans orphaned files, and resque-retry retries storage errors three times with growing delays.
The result is a responsive editing interface and a predictable processing time of about 90 seconds per large gallery. When a corrupted image crashes a child process, only that single job fails and appears in the dashboard for review.