Summary notes created by Deciphr AI
https://podcasts.apple.com/au/podcast/the-real-hidden-cost-of-a-request/id1330350799?i=1000638395855Hussein Nasser delves into the intricate journey of a request from a front-end to a back-end server, emphasizing the critical steps involved and their performance implications. He outlines six key stages: connection acceptance, data reading, decryption, request parsing, decoding, and processing. Nasser highlights the hidden complexities and costs at each stage, such as the overhead of decrypting data and parsing protocols like HTTP. He stresses the importance of understanding these processes to appreciate the backend's workload and efficiency, setting the stage for deeper exploration in future discussions.
"I want to take you on a journey of what we call a request sent from a front end to a back end server."
"There are so many steps that this logical object that we described that is called request goes through before we land in a process or a thread that actually handles the request, whatever that means."
"A common question that we get on the back end is like, how many requests can you handle per second? You know, that's a very difficult and frankly very overloaded question to answer, because what do you mean by handle?"
"If we understand what happens to the request from the moment it is incepted, pretty sure that's not a word in created on the front end until it is arriving in the backend. There is these steps that is goes."
"Appreciating these steps makes you better aware of the performance implications of what you're doing."
"We often use. We mean the actual processing of the request when we say that. But even then, we really don't know how much that factor in."
"Once I go through these steps, you understand, like, wait a minute. Yeah, what does it, what does handle really mean?"
"This is an article I wrote on medium. It's called the journey of a request, the backend. I'm not going to read it, but I like to use it as a reference."
"I'm going to have it in the description below. I want to use it as a reference, especially for the graphic that I developed here."
"And appreciating these steps makes you better aware of the performance implications of what you're doing."
"It goes back to what we this word that I used, handle. You know, a common question that we get on the back end is like, how many requests can you handle per second?"
"The first step which is the acceptance not really of a request, but of the vehicle of the request which is the connection."
"You cannot send really request Willy nilly to the backend."
"This pipe is called the connection. And the vehicle is what we call the transport protocol, you know."
"In order to create a connection your connection must be accepted. And boy that is not a trivial task to do."
"A lot of proxies and web servers you know, their bread and butter is the connection. Acceptance, how can I accept you?"
"You can have one process accepting or a 10,000 process accepting."
"Read now that I have a connection that has a bunch of raw bytes coming at me. Raw bytes because yeah connections, you know in networking we only send bytes."
"There is no HTTP in networking like at low level. You look at this pipe coming, the data coming from the neck, there is no regular HTTP. All this your JWT, they don't exist. There are just a bunch of bytes."
"Then we need to most probably decrypt this data because it is most probably encrypted because you probably use TL's because if you're using HTTPs you have to use TL's and everything is encrypted."
"So now you read something, you decrypted it as another cost."
"Only then you can actually start forming coherent representation of what you call, you know, the request or the backend and, and the front end agree to be what a request really is."
"It's an abstracted away, you don't really need know about it. And that's the sad part. That is the scary part that we don't know about the most of the stuff that is going on here."
"And, and the sad thing, again, it's all hidden. When I say hidden, it's really tucked away, you know, and we don't appreciate it anymore."
"And then after we parse that is now I have plain text bytes that says, oh, there is a get and then slash about, then space, and then there is the protocol, and then get, and then, oh, okay, okay, there's, I started understanding, you read, read, read, and you start parsing."
"You really read and start understanding this protocol until you get a unit of what you call a logical request."
"Let's create a request object that's a node, for example, or c, or c sharp. You're going to create a dot, a request object stored in the heap and store the address, family and the information, the client and the IP address."
"There's always a cost to all this stuff. And, and the sad thing, again, it's all hidden."
"This gets more complicated with HTTP two because there are the protocol itself, unlike htbo eleven, which is a text only, this is a binary stuff. There is a stream. There's so much stuff there at the protocol level."
"Now that you received a request, the request might have headers, might have, well, that's not really always the case, but it can have a body if it's a post request."
"That's why we need a decoding step where, okay, let me actually understand what this thing is, you know, and let me build."
"That's why you install the Node.js, you install the body parser, or the Express, you do express that does JSON, you execute a function to actually execute that because there is converting the bytes, that is the body that is JSON to actual JSON object is not cheap."
"Well, it might be a little bit cheaper in JavaScript, but other languages go, boy, they suffer. No, I've seen some libraries, some C library really suffer with JSON, you know, serialization and deserializing."
"That's what it is. Serialization, deserialization. Let me make sure, actually, I got my ducks in a row. Yep, that's it."
"This is also UTF-8, right? Remember, even if you're sending in text, even if you're sending text, I need to know if this text is ASCII or UTF-8 because the byte representation really changes."
"That's part of the parsing. I mean, a lot of people might just say, okay, these two are really the same."
"The final step is actually to process this thing. Actually, now that I have request. Now it's mostly user code. They say, all right, let's go ahead and take this sucker. Oh, you want to do, I don't know, get the list of user by id. Okay, I know what to do. Let's establish a connection to the, back into the database, to the Postgres database, send a SQL asynchronously."
"Wait. And then me, while I'm waiting, while I'm awaiting. Right. I can do another of these cycles. I can, again accept, I can read, I can decrypt I can parse. That's why the backend, even with a single thread, if it's doing mostly asynchronous work, oh boy, can do so much, so much, so much work."
"Do you have, if it's a CPU heavy, do you split this into its own thread or its own process to execute that while your main thread becomes, you know, alleviated to do other stuff?"
"So I'm going to stop here making this video a little bit short and maybe in future videos I'll go deep into each one of them. I think because you need to, we need to pay respect to each of these steps. You know, each of these steps really deserve really more details and boy I can go into a lot of details sometimes, you know, and you guys actually let me know about this."
"All right, see you in the next one. Goodbye."