📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you shut down an ASP.NET Core service in Kubernetes without dropping in-flight requests during a rolling deploy?

Senior Architecture Advanced

🎯 Key points

  • SIGTERM and endpoint removal happen concurrently; propagation lags
  • Fail readiness on ApplicationStopping
  • preStop sleep of 5–10 s before shutdown begins
  • HostOptions.ShutdownTimeout for in-flight requests (30 s default)
  • BackgroundService loops honour the stopping token and finish or checkpoint their current item
  • terminationGracePeriodSeconds > preStop + shutdown timeout
  • Verify with load during a rolling deploy

⏱ 30-second answer

On SIGTERM, Kubernetes removes the pod from endpoints and signals the container at roughly the same time, but endpoint removal takes a few seconds to reach every node and ingress. So I fail readiness as soon as ApplicationStopping fires and add a preStop sleep of about 5–10 s so routing catches up. I let the host finish in-flight requests within HostOptions.ShutdownTimeout (30 s by default since .NET 8), and keep terminationGracePeriodSeconds longer than the preStop delay plus the shutdown timeout. Background services must honour the stopping token. I verify with a load test during a rolling deploy: zero 5xx.

🔍 What the interviewer is checking

Checks understanding of SIGTERM, endpoint propagation delay, preStop hooks and HostOptions.ShutdownTimeout

↩ Usually asked after

More in Reliability Patterns

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me