DEV Community

Wesley Schmidt
Wesley Schmidt

Posted on

Data Persistence

So, imagine if Facebook still stored your information on the page itself and every time you wanted to look at one of your friends pages, you had to log-in all over again. It would be extremely frustrating! So, what is data persistence? It's way for storing a users data from page to page, basically a way for the site to know you are still you whenever you move pages. Before data persistence, info was stored on the sites URL itself, meaning every time a new URL was loaded, all data was lost, resulting in a lot of frustration.

How does it do this? Well, there are a few approaches, but websites will often store this info locally on the client side using cookies. This can be thought of as an id badge that the server can quickly look at to determine your status to know that you are still "you". On the other side, a webpage will also store a users info on the server using sessions that are saved in a database. This allows the website to store data dynamically from page to page. You can think of it like this:

Alt Text

The client will send your request to the server, which will verify your ID and in turn store that request on its database as a session. This has become a staple when designing a website and can be seen in every major site today. For example, whenever you log in to YouTube, the server can keep track of which videos you have watched, whether you liked or disliked them, and who you are subscribed to. It can take this information and start to relate it to other content on its site, offering up suggestions for other content you may enjoy. Another way to look at it is through Amazon, being able to keep track of what items you have shown interest in through purchases and having your items stay in a shopping cart while you continue to browse for others. With the combination of cookies and sessions, sites like Spotify allow users to download their favorite music to their local systems, allowing for offline use. Why is this cool? Because, being a streaming site, most of the time it will require an online connection to listen to music, but because of the cookies on your computer, Spotify is able to confirm your permission without having to check your connection.

With this practicality comes a catch however, data leaks. By sending out valuable information, such as social security numbers or credit card info, you are making it publicly available to anyone who wishes to look for it. They often do this when your local client is trying to send information to a server. This is possible because of the indirect correlation of the client to the server. Often, your computer isn't directly connected to the server, most of the time it will have to pass this information through nodes, like a relay, where someone will be listening and steal your identity.

This can be countered though through using encryption, which will jumble up requests a client will send to the server with a process called hashing. Hashing is a lossy encryption, meaning it takes out information permanently making it unique to the same info that may be typed in by another user. Hashing in tandem with salt, which randomly adds information to submitted data, makes stealing precious information from you much, much harder.

Latest comments (0)