Rails Solid Queue for Background Jobs

Rails 8.0 introduces Solid Queue as the new default background job processing system. Built by the Rails team, Solid Queue provides a simple, database-backed solution that eliminates the need for external dependencies like Redis or Sidekiq.

What is Solid Queue?

Solid Queue is a background job processing system that uses your existing database to store and process jobs. Unlike Sidekiq or Delayed Job, Solid Queue doesn't require Redis or any external services—it leverages your PostgreSQL or MySQL database for job storage and processing.

Why Solid Queue?

Traditional background job systems like Sidekiq require Redis, which adds complexity to your infrastructure. Solid Queue simplifies this by:

  • No external dependencies: Uses your existing database
  • Simple setup: Works out of the box with Rails 8.0
  • Reliable: Built on proven database technologies
  • Performant: Optimized for high-throughput job processing

Installation

If you're using Rails 8.0, Solid Queue is available by default. For earlier versions, add it to your Gemfile:

gem 'solid_queue'

Then run the installer:

rails solid_queue:install

This will generate the necessary migrations and configuration files.

Basic Setup

1. Configure the Queue Adapter

Set Solid Queue as your Active Job adapter in config/application.rb:

module MyApp
  class Application < Rails::Application
    config.active_job.queue_adapter = :solid_queue
  end
end

2. Run Migrations

Run the migrations to create the necessary tables:

rails db:migrate

This creates tables like solid_queue_jobs, solid_queue_blocked_executions, and solid_queue_failed_executions.

3. Start the Worker

In development, start the Solid Queue worker:

rails solid_queue:start

For production, you'll want to run this as a background process using a process manager like systemd or a deployment tool.

Creating Background Jobs

Creating jobs with Solid Queue is the same as any Active Job:

# app/jobs/email_notification_job.rb
class EmailNotificationJob < ApplicationJob
  queue_as :default

  def perform(user_id, message)
    user = User.find(user_id)
    UserMailer.notification(user, message).deliver_now
  end
end

Enqueue the job:

EmailNotificationJob.perform_later(user.id, "Welcome to the app!")

Configuration

You can configure Solid Queue through an initializer:

# config/initializers/solid_queue.rb
SolidQueue.configure do |config|
  # How often to poll for new jobs (default: 1 second)
  config.poll_interval = 1.second

  # Maximum number of concurrent jobs (default: 5)
  config.max_concurrency = 5

  # Concurrency per queue
  config.concurrency = {
    default: 5,
    mailers: 3,
    urgent: 10
  }
end

Queue Management

Named Queues

You can use named queues to organize your jobs:

class UrgentJob < ApplicationJob
  queue_as :urgent
end

class EmailJob < ApplicationJob
  queue_as :mailers
end

Scheduling Jobs

Schedule jobs to run at a specific time:

# Run in 1 hour
EmailNotificationJob.set(wait: 1.hour).perform_later(user.id, message)

# Run at a specific time
EmailNotificationJob.set(wait_until: 1.day.from_now).perform_later(user.id, message)

Priority

Set job priority:

EmailNotificationJob.set(priority: 10).perform_later(user.id, message)

Higher priority jobs are processed first.

Monitoring and Management

Solid Queue provides a web interface for monitoring jobs. Add it to your routes:

# config/routes.rb
Rails.application.routes.draw do
  mount SolidQueue::Engine, at: "/solid_queue"
end

Visit /solid_queue to view:

  • Active jobs
  • Failed jobs
  • Job statistics
  • Queue status

Error Handling

Solid Queue automatically retries failed jobs. Configure retry behavior:

class EmailNotificationJob < ApplicationJob
  retry_on StandardError, wait: :exponentially_longer, attempts: 5

  discard_on ActiveRecord::RecordNotFound

  def perform(user_id, message)
    # Job implementation
  end
end

Comparison with Other Solutions

FeatureSolid QueueSidekiqDelayed Job
External DependenciesNoRedisNo
Setup ComplexityLowMediumLow
PerformanceHighVery HighMedium
Web UIYesYesNo
Built-inRails 8.0+NoNo

When to Use Solid Queue

Solid Queue is ideal when:

  • You want a simple, built-in solution
  • You don't want to manage Redis
  • Your job volume is moderate to high
  • You're already using PostgreSQL or MySQL

Consider Sidekiq if:

  • You need extremely high throughput
  • You already have Redis infrastructure
  • You need advanced features like scheduled jobs with cron syntax

Conclusion

Solid Queue is ideal for smaller teams or startups seeking to simplify their stack. If you’re starting a new Rails 8.0+ app, Solid Queue should be your default.

Rails Solid Queue for Background Jobs - Abhay Nikam