Ruby
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Methods and Blocks
-
Section 4: Object-Oriented Ruby
-
Section 5: Metaprogramming
-
Section 6: Working with Data and Files
-
Section 7: Ruby Frameworks Overview
-
Section 8: Ecosystem and Testing
-
Section 9: Practical Projects
-
Section 10: Interview Practice
-
Section 11: Data Structures and Algorithms in Ruby
-
Section 12: More Practice Exercises
-
Section 13: Enumerable and Functional Style
-
Section 14: More OOP Practice
-
Section 15: More Testing
-
Section 16: Enumerable and Comparable Modules In Depth
-
Section 17: Ruby Standard Library: Core Utilities
-
Section 18: Ruby Standard Library: Data and Security
-
Section 19: Ruby Standard Library: CLI and Text
-
Section 20: Ruby Networking
-
Section 21: Ruby on Rails Deep Dive
-
Section 22: Ruby Metaprogramming Deep Dive
-
Section 23: Ruby Design Patterns
-
Section 24: Ruby Concurrency
-
Section 25: Ruby Testing Deep Dive
-
Section 26: Ruby Gems and Packaging
-
Section 27: Ruby Performance
-
Section 28: More Practice Exercises
-
Section 29: More Interview Practice
-
Section 30: Rails API Development
-
Section 31: Rails Authentication and Authorization
-
Section 32: Rails Testing Deep Dive
-
Section 33: Rails Performance
-
Section 34: Rails Deployment
-
Section 35: Sinatra and Lightweight Ruby Web Apps
-
Section 36: More Ruby Language Deep Dive
-
Section 37: Ruby 3.x Modern Features
-
Section 38: More Data Structures in Ruby
-
Section 39: More Practical Projects
-
Section 40: Ruby Ecosystem Tools
-
Section 41: More Practice and Review
-
Section 42: Final Practice and Mastery
-
Section 43: Ruby Interview Deep Dive
-
Section 44: Ruby Background Processing Deep Dive
-
Section 45: Ruby GraphQL
-
Section 46: Ruby Object Model Deep Dive
-
Section 47: Ruby Hanami Framework Overview
-
Section 48: Ruby gRPC and Protocol Buffers
-
Section 49: Ruby Data Processing
-
Section 50: Ruby Search Integration
-
Section 51: Ruby File Upload and Media
-
Section 52: Ruby Email and Notifications
-
Section 53: Ruby Admin Panels
-
Section 54: Ruby Feature Flags and Experimentation
-
Section 55: Ruby Monitoring and Observability
-
Section 56: Ruby Docker and Deployment Deep Dive
-
Section 57: Ruby Security Deep Dive
-
Section 58: More Advanced Metaprogramming
-
Section 59: More Final Projects
184: Resque as an Alternative to Sidekiq
By this point in the course, you're probably pretty comfortable with Sidekiq. It's the gold standard for a reason: it's fast, it's efficient, and it handles thousands of jobs per second without breaking a sweat. But there is a fundamental architectural trade-off happening under the hood that can bite you in the ass if you're dealing with "unstable" code. Sidekiq is multithreaded. That means one Ruby process is running multiple jobs simultaneously in different threads.
The Thread-Safety Gamble
Imagine you're building a feature that generates complex PDF reports using a library that wraps a C-extension—something like wkhtmltopdf. In a perfect world, this works great. But in the real world, some of these libraries have memory leaks or, worse, they occasionally cause a segmentation fault (a "segfault").
If you're using Sidekiq and one of those PDF jobs triggers a segfault, it doesn't just kill that one job. It kills the entire process. Because Sidekiq is running 25 other jobs in that same process, all 25 of those jobs are suddenly terminated mid-flight. You've just turned a single failing report into a cascading failure across your background queue. I've seen this happen in production where a single "poison pill" job would repeatedly crash the worker, effectively DOS-ing the system because Sidekiq would keep trying to pick it up and crashing again.
The Isolation Guarantee
This is where Resque comes in. While Sidekiq is multithreaded, Resque is fork-based. When a Resque worker picks up a job, it doesn't run it in a thread; it forks a completely new child process to handle that specific piece of work.
Going back to our PDF example: if the PDF generator leaks 500MB of RAM or hits a segfault and crashes, it only kills the child process. The parent worker process remains untouched, calmly notes that the child died, and moves on to the next job. The operating system handles the cleanup, and all that leaked memory is reclaimed instantly. It's a "burn after reading" approach to job execution. You get total isolation, which is an incredible safety net when you're forced to use unstable third-party binaries or legacy code that isn't thread-safe.
Trading RAM for Peace of Mind
Now, you might be wondering why we don't just use Resque for everything. The cost is memory. Forking a process is significantly "heavier" than spawning a thread. If you have a large Rails app, every time Resque forks, it carries over the memory footprint of your application (though Ruby's Copy-on-Write helps mitigate this). If you're running 50 workers, you're using way more RAM than 50 Sidekiq threads would.
I usually tell my team to think of it this way: Sidekiq is for your high-volume, "well-behaved" logic (sending emails, updating counters, syncing APIs). Resque is for the "dangerous" stuff (heavy image processing, PDF generation, shell-outs to unstable CLI tools). You don't even have to choose just one; you can actually run both in the same app, routing your stable jobs to Sidekiq and your volatile jobs to Resque.
# A typical Resque job looks remarkably like Sidekiq,
# but the execution model is fundamentally different.
class MonthlyReportGenerator
@queue = :heavy_lifting
def self.perform(user_id)
user = User.find(user_id)
# If this method crashes the Ruby VM, only the fork dies.
PDFGenerator.render(user.report_data)
end
end
📋 Practical Task
Migrating the Volatile PDF Worker to Resque
You have a Sidekiq worker called InvoicePdfWorker that is currently causing intermittent crashes in your production environment due to a memory leak in the underlying pdf-renderer gem. Your goal is to move this specific functionality to Resque to ensure process isolation.
- Create a new Resque job class named
InvoicePdfJob. - Define the
@queueas:pdf_reports. - Move the logic from the Sidekiq
performmethod into the Resqueself.performmethod. - Update the call site in the
InvoicesControllerto useResque.enqueue(InvoicePdfJob, invoice_id)instead ofInvoicePdfWorker.perform_async(invoice_id). - Verify that the job is correctly enqueued by checking the Redis
resque:queue:pdf_reportskey.
There are no comments for now.