In a Rails 8.1 app, what changes when Sidekiq runs jobs through Active Job's :sidekiq adapter rather than as native Sidekiq::Job classes?
answer
- one adapter line in config
- a wrapper job carries the serialized hash
- GlobalID vs JSON-only arguments
- provider_job_id holds Sidekiq's jid
- 8.1 deprecates Rails' bundled adapter
basics
~10 sWith config.active_job.queue_adapter = :sidekiq, ApplicationJob classes keep perform_later, GlobalID arguments, callbacks and retry_on, and Sidekiq runs them inside a wrapper job. Native Sidekiq::Job classes skip Active Job: JSON-only arguments, Sidekiq's own API, less overhead.
solid answer
~40 sSetting `config.active_job.queue_adapter = :sidekiq` keeps jobs as `ApplicationJob` subclasses: you call `perform_later`, arguments go through Active Job serialization (so a `Photo` travels as a GlobalID), and callbacks, `retry_on` and `discard_on` all work. The adapter pushes a `Sidekiq::ActiveJob::Wrapper` job whose single argument is the serialized Active Job hash, and Sidekiq's `jid` becomes the job's `provider_job_id`. Native `include Sidekiq::Job` classes skip that layer: JSON-only arguments, `perform_async`, and less CPU spent per job. In Rails 8.1 the adapter Rails itself bundles is deprecated; the sidekiq gem (7.3.3 and later) ships its own adapter and replaces Rails' class when it loads, so a Sidekiq 8 app keeps the same setting and sees no warning. Active Job classes can still call `sidekiq_options`, because the gem mixes `Sidekiq::Job::Options` into them.
code
ruby · 7 lines# Rails console, queue_adapter = :sidekiq, sidekiq 8.1
job = WatermarkJob.perform_later(Photo.find(42))
job.job_id # => "5d1e..." Active Job's UUID
job.provider_job_id # => "a91c..." Sidekiq's jid
# The same work as a native job: ids only
WatermarkNativeJob.perform_async(42) # => "7be0..." (jid)go deeper
Remember the one-line switch, config.active_job.queue_adapter = :sidekiq, and that jobs then keep using perform_later while Sidekiq does the running.
Walk through the wrapper: serialize, push Sidekiq::ActiveJob::Wrapper with the hash, execute on the worker, and how job_id and provider_job_id differ.
Decide per job class: Active Job for portability, records and retry_on; native jobs where overhead matters; and know the 8.1 deprecation moves the adapter into the gem.
Frame the choice as an abstraction budget: a portable job API eases a later backend move, while native jobs couple the code to one vendor for speed and features.
## Two ways into the same Redis queues A Rails application can hand work to **Sidekiq** in two styles, and both can live in one codebase. - **Through Active Job.** Jobs subclass `ApplicationJob`, are enqueued with `perform_later`, and the application selects Sidekiq with one setting: `config.active_job.queue_adapter = :sidekiq`. - **Natively.** Classes `include Sidekiq::Job` and are enqueued with `perform_async`, `perform_in` or `perform_bulk`. Active Job is never involved. The worker process is the same `bundle exec sidekiq` either way, reading the same queues. ## What the adapter does under the hood ```ruby # config/application.rb config.active_job.queue_adapter = :sidekiq # app/jobs/watermark_job.rb class WatermarkJob < ApplicationJob queue_as :thumbnails sidekiq_options backtrace: 10 # Sidekiq-level option on an Active Job class def perform(photo) WatermarkStamper.new(photo).stamp! end end WatermarkJob.perform_later(photo) # photo travels as a GlobalID ``` 1. `perform_later` builds the job and calls `serialize`, which turns the record into a GlobalID string and records the job class, `job_id`, queue name and execution counters. 2. The adapter calls `Sidekiq::ActiveJob::Wrapper.set(wrapped: WatermarkJob, queue: "thumbnails").perform_async(serialized_hash)`. 3. Sidekiq returns a `jid`, which Active Job stores as `provider_job_id`; `perform_later` itself returns the job instance, or `false` if enqueuing failed. 4. In the worker, `Sidekiq::ActiveJob::Wrapper#perform` calls `ActiveJob::Base.execute`, which deserializes the hash, loads the photo again through GlobalID, runs the Active Job callbacks and finally `WatermarkJob#perform`. The `wrapped` key is why the Web UI shows `WatermarkJob` rather than the wrapper's name, and why the wrapper's options are merged with `WatermarkJob`'s own `sidekiq_options`. ## What each path gives you | Concern | Active Job with `:sidekiq` | Native `Sidekiq::Job` | |---|---|---| | Enqueue call | `perform_later`, `set(wait:)`, `perform_all_later` | `perform_async`, `perform_in`, `perform_bulk` | | Arguments | Active Job serializers: records via GlobalID, symbols, times | JSON-native values only; strict mode raises otherwise | | Error rules | `retry_on` / `discard_on` in the job, then Sidekiq's retries if the error escapes | Sidekiq's retry options and blocks only | | Sidekiq options | `sidekiq_options` still available | `sidekiq_options` | | Switching backend | change one config value | rewrite the jobs | | Cost per job | extra serialization and callback work | lowest overhead | Sidekiq's own README measures that cost: in its benchmark Active Job jobs processed at a clearly lower rate than equivalent `Sidekiq::Job` classes, the gap coming from argument deserialization and callbacks. For most applications that is noise next to the job's real work; for millions of tiny jobs it is not. ## Rails 8.1: whose adapter is it? For years Rails shipped its own `ActiveJob::QueueAdapters::SidekiqAdapter`. **Rails 8.1 deprecates it**, with a warning that it will be removed in Rails 8.2 and that `sidekiq` 7.3.3 or later provides the adapter instead. The sidekiq gem's Rails integration loads its own adapter file, which removes Rails' constant and defines a replacement under the same name. The consequences: - an app on Sidekiq 8 keeps `queue_adapter = :sidekiq` unchanged and gets the gem's adapter without a warning; - an app pinned to an older Sidekiq gets the deprecated built-in adapter and the warning; - the payload class is now `Sidekiq::ActiveJob::Wrapper`; the older wrapper constant survives only as an alias so jobs already sitting in Redis still run. The 8.1 change does not mean Rails stopped supporting Sidekiq; ownership of the adapter moved to the gem. ## Traps at the boundary - `perform_later` returns the job object (or `false`), never a `jid`; read Sidekiq's id from `provider_job_id`. - `sidekiq_options queue: "x"` on an Active Job class has no effect on routing, because the adapter always passes the job's own queue name; use `queue_as`. - `sidekiq_options retry: 3` on an Active Job class does apply: it limits the Sidekiq-level retries that start when an exception escapes. - An app that pins an older sidekiq gem on Rails 8.1 sees the deprecation warning on boot, which is the cue to upgrade the gem rather than to rewrite jobs. ## Choosing between them - Prefer **Active Job** when jobs pass records, when the team wants one job API across backends (Solid Queue in one app, Sidekiq in another), or when jobs rely on `retry_on`, callbacks or continuations. - Prefer **native jobs** for very high-volume, small jobs where per-job overhead shows, or when you need Sidekiq-only features such as iterable jobs. - Mixing is fine: a stock-photo site might keep mailers and record-oriented jobs on Active Job and run its thumbnail fan-out natively.
- If a WatermarkJob raises and declares no retry_on, who retries it?The exception escapes `ActiveJob::Base.execute`, so it reaches the `Sidekiq::ActiveJob::Wrapper` job and Sidekiq treats it like any failed job: it goes to the retry set with Sidekiq's backoff and ends in the dead set if every retry fails. Active Job's own rules only apply when the class declares them; then those retries are fresh pushes that never appear in the Retries tab.
- Can one app run both styles against the same Sidekiq process?Yes. Both styles push ordinary Sidekiq payloads, so one `bundle exec sidekiq` process listening on the right queues runs `ApplicationJob` subclasses through the wrapper and native classes directly. Teams often keep Active Job as the default and move only the hottest, simplest jobs to `Sidekiq::Job`.
- Saying Rails 8.1 dropped Sidekiq, so jobs must move to Solid Queue
- Claiming perform_later returns Sidekiq's jid rather than the job instance
- Believing Active Job classes cannot use sidekiq_options at all
- Assuming native Sidekiq::Job arguments get GlobalID serialization too
- Thinking Sidekiq runs the ApplicationJob class directly with no wrapper
Assumes Rails 8.1 with the sidekiq 8.1 gem; Rails 8.1 deprecates its bundled :sidekiq adapter in favour of the one sidekiq 7.3.3+ ships.