Are you new to the software development industry? If you are, let me introduce you to the concept of soft delete and hard delete, and why, for the most part, you are going to be using the first one.
Let’s say you open your Messenger, WhatsApp, or whatever chat application you use to communicate on a daily basis. You like to send gifs/animated stickers online to most of your closest friends. All of the sudden you get a message from someone you don’t know, and while you were in the process of adding the gif and clicking the send button, you notice you have sent the message to the wrong person.
Luckily, companies like Facebook have enough budget to cover a very complex functionality that requires project planning of 4 months to get it to completion: the ability to delete messages.
Back to the story…
You quickly make sure to delete the message you sent by mistake, and your heart rate starts beating back to normal. Let me tell you that what you just did was soft deleting your message. Congratulations, now you are a software engineer, and you can work for Facebook.
Hummmm, part of it is true, and part of it is not true. You have to prepare more to get a software engineer position at Facebook, or Google, or Amazon, or any big tech company.
Table of Contents
Back to the point, soft deleting is the process of making unavailable data that the user once had access to and no longer can see. In other words, your message is never deleted from the app’s database. This information is retained for whatever reason, such as, stalking the messages you tried to delete, gathering data to understand better the user behavior, giving the possibility to restore information that the user thought was deleted, and… stalking more your information.
For that reason, there is usually a column in most of the tables where your data is stored that define whether this data has been acknowledged by the user as deleted or not. This column may have a name along the lines of IS_DELETED, DLTED, DELETE, IS_ACTIVE, ACTIVE, etc. In the tech industry, we often call this a flag or a switch.
On the other hand, hard deleting is the process of completely removing the information from the database. That means that if you call customer support and they cannot do anything to recover this information, believe them. They cannot recover this information. Hard deleting becomes a great option when there’s data that doesn’t serve much purpose and takes away precious database storage space.
For the most part, whenever you use an app and you want to delete an item, you get a similar prompt message:
“Are you sure you want to delete this?”
If you are not too concerned about the data and you decide to delete it, feel safe then there is a high chance that the information will remain in the database. However, if it is sensitive information, I would not be comfortable thinking that the information was deleted.
If you didn’t know by now, data means money, and the more data companies can get from you and retain and analyze to make better business decisions, the less likely they will be performing hard deletes.
This was one of the major learnings that I discovered during my initial stages in the software industry. It is a simple, but crucial concept to understand to avoid making a fool of yourself the next time you try to add “delete” functionality. In fact, they are telling you to add soft delete functionality, unless it is explicitly described in the task.
Are Soft Deletes Bad?
Everything in life has a purpose and this applies in a similar way for soft deletes. Thinking about soft deletes being bad is not correct. On the other hand, it is not correct to say using soft delete all the time is correct either. Unfortunately, the correct answer is “it depends”.
The term “soft delete” can cause be misleading as the word “delete” implies that something doesn’t exist anymore. A good way to think about “soft delete” is to enable and disable a record from a user. The problem happens when a software developer implements a soft delete strategy for every single project they work on.
Software development projects can have similarities but they are never the same unless they were copied and pasted. For most junior developers, it is recommended to use soft delete as they might not be aware of scenarios where they need to recover data for a user who accidentally deleted data from their account.
However, once you start getting a better understanding when developing software as well as clearly identify the trade-offs between making a decision between soft delete and hard delete in a specific project, you will start realizing soft deletes can be a bad idea if they are used unknowingly.
Should you ever
DELETE data in a Database?
We are in an era where having access to data gives you a lot of power. A mine of data is like a mine of gold. What matters is not the data in itself but how you use it. Although data plays an important aspect in today’s world. there is nothing wrong with deleting data from the database. However, failure to say that it depends would be catastrophic as there will be scenarios where you want to delete this data.
Let’s say you are architecting an application that stores shortened URLs, such as bitly, as many users share links in their social media, and having a long link in a description of a post will look bad. Depending on the social media, you might have a limit of characters you can type, and using a long link will take a lot of the character limit. All of these shortened links are stored in a database.
Let’s say you can set an expiration date to those links shortened for cases when there are promotional web pages that are available for a short amount of time. Once the links expired, would it make sense to keep storing the records in the database? That depends on the project. However, for this example, we are going to assume it doesn’t make sense to keep that information as it is no longer relevant for us. Hence, we should delete data in the database.
Deleting data frees up the database and makes it lighter when fetching large chunks of related information. It allows us to maintain the costs down by not having to pay for more data storage in case we exceed the quota. Did you there is nothing wrong with deleting data from the database? As long as you understand the pros and cons, you always have the chance to remove data.
There could be other scenarios where the soft “deleted”, or disabled data is used for analysis and get a better understanding of the customer’s behavior when interacting with an application. In that case, data scientist members will not appreciate removing completely records from a database.
In this article, we talked about what soft deletes and hard deletes are and their main differences. Although soft deletes are widely used across different teams, it doesn’t mean you should always design an application to soft delete records.
Sometimes it makes more sense to completely delete data from the database. Unless having a clear understanding of the pros and cons of using one method or the other, it is recommended to soft delete data in the first place as it can be available for restoration as easily as switching a flag or a column value of a record.