Sessions & Cookies

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys Tech video today or uh pseudo pseudo Tech video today and we're going to talk about something really really important about the internet specifically sessions and cookies so if you want to understand the internet you have to understand what those two words mean and that's the purpose of this video today if you haven't seen the first video on HTTP basics please watch that first remember that HTTP is a stateless protocol and if that sentence doesn't make sense to you just check that out real quick and come back so sessions cookies fundamental stuff everyone should understand this and let's do it I like coffee you probably like coffee I go to Starbucks maybe twice a week right now I have a very stateless interaction with Starbucks every time I go I check out the menu order my drink they make me my drink I pay them a little bit and I get it and I'm happy if I go back 3 days later they don't really remember what I ordered 3 days ago right I'll just order again look at the menu again and this time I'll just get a latte so every single interaction I have is stateless with Starbucks go in order get my coffee so hope that's clear let's just think about how would we design a system so our interactions with Starbucks could be a little more stateful and what does that mean like how could Starbucks remember what I ordered last time or how could they remember my 10 favorite drinks how would you design a system like that lucky for us Starbucks has already solved this problem and the way they solved it is exactly how sessions and cookies work on the internet so the way they've solved it is they give you a Starbucks card that you carry with you and what that Starbucks card actually does is give you a very stateful interaction with Starbucks and we're going to talk through that so what exactly is a Starbucks card anyways this is not a real Starbucks card it's just a card that I have but what does this really mean this thing right here actually means two different things right when you carry this card around this is your identification for Starbucks right but for Starbucks they've already made an account for you to track all your stuff like the last drink you ordered your top 10 favorite chocolate drinks two parts right this is what you carry around your identification but it matches a thing on the Starbucks server where they're tracking all your info so for this whole example this whole example is kind of just analogous to the internet right I'm actually the client ordering my drinks at Starbucks I'm like a web browser for the internet and Starbucks is kind of like a web server servicing my requests so this ID card the ID card that you carry with you this identification that the client always carries that's called a cookie so if we have our cookie right the opposite thing to make this cookie even useful is the session which lives on the server so Starbucks is tracking a lot of different sessions for all their different coffee drinkers so why this cookie is important because it's used to match up with the right session this is my identification so Starbucks knows to retrieve my session hope that made sense all right just going to repeat myself again to make it extra extra clear I'm the client Starbucks is a server this identification card or cookie is always client side if you open up your browser if you have Chrome developer tools or anything you can see every single cookie that your browser has saved for all the different websites you visited so it's always client side and the session is sometimes but not always server side if I go to Starbucks I'm going to show them this first right I'm going to show them my identification so they can get what whatever information they need about me it's the same thing with web browsers every single HTTP request made by your browser sends a cookie along so the server can do something smart with it all right so I hope everyone's slowly digesting this but you can see how the Starbucks card and Starbucks tracking my favorite drinks that's kind of giving statefulness to my interaction with Starbucks right at the beginning of the video I told you my interaction was stateless order a drink on Monday order a drink on Tuesday order a drink on Wednesday but once I have statefulness my experience gets much better hopefully this is uh the most important sentence to understand and if you understand this sentence now you understand sessions and cookies sessions in cookies are what makes HTTP stateful I'll just I'll just say it one more time to maybe it'll sink in but remember from the first video HTTP is naturally a stateless protocol sessions and cookies make it stateful okay guys one last note before we wrap it up but as you said cookies always client side remember that when you hear the word cookie just think client side and the browser is handling your cookies right but I mentioned earlier that sessions where are sessions stored normally they're stored on the server but actually Sometimes some applications actually choose to store session information on the client as well and let's just talk about that real quick for any web developers out there um I'm sure you know what rails is probably one of the top if not the most popular web framework uh in existence or maybe right now but by default if you use the latest rails they actually store the session on the client by default and this is a little different from what's conventional because conventionally sessions have always been stored on the server what's what's the advantage of storing session information on the client well the one major thing that it provides is that it's really really fast right if your session information is on the server you have to present this first the server does a lookup in its database of all your stuff and it gives you your 10 favorite drinks but if the session is stored on this client it's actually right there always right it's just really fast so one good thing about storing sessions client side is that it's really fast now the main disadvantage of storing information on the client side is lack of space right lack of space if you store a session with the cookie you only get 4 kiloby of space it's like if you have a really complicated stateful logic like maybe you're tracking shopping cart your preferences all this fancy stuff and it can't fit here then you would have to actually put all that stateful information on the server all right guys that's it end of the video hopefully it was intuitive to understand if you ever come across these terms before I would just think back to the Starbucks analogy getting a Starbucks card to use at Starbucks is just like using a cookie and presenting it to a website all right so sessions cookies that's what makes the internet stateful and you have to understand what those two things are so hope this video was helpful please like comment subscribe all that stuff ask me any questions in the comments and have a great week all right
Info
Channel: Dave Xiang
Views: 144,008
Rating: undefined out of 5
Keywords: computers, software, software engineering, software engineer, development, coder, coding, programming, internet, sessions
Id: 64veb6tKTm0
Channel Id: undefined
Length: 7min 29sec (449 seconds)
Published: Sat Oct 08 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.