KEDA in depth
Example: scaling invoice workers on a queue
Example: a hypothetical company processes uploaded invoices through a queue in RabbitMQ. Workers run as a Deployment. A ScaledObject targets that Deployment with a RabbitMQ trigger based on queue length per replica, with minReplicaCount of zero and a sensible maxReplicaCount that the downstream database can handle. Credentials come from a TriggerAuthentication that references a Kubernetes Secret populated by the External Secrets Operator. When invoices arrive in the morning, KEDA activates the Deployment from zero to one replica and the HPA it manages scales further based on backlog. In the evening the queue empties, and after the cooldown period KEDA scales the workers back to zero. Karpenter then removes the nodes that became empty.
Key settings to understand
- pollingInterval: how often KEDA checks each trigger; shorter means faster activation but more load on the event source.
- cooldownPeriod: how long to wait after the last activity before scaling to zero; it applies only to the zero step, while scaling between one and the maximum follows HPA behavior.
- minReplicaCount and maxReplicaCount: bounds for the workload, with zero allowed as a minimum.
- fallback: a replica count to use if the scaler cannot read its metric, so an outage of the metrics source does not scale the workload down.
- advanced HPA behavior: pass-through settings for scale-up and scale-down policies on the generated HPA.
- Pausing: an annotation pauses autoscaling during maintenance or incidents.
ScaledObject or ScaledJob
| Resource | Best for | Behavior |
| ScaledObject | Long-running consumers and services | Scales replicas of a Deployment, StatefulSet or custom resource |
| ScaledJob | Long or uneven tasks such as video processing or report generation | Creates Kubernetes Jobs for pending work, so a scale-down never kills a task midway |
Security and operations
Prefer workload identity over static secrets where supported: TriggerAuthentication can use pod identity providers for AWS, Azure and Google Cloud. Give scaler credentials read-only access to queue metrics, not permission to consume or delete messages. Monitor KEDA's own metrics and the generated HPA's events, and alert when a scaler reports errors, since a broken scaler silently stops scaling.
How to evaluate KEDA autoscaling
- Backlog age: how long the oldest message waits, the measure users actually feel.
- Activation delay from first event to first processed item, including cold start.
- Replica count over time against queue depth, to spot lag or flapping.
- Idle capacity and compute spend during quiet hours.
Common mistakes
- Creating a separate HPA for a workload that KEDA already manages, causing the two to conflict.
- Scaling to zero for latency-sensitive services where a cold start is unacceptable; keep a minimum of one, or look at the KEDA HTTP add-on with care.
- Maximum replicas higher than a downstream database or API can handle.
- Thresholds set without load testing.
KEDA extends the Horizontal Pod Autoscaler, pairs with node autoscalers, and supports FinOps goals on Kubernetes. It also suits AI pipelines such as document processing or batch inference workers. We set it up in our Kubernetes and cloud cost optimization and FinOps services.