Hey Arpit, I've been following your channel for a while now and I've seen all your videos on system design and related concepts - I'm a huge fan! This video on building a TCP server is just amazing, and I love how it shows the practical side of things. It's so helpful to see real-world examples like this. I'd be thrilled if you could continue creating more content in this style. Keep up the fantastic work, and thanks for sharing your expertise with all of us! 🙌👩💻🚀
Damn, how can someone demystify the concept of "writing your own", which sounds quite scary, so beautifully. While watching this video i was glued to my computer screen. Thanks Arpit
I have never really thought, infinite for loop or loop is a valid usecase without knowing that every single day I am using it in interacting with each and every web server. Wonderful video... felt like my weekend was productive by watching this video, Thanks.
awesome video!! I was expecting you to talk about I/O multiplexing as well when you were talking about multi-threaded servers, and indeed you did in the 24th minute!!
yeah. IO Multiplexing is great; it just minimises synchronization and threading overheads. Unfortunately could not go in depth of implementation, given I cover it in my Redis course. Had to draw the line. Glad you still found the video interesting :)
@@AsliEngineering loved it!!! 👏👏 actually I was aware of I/O multiplexing when we used RedisStackExchange library in one of the projects.. but after watching your video, I really did a deeper dive to understand how things work under the hood!
@@AsliEngineering your videos are the second best thing on youtube after Hussein Nasser's videos. Not comparing, just putting in chronological order. 😁😁
@@TheNayanava Hussein is next level. I really wish I could go as deep as him. He actually pointed into Postgres source code. That's commendable, given how complex the codebase is.
Arpit, Its a great and informative video. Really appreciate your efforts. It would have been good if you have included what is socket in tcp connection.
I always had this curiosity in the head that how multiple connections are handled in prod but kept procrastinating untill today i watched this and went into dissecting them.
Nginx is not multithreaded. It is multi-process (1 process per core) and uses asynchronous I/O (with epoll) where a single process can accept and process multiple connections and requests.
There are very less useful videos on GoLang. I have started following you one month back and I can see how engineer should have thinking process. Also I am DevOps engineer and started learing golang just for my interest. Thank you for this video. Keep it up.
Hey Aprit, amazing videos, i have started watching your videos recently. Just a suggestion as a viewer, could you declutter notes that you use for teaching, only diagrams and one words are enough, you are already explaning everything on top of it. It feels redundant information on the notes and blocks the important information if you would have written.
Hii Arpitbhai, Understood how multi threaded web server works. Still I have one doubt how listen and accept works. Like lets say we invoked the listen on some particular port how the process is listening like how it actually listens internally that as soon as client connects it accepts the request and how read write actually works. I know the concept of pipe but as far as I know its for local processes only. I hope you got my doubt.. Thanks for the nice explanation.
How many connections a server can handle concurrently? I guess conn object return by listener.accept will be different for each curl request ? or that conn object is a shared resource between threads.
Hey Arpit, awesome video that explains the working of a server. Just curios to know 1 thing. In your example from the client side you made 2 requests almost simultaneously and while 1 connection got accepted, what actually happens to the other client request till the server is busy? Since it kept on waiting for the server to get freed up…do we have some queue that keeps track of all requests that has been made to the port? Or internally do we keep on trying from the client side till some TTL window where if it gets crossed the client will close the conn from its side saying server took too long to respond or something like that?
Thats what backlog queues are for, on starting a socket connection you can determine how many connections can wait in the backlog. I think when the queue is full the connections are simply discarded.
Arpit sir just a small doubt I have here is that as if you are saying that the code is single threaded server, because of which multiple requests are not able to process at the same time they are waiting for 1 process to complete, my question is these process which has been started, as they are waiting you mentioned but there is no such queue in which they can store, so how currently these values which are not yet executed are getting stored basically their internal workings I am concerned about, if there is no data structure used then why the process is not leading to crash of the applications or Is GO Language is handling these internal working ?
@@AsliEngineering Which VI plugin's you use, as the one by default in VScode is very sluggish. Do you have any cheatsheet for the VI which you use frequently.
What do you mean every number? Also, creating large number of threads has its own overheads - memory overhead because of local thread stack and scheduling overhead for the OS/kernel.
If number of concurrent requests are more than the number of threads present in thread pool, then the extra requests will have increased response time or the request would get dropped?
masiha h re tum bro... ek request h bro, kyoki maine kabhi kaam nhi Kiya h distributed systems me to kind of imposter wala feeling aata hai apply karne me. thoda kuch bta do bro k ek project agar scratch se banate ho to kya expected hota h ek 5-6 yr experienced bande se. please 🙏🙏 8
What I implemented is a multi-threaded TCP server. So long as challenges are concerned, they are exactly what you'd face when you have multiple threads - synchronization.
Hi, how consistency is maintained across multiple threads? assume we've written a class that has a static counter which gets increased after every call. In a single threaded scenario the value of counter would remain consistent after n calls are made. But how can we make sure this is followed in multi-threaded servers? Assume the code you've written has a global counter variable and this variable gets increased in the 'do' function. Now in multi-threaded environment how we can make sure that the state of counter is correct after n parallel calls are made.
@@AsliEngineering okay. How is this implemented in production? Let's say I've spring boot local server, and there's a static variable in a different class that I want to a update. I've a REST controller exposed via get/post. Now in my local I'm not creating multiple threads, spring boot automatically serve multiple requests. So how to apply lock in this scenario, and where to put locking code. Thanks