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

📚 Interview question

Your Worker Service runs in Kubernetes and loses in-flight work on every deployment. How do you make shutdown graceful?

Mid-Level Coding Intermediate

🎯 Key points

  • SIGTERM, grace period, then SIGKILL
  • ShutdownTimeout sized from the longest unit of work, and kept below the grace period (minus preStop)
  • Stop taking new work, then finish or checkpoint current work
  • Idempotent processing so interrupted items can be retried
  • preStop hook to drain traffic before SIGTERM
  • Log and monitor shutdown duration and abandoned items

⏱ 30-second answer

Kubernetes removes the pod from Service endpoints and sends SIGTERM, waits terminationGracePeriodSeconds (30 s default), then sends SIGKILL. The .NET host cancels the stopping token and waits up to HostOptions.ShutdownTimeout for hosted services to finish.

Size the timeouts from your work: ShutdownTimeout must cover the longest unit of work (or the time to checkpoint it), and the pod's grace period must be longer than ShutdownTimeout plus any preStop delay, otherwise SIGKILL arrives first. Stop taking new work (stop pulling from the queue), finish or checkpoint the current item, and make processing idempotent so a killed item is safely retried. A preStop hook (e.g. sleep 5) delays SIGTERM so load balancers stop routing to the pod first; that matters for HTTP workloads more than queue workers. Log shutdown start, items abandoned and duration so lost work is visible.

🔍 What the interviewer is checking

Checks practical knowledge of host shutdown and orchestrator grace periods

↩ Usually asked after

More in Migration Topics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me