0:00 Today, we're gonna take a look at implementing 0:02 graceful termination in a 0:03 Node.js application. Now, the idea of graceful termination 0:07 is that when we run our application in an environment like Kubernetes, for 0:11 example, when we run a delete pod command to delete 0:15 our 0:15 application that's running in a Kubernetes cluster, for example, we're scaling 0:19 down our deployment, we send a delete pod 0:23 command to our cluster. That's gonna send a SIGTERM 0:27 signal to the underlying Node.js process that our 0:30 application is running. 0:33 Now, by default, in a Node.js Express server, in this case, 0:37 a 0:37 Nest.js application, this is gonna cause the application to 0:41 immediately shut down even if we have in-flight pending 0:45 requests that have not completed yet. 0:48 So what we can do is implement graceful termination easily 0:52 in our application so that we actually track each and every 0:55 request that is sent to our application, so when we receive one of these 0:59 SIGTERM events, we can actually await the requests 1:03 to finish up to a certain timeout and then close our server 1:07 afterwards. So in this way, we shut down our server gracefully, let 1:11 all pending requests complete, so we aren't left with any 1:15 stale work, and our services are essentially idempotent in 1:19 this way because we're gonna allow them time to complete their 1:23 requests before closing down the application. 1:26 So I'm super excited to jump into today's lecture to learn how we can implement 1:30 this graceful termination. Let's go ahead and jump in. 1:33 I'll see you there. 1:34 So to get started, let's go ahead and create a new Nest.js 1:38 application, which we'll use as a demonstration 1:41 throughout this 1:42 lecture 1:43 to show why we need graceful termination when running our 1:47 Node.js application in an environment like Kubernetes or really 1:51 any ecosystem where we receive SIGTERM events from the
The rest of the transcript is for members.
Sign in