This article was migrated from my college notebook.

As an undergraduate student in CS, I’ve always had this question: Why that particular thing on my browser is called a Cookie? 🍪

Until randomly, on a Network Security class, a brilliant lecturer told me a story:

Once upon a time, there was a king.

The king was so wise, so kind, so powerful. Everybody loved the king.

Most of the time, the king sat on his throne and people would line up standing, waiting to tell their problem and personal affairs so that the king may help them.

But there is one catch: the king is quite old, and he has long-term memory loss. Added with so many people he needs to meet daily, he would quickly forget people or problems he has faced yesterday and all the days before.

This condition is fine for most of the people that only bring small-sized problems. But for another people with adequately complex & big problem that spans days or weeks, this became an issue as long-term structured communication was basically impossible.

Then a person came up with smart idea: on every visit to the king, he would also bring a gift, a Cookie! 🍪

He would give the cookie to the king after bring his problem up.

Everytime he wants to meet the king, he always brings that same kind of cookie and give it to the king.

Now the king is still as forgetful as before, but not as hard as remembering hundreds of name or problems he would face every day, it is relatively easier to remember the cookie - that this exact particular person always give me a cookie after they came to see me.

The king may not remember this man’s name, but the king remember his cookies 🙂

In a real life, a server is serving hundreds of different clients, each of them having different needs. The server would not know who is who, so at some point (let’s say, after logging in) it will generate a unique string and give it to the client. This is a cookie. The client would then save that unique string inside their browser, and provide it along the request of future web features. Due to how common this style is, it is handled automatically by majority the browsers, so plain user wouldn’t recognize when the exchange is happening.

With cookie, the server doesn’t really need to know well what’s your name or more detailed personal information of yours, but it can understand what you likely want by looking from it.

Now, try deleting all the cookies on your web browser 🙂