Scaling Kubernetes pods with KEDA based on Amazon SQS queue depth
- Core Premise: Traditional CPU/memory metrics fail for asynchronous, queue-based workloads; SQS queue depth (backlog) serves as the true scaling metric.
- Architecture Flow: Producers publish messages to Amazon SQS -> KEDA polls queue backlog metrics -> KEDA updates Kubernetes Horizontal Pod Autoscaler (HPA) -> HPA scales consumer deployment pods dynamically.
- AWS Authentication: Recommends granting minimal IAM permissions (
sqs:GetQueueAttributes,sqs:ReceiveMessage,sqs:DeleteMessage, etc.) to workers via IRSA or EKS Pod Identity. - Replica Calculation: KEDA determines total outstanding messages (
ApproximateNumberOfMessages+ApproximateNumberOfMessagesNotVisible) and calculates desired pods viaceil(outstanding messages / queueLength), bounded byminReplicaCount(allows scale-to-zero) andmaxReplicaCount. - Key Configuration Parameters:
queueLength: Target number of messages per pod.activationQueueLength: Threshold to trigger initial scale-up from zero.cooldownPeriod& HPAbehavior: Manage scale-down delay and stabilization windows.
- Troubleshooting & Production Advice: Tune
queueLengthbased on consumer throughput, decide whether in-flight messages count (scaleOnInFlight), and configure fallback replicas for operational resilience.