惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
G
Google Developers Blog
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
博客园 - 聂微东
V
Visual Studio Blog
博客园_首页
D
DataBreaches.Net
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
月光博客
月光博客
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Mastering Background Processing in Rails 8: Sidekiq & Red...
Abhinav Kushwaha · 2026-05-31 · via DEV Community
Cover image for Mastering Background Processing in Rails 8: Sidekiq & Redis Optimization

Abhinav Kushwaha

In modern web applications, keeping the Request-Response cycle fast is crucial for user experience. If a user registers on your Rails 8 app and you trigger a welcome email directly inside the controller, the browser will remain in a loading state until the SMTP server responds.

To solve this, we offload heavy, non-blocking tasks (like sending emails, generating PDFs, or syncing third-party APIs) to background workers. While Rails 8 now introduces Solid Queue as its default database-backed adapter, Sidekiq remains the industry gold standard for high-throughput, multi-threaded asynchronous processing powered by Redis (an in-memory data store).

​1. System Requirements & Installation

First, ensure that Redis is installed and running on your production or local environment.

For Ubuntu/Linux:

sudo apt update
sudo apt install redis-server
sudo systemctl enable redis-server.service

Next, add the Sidekiq gem to your Rails 8 Gemfile:

gem 'sidekiq'

Execute the bundle command in your terminal:

bundle install

2. Configuring Rails 8 to use Sidekiq

​Even with Rails 8's new defaults, switching to Sidekiq is seamless. You need to instruct your Active Job framework to use the Sidekiq adapter. Update your config/application.rb or config/environments/production.rb:

module BlogApp
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 8.0

    # Setting Sidekiq as the backend queue adapter
    config.active_job.queue_adapter = :sidekiq
  end
end

3. Production-Ready Redis Connection Pooling

​A common issue in production is running out of Redis connections due to improper pool sizes. To handle this cleanly, create a dedicated initializer file at config/initializers/sidekiq.rb:

# config/initializers/sidekiq.rb

Sidekiq.configure_server do |config|
  # Server pool size should match or slightly exceed your concurrency limit
  config.redis = { 
    url: ENV.fetch('REDIS_URL', 'redis://localhost:6379/0'), 
    size: 25 
  }
end

Sidekiq.configure_client do |config|
  # Client pool size scales with your web server (Puma) threads
  config.redis = { 
    url: ENV.fetch('REDIS_URL', 'redis://localhost:6379/0'), 
    size: 5 
  }
end

4. Real-World Example: Writing a Rails 8 Job

​Let's create a concrete example. We will generate a job that processes a user subscription report and sends an email.
​Instead of using old workers, we leverage modern Rails 8 standard inheritance. Run the generator command:

bin/rails generate job ProcessSubscriptionReport

This generates a file in app/jobs/process_subscription_report_job.rb. Let's implement it with proper error handling and a custom queue:

# app/jobs/process_subscription_report_job.rb
class ProcessSubscriptionReportJob < ApplicationJob
  # Classifying the priority queue in Sidekiq
  queue_as :default

  # Sidekiq-specific retry configuration
  sidekiq_options retry: 3, backtrace: true

  # Best Practice: Avoid passing complex ActiveRecord objects. Pass IDs instead.
  def perform(user_id)
    user = User.find_by(id: user_id)
    return unless user

    # Simulating heavy reporting logic
    report_data = UserReportGenerator.generate_for(user)

    # Triggering Mailer
    UserMailer.report_ready_email(user, report_data).deliver_now
  rescue ActiveRecord::RecordNotFound => e
    Rails.logger.error "Job failed: User with ID #{user_id} no longer exists. Error: #{e.message}"
  end
end

5. Sidekiq Concurrency & Concurrency Tuning
​Create a configuration file at config/sidekiq.yml to manage your concurrency limits and queues systematically for production:

# config/sidekiq.yml
:concurrency: 10
:queues:
  - critical
  - default
  - low

To run Sidekiq in your terminal, simply execute:

bundle exec sidekiq