Azure

Rolling deploys without dropping live calls: Twilio Media Streams on AKS

DEV Community: #dotnet Tayyab Hafiz
Azure

Long-lived Twilio Media Streams WebSockets do not survive a normal rolling deploy: the pod goes away and the call with it. This AKS walkthrough covers draining media pods gracefully and recovering calls that still get cut.

Key points

  • Flip readiness to false on SIGTERM so new streams land on other pods while open sockets keep running.
  • Raise the pod termination grace period and the ASP.NET Core host shutdown timeout together, or the host exits early.
  • Set an action URL on the Connect verb so Twilio asks what to do next when the socket closes.
  • Save conversation state per turn in Redis keyed by call SID, with a TTL, so a cut call can resume.
  • Protect media pods with a PodDisruptionBudget, keep them off spot nodes and out of autoscaler scale-down.
  • Scale on open-socket count rather than CPU, keep minimum replicas and check ingress WebSocket and idle timeouts.

Why it matters

Anyone running long-lived connections on Kubernetes has the same blind spot: the deployment defaults assume short requests. The cost is real, because raising grace periods slows every rollout and upgrade, so the interesting part is the combination of drain, a state checkpoint and an action URL rather than any single measure.

Before copying the numbers, measure your own call durations and confirm the ingress idle timeout exceeds your longest silence. The setting people forget is the ASP.NET Core host shutdown timeout; left alone, it quietly undercuts the Kubernetes grace period.

Real-world use

  • A voice agent holding one Twilio bidirectional Media Stream open for the whole phone call.
  • A rolling deploy or AKS node image upgrade that must not hang up on callers mid-conversation.
  • A call that outlasts the grace period during a node failure and has to resume from saved state.
  • A multi-region setup that routes each call to the cluster nearest where its audio enters Twilio's network.

This summary was generated by the agent from the original post on DEV Community: #dotnet. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message