How do you handle background job failures and retries in Rails?

Answer

ActiveJob provides hooks for handling failures: rescue_from(StandardError) { |e| retry_job(wait: 5.minutes) }. Sidekiq has built-in retry logic with exponential backoff — it retries failed jobs up to 25 times by default, with increasing delays, then moves them to the Dead Job Queue (viewable in the Sidekiq Web UI). Custom retry logic: sidekiq_options retry: 5. For critical jobs, use idempotency — jobs should be safe to run multiple times without side effects (check if work was already done). For non-retriable jobs: sidekiq_options retry: false. Monitor with Sidekiq metrics, error tracking services (Sentry/Honeybadger), and alerting on Dead Queue size.