What Are Session?

What Are Session?

ยท

3 min read

I'm fairly certain the average netizen has heard "the internet never forgets" somewhere, that is true yet false at the same time; true in the sense that your digital footprint is hard to erase and false in the sense that the internet is largely stateless. What we mean by statelessness is that every time you submit a request to the internet, the internet perceives it as a fresh request. A request can be in the form of creating a post, updating an item, reading an item, or deleting an item.

Even if you just made a request 2 seconds ago, the internet doesn't remember, if you make a request now, the internet will perceive you as a first-timer ๐Ÿ˜…. If you're someone who thinks he/she is forgetful, well, consider yourself outdone ๐Ÿ˜‚. Now I know you're curious as to how you're able to navigate back and forth between pages and see what you last saw or did, that's where your browser plays a huge role. Things like caching, cookies, and sessions, among others, make you believe the internet actually remembers you.

To further drive home this point, you'll recall that there are some forms that if partially filled out before you close your browser is totally wiped by the time you reopen your browser thus forcing you to refill the form from the beginning; that's the internet's default behaviour when the browser isn't lending a helping hand ๐Ÿ˜“.

Today we'll briefly look at one of the ways in which the browser is able to assist the internet in ensuring you have an amazing experience; we'll be looking at sessions ๐Ÿ˜. When you're accessing a platform (with a specific timeframe), you create a session, the session literally tries to associate all actions carried out within a timeframe to one netizen, it does this by grouping your data and behaviour in a way that helps it follow your digital trail.

A man showing a little girl images on a laptop

A relatable explanation

To make an example, have you ever been in a situation where you input your phone number in the first "page" of a form (note that I'm using the term "page" loosely here despite writing about SPA recently just so you can get the idea) and when you're taken to other pages of a form or the platform, your phone number input is prefilled in other parts despite you not being the one who input it?

It's somewhat difficult to show the difference between session and other persistent storage features that the browser implements, however, one feature you shouldn't mistake for session is the one where you use your browser's suggestion and it prefills the rest (especially in Google Chrome). Session is different from the above because with session it's only details you input that's carried forward, no extra difference from what you inputted yourself is prefilled for you in subsequent pages.

Sessions are able to link data within a specific timeframe (that we software engineers can adjust) using session ID, this is why you can copy a browser link directly from the tab (where it's way longer and filled with some gibberish), paste it in another browser, and still not be shown the exact same thing. Sessions are really useful for backend development as they let us use and pass data across many parts of an application without requesting for the data more than once from the netizen or having to call a database repeatedly.

Picture of a girl walking with balloons

Finally

Sessions shouldn't be overly relied upon without doing some research. Sessions aren't very secure as such, you shouldn't keep sensitive data there, sessions are pretty handy for minor stuff that helps user experience and it's very useful in fetching data from the frontend without making unnecessary calls to a database.