A developer implements HTTP Keepalive for Axios in a Node.js project to improve performance. The session covers defining configuration interfaces, setting timeouts, managing socket pools, and creating reusable HTTP and HTTPS agents to reduce connection overhead.
Length 12:05
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #nodejs #axios #http-keepalive #typescript #tcp-handshake #software-engineering #web-development #backend #api-performance #coding-tutorial
0:00 All right, so to go ahead and get started, we wanna begin with HTTP 0:03 Keepalive. Now, before we start with the implementation, 0:07 let's 0:07 discuss a bit about what TCP Keepalive is. 0:11 Now, TCP, Transmission Control Protocol, is what 0:15 actually establishes a connection whenever we launch an 0:19 HTTP request to another service or webpage 0:23 using Axios, which is the client library we're using, 0:26 but same 0:26 thing with on a browser. Whenever we make HTTP requests, 0:30 we're always 0:30 establishing a TCP connection, and this handles the 0:34 transfer of data from the client to the server in a 0:37 controlled, reliable way. Now, importantly, in this 0:41 TCP protocol, when we establish a connection, there is 0:45 what's called a TCP handshake, which essentially the 0:49 client, when it wants to talk to a server, it has to make 0:54 a request to that server to open up the connection before it 0:58 can actually start sending data. Now, as you can imagine, 1:02 that time it takes to send the request to the server to 1:05 ask it to open up the connection costs a lot of time. 1:09 It's a total round trip to the server. 1:11 And what HTTP Keepalive allows us to do is 1:15 reuse a connection that we've already established with that 1:19 server at the beginning of the connection for another 1:22 request so that, for example, if we send multiple re- requests to the 1:27 same server, we don't have to reopen the connection and 1:30 spend all that time going back and saying, "Hello. 1:33 Can we open up this connection to send data?" Instead, the connection is 1:37 already open, and we save that entire round trip to the server, 1:41 which can really add up to amazing performance benefits, 1:44 especially if your app is very chatty and making many 1:48 requests to the same endpoint. 1:52 And so by default, Keepalive is not enabled on the
The rest of the transcript is for members.
Sign in