DEV Community

Wilbur Suero
Wilbur Suero

Posted on

Background Jobs in Rails: A Look at SolidQueue

Coming from a Rails background, one of the most common patterns developers rely on is background job processing. Traditionally, this has meant reaching for Sidekiq, Resque, or Delayed Job—external tools that require Redis or additional infrastructure. But what if you could handle background jobs natively within your database? Enter SolidQueue.

In this post, I’ll explore how SolidQueue changes the game for Rails developers, how it compares to existing background job solutions, and how you can start using it today.

SolidQueue in Rails 8: Built-In Background Jobs

With the release of Rails 8, SolidQueue is now bundled as the default background job system. This means that if you're starting a new Rails 8 application, you already have everything you need to manage background jobs without any additional dependencies.

Minimum Required Version

SolidQueue requires Rails 7.1 or later to function. However, for full integration and the best experience, Rails 8 is recommended since it comes pre-configured.

Understanding SolidQueue: Background Jobs Without External Dependencies

SolidQueue is a database-backed queuing system designed to work seamlessly with Active Job in Rails. Unlike Sidekiq or Resque, which rely on Redis, SolidQueue keeps everything within your application’s SQL database. The result? Simplified infrastructure, reduced operational complexity, and one less dependency to worry about.

Key Features of SolidQueue

  1. Native Database Integration: Jobs are stored and managed using PostgreSQL, MySQL, or SQLite—whichever database your Rails app already uses.
  2. Active Job Compatibility: Works out of the box with Rails' Active Job framework.
  3. No Additional Services Required: Eliminates the need for Redis or external queueing systems.
  4. Mission Control UI: Provides a web interface to monitor and manage jobs.
  5. Automatic Job Retries & Error Handling: Ensures reliable job execution.

How to Set Up SolidQueue in Rails 8

If you're using Rails 8, SolidQueue is already included, and you just need to enable it.

Enabling SolidQueue in a New Rails 8 App

For new Rails 8 applications, SolidQueue is the default Active Job adapter. To ensure it is enabled, check your config/application.rb:

config.active_job.queue_adapter = :solid_queue
Enter fullscreen mode Exit fullscreen mode

Then, run the database migrations to set up the necessary tables:

rails db:migrate
Enter fullscreen mode Exit fullscreen mode

Setting Up SolidQueue in an Existing Rails 7.1+ App

If you're on Rails 7.1 or later and want to use SolidQueue, you'll need to install it manually:

# Add to your Gemfile
gem 'solid_queue'
Enter fullscreen mode Exit fullscreen mode

Then, run the installation generator:

bundle exec rails generate solid_queue:install
rails db:migrate
Enter fullscreen mode Exit fullscreen mode

Defining and Enqueueing Jobs

Creating jobs with SolidQueue is no different from using Active Job:

class ExampleJob < ApplicationJob
  queue_as :default

  def perform(name)
    puts "Processing job for #{name}"
  end
end

ExampleJob.perform_later("Alice")
Enter fullscreen mode Exit fullscreen mode

Running Jobs

SolidQueue requires a supervisor process to run jobs. Start it with:

bundle exec solid_queue:start
Enter fullscreen mode Exit fullscreen mode

This will process jobs from the database queue, similar to how Sidekiq works.

A More Detailed Example: Processing an Order in Rails 8

Let’s say we’re building an e-commerce application and need to process orders asynchronously. With SolidQueue in Rails 8, we can handle this with ease.

Step 1: Define the Job

class ProcessOrderJob < ApplicationJob
  queue_as :default

  def perform(order_id)
    order = Order.find(order_id)
    order.process_payment!
    order.update!(status: "completed")
    puts "Order ##{order.id} has been processed."
  end
end
Enter fullscreen mode Exit fullscreen mode

Step 2: Enqueue the Job When an Order is Created

Modify your OrdersController:

class OrdersController < ApplicationController
  def create
    @order = Order.create!(order_params)
    ProcessOrderJob.perform_later(@order.id)
    redirect_to @order, notice: "Your order is being processed."
  end
end
Enter fullscreen mode Exit fullscreen mode

Step 3: Start the Worker Process

To start processing jobs, simply run:

bundle exec solid_queue:start
Enter fullscreen mode Exit fullscreen mode

Now, every time a new order is created, it will be processed in the background by SolidQueue.

Comparing SolidQueue to Sidekiq

Feature SolidQueue (Database-Backed) Sidekiq (Redis-Backed)
Dependency Uses SQL database Requires Redis
Infrastructure No extra services needed Needs Redis, Sidekiq
Performance Good for most applications Optimized for high throughput
UI for Jobs Mission Control UI Sidekiq Web UI
Reliability Database transactions ensure safety Redis-based, requires persistence tuning

If you’re running a high-throughput application with millions of background jobs per day, Sidekiq may still be the best choice. But for most Rails applications, SolidQueue provides a much simpler, integrated solution without the extra operational burden.

When Should You Use SolidQueue?

SolidQueue is a great choice if:

  • You want to avoid the overhead of running Redis.
  • Your application already relies heavily on its database.
  • You prefer an all-in-one solution with built-in job monitoring.
  • You need Active Job compatibility with minimal setup.

However, if you need extreme performance and high concurrency, Sidekiq might still be the better option.

SolidQueue represents a shift in how Rails developers can handle background jobs. By leveraging the database as a queueing system, it removes the need for external services like Redis while maintaining reliability and simplicity. With Rails 8, SolidQueue is now the default, making background job processing more accessible than ever.

If you’re using Rails 8, try it out today—it’s already built in! And if you're on an older version, upgrading to Rails 8 or installing SolidQueue manually can help simplify your background job processing.

Top comments (0)