What is the best way to handle scale down operatio...
# ask-ai
e
What is the best way to handle scale down operations with ECS? I know that livekit will automatically drain the worker while allowing the existing processes to finish however ECS has a maximum timeout period of 120 seconds before it kills the instance in which all calls in that instance will end abruptly. Advise me on the best way to go about this so that the existing calls will finish before ECS can kill the instance
t
Thanks for reaching out, Josh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The optimal way to handle ECS scale-down with LiveKit is to adjust the drain_timeout in your LiveKit worker configuration to about 90–110 seconds, ensuring there's a buffer before ECS enforces its maximum 120-second termination window. This lets LiveKit enter draining state, stop new sessions, and let existing calls finish within the ECS grace period. • In your task definition, set
stopTimeout
to 120 seconds to use the full ECS grace window. • Set
drain_timeout
(in worker options or environment variable) to 90–110 seconds, providing time for in-progress calls to end gracefully. • For critical workloads, slow down scale-down operations with conservative autoscaling cooldown periods to give more time for workers to drain without being terminated abruptly. Be aware that ECS's 120-second termination is much shorter than the default LiveKit drain period (typically 30 minutes for voice agent apps). If your application often has longer sessions, consider designing for session handoff or look into platforms like Kubernetes, which permit longer termination grace periods (up to hours). Calls ongoing beyond the 120s window will be ended by ECS. Summary of recommended settings and considerations: • drain_timeout: 90–110 seconds • ECS stopTimeout: 120 seconds • Autoscaling: Conservative downscale cooldowns • For longer sessions: Explore session handoff or alternative orchestration like Kubernetes Sources: Worker options | LiveKit Docs | Deploying to production | LiveKit Docs | Deploy to Kubernetes | LiveKit Docs