CloudJod

ArchitectureCTO

Can background workers scale on queue depth instead of CPU?

The answer

Yes: scale a worker on the length of its Redis queue. A worker idle at low CPU while jobs pile up is the case CPU-based scaling gets wrong; the number of waiting jobs says directly how many workers are needed.

Why doing it by hand hurts

Wiring that up yourself means a metrics exporter for the queue, an autoscaler that reads it, cooldowns so it does not flap, and care that scaling down never kills a worker mid-job. It is a small system of its own to run.

How CloudJod handles it

Autoscale beside the worker on the Processes tab, or cloudjod ps scale APP worker queue --max 5 --database jobs --key queue:default, runs one copy for every so many jobs waiting (50 unless you say). With a minimum of 0, no copy runs while the queue is empty, and the first job starts one within half a minute. Copies are added after half a minute of need and taken away one at a time, five minutes apart, each given time to finish. Scaling on memory is there for workers that hold state, never below one copy. The trade-offs: it reads a list in your own Redis or Valkey database (as Sidekiq, Celery, BullMQ and RQ keep their queues), and autoscaling is on the Pro and Enterprise plans.

queue:default120 waiting 0 waiting 1 copy for every 50 waiting worker worker worker between 0 and 5 copies taken away 5 minutes apart
Jobs pile up in the queue, a copy is added for every 50 waiting, and as the queue empties the copies leave one at a time.
Under the hood

the queue's length is one LLEN against your own database. Why are copies added after half a minute but taken away only five minutes apart?

Read more in the documentation