IT systems differ a lot, in the domain they cover, the platforms they run on and the audiences they are aimed at. If we had to find anything they all share, it would be basic operations such as adding and reading business objects, better known under the acronym CRUD. Today, though, we are not interested in create, read or update. Instead, we will focus on what hides behind the "D" in that term, namely delete.
Everyone expects that if we can add something in an application, we should be able to delete it too. The reasons vary: freeing up space, getting rid of incorrect data, hiding something, and so on. But this operation is very specific and, for that reason, not always possible. What is the reason, and does deletion really deserve special treatment? After all, mechanically it is much simpler than creating an object, right? Well, not necessarily.
Forms of deletion
Most of us, when thinking about deletion, associate it with physically removing information from a database (or a file from a system). And rightly so, since that is the purpose of deleting anything. However, while this term is indeed used when writing documentation and specifying requirements to describe a system function, "physical" deletion is not always recommended.
There are at least two reasons. The first is the finality of such an operation. Of course, many people will say that is how it should be: the user picks this option for a reason and wants to clean up the system. But you would not believe how unaware and unsure users sometimes are about what they are asking for and what they are doing in the application. The person knows they want to delete, but then doubts creep in: "what if it was the wrong object", "can this be recovered somehow", "why did this disappear on me", and the like. With "physical" deletion, such dramas can indeed happen. That is why this kind should be used only for simple, "uncomplicated" data. But there is a second issue to consider.
It is the relationships between objects, and that is the main reason "physical" deletion is not recommended. Imagine a document processed in the system (as a database record) and think about which attributes describe it. Many people will name the title or content, but there is also, for example, the author (so a user), the people assigned to edit it (users again) or the context in which the document was created (such as a project or a client, also stored in the database). And these are not only attributes: the document itself can have a history, people who sign it, or attachments. In that case, when the record is deleted, carelessly configured mechanisms of database management systems would have to automatically delete the related information too, and the user would lose, for instance, any access to the history entry saying they performed some operation. This can do a lot of damage in the system and is prone to errors. On top of that, the database will not allow it on its own (provided we configure the schema properly), which means that many operations deleting associated objects have to be done manually.
That is why "logical" deletion, also called deactivation, is used much more often. In this case the data is not permanently removed from the system. Instead, it is marked as deleted or inactive. The undeniable advantages are:
- no need to cascade-delete related records (simpler handling),
- a "safety valve" in the form of being able to go back to a given record,
- better options for analyzing who deleted a record,
- from the user's side it is functionally equivalent to physical deletion (if done well),
- if deleted data should still be visible on objects where it was previously selected, that is still possible.
In practice, most important objects processed in a system are deleted this way, because it is simply safer, and these entities are often related to a great many elements. On the other hand, it requires checking the activity flag in practically every database query, which makes them a bit longer, but above all requires developers to remember it. These are minor drawbacks, though, insignificant next to the advantages. Especially since you can use suitable mechanisms in the architecture or the database system to do this filtering automatically.
Deactivation can also be understood more literally. There are objects that the client only wants to mark as inactive and be able to look at at any moment from within the application. This is most often called "archiving" and works on a similar principle, but there are two basic differences. First, the interface lets users restore them explicitly, and second, it causes a few more problems with queries, because you have to decide when to check the flag and when not to. That depends on the specific arrangements.
Another form is blurring the data of the deleted object. It works like deactivation, but does not rely on changing a single column in the system. Instead, the relevant information is hashed, so it cannot be read clearly. Two terms to remember here are pseudonymization and anonymization, and we will come back to the topic later in the text.
Finally, there is sometimes also something like a merge, which is not deletion in itself but usually comes with it. Some systems import a client's archival data from files or another system and, as you might expect, it is not always clean. It also happens that imported objects were already added to the system manually, which creates duplicates. That is why a merge function (or, as developers more often say, "merging") is sometimes needed, and one consequence is getting rid of the duplicate, that is, (this time) physically deleting it. This situation is even more tied to the specifics of the system and is implemented fairly rarely because, frankly, it is a very complex matter.
There are also cases where the system does not allow deleting objects at all, in any form. Most often this comes from legal issues related to payments, or simply from a conscious decision of the software owner. An example is holding the data of a user who signed a contract or received an invoice. We will look at users separately anyway, but the cases related to them are the best "documented" situations where the "D" in CRUD has no right to appear. Or at least not always.
When to delete and when to deactivate?
I have already answered this question indirectly: deactivation is certainly safer, saves you from wondering what has to be taken into account when getting rid of a row in the database and provides a safeguard in the form of being able to return to the data. That is why this technique is recommended for all objects that are:
- important to the business,
- "large", meaning they not only have many fields but also take the user longer to fill in,
- tied to many other objects,
- a significant component of data that is constantly processed in the system (for example, a product group used by goods).
Someone may rightly point out that, apart from the earlier mentioned need to include the right flag in queries, deactivation has the drawback of not getting rid of the information. As a result, large tables in which data is often deleted can become a dumping ground and take up a lot of disk space. In such situations, if it concerns, say, dictionary data and references to it can be moved to other objects, the "physical" route is worth considering. A fairly natural example is an object for which we manage a group of information right away (on one screen). Take a client and their contact persons: the data is sent in one package and there are two approaches to saving it:
- We check each submitted contact person to see whether it is new (insert) or edited (we find the right row and run an update). If a contact person existed in the database before but is missing from the new data, we delete it (physically or logically).
- We (physically) delete all contact persons saved so far and add the rows again using the submitted form. In particular, it may happen that we deleted two people and added the same two people again.
Again, it all depends on the case. In some, this related information is still referenced by other objects, and then only option 1 is on the table. But if we do not care about keeping record identifiers and the objects can safely be "reset", option 2 is definitely simpler.
Other difficulties with deletion
I mentioned that deletion can be a more complicated matter than it first seems to the client. With deactivation, the "catch" is handling a specific flag on objects. With the classic approach, it is simply attended by a certain risk, and therefore calls for more careful testing of various cases.
But we also need to remember details that usually escape attention during analysis. For example, that deletion operations should be confirmed by users, which means introducing modal windows or other forms of alerts with "Yes" and "No" buttons. Since from the user's point of view the operation is irreversible (or at least restoring is problematic), such a confirmation request is needed. The second issue is permissions: even if a user can add objects, it does not always mean they can delete them. That means securing the methods on both the frontend and the backend, making sure the right buttons are shown on the frontend, and sometimes even moving everything to a specially separated admin panel.
The third issue is logging, in the sense of keeping a history of operations on a given object. This makes sense especially for larger, business-critical tables, where you may later need to investigate which data disappeared, why and who was responsible. Logs themselves go beyond the topic of this text, but it is another safeguard for unforeseen situations and for the client's question "how did this disappear on me".
What about users?
We have already mentioned that deleting users needs special treatment. On one hand, there is the GDPR, that is, the protection of personal data, which among other things requires handling requests to erase such information from an IT system. On the other, users are usually tied to a huge amount of data, and physically deleting them is a disaster for the system. Three things come to the rescue here.
First, the erasure of personal data can be understood in different ways, and there are legal grounds for keeping such information under certain conditions.
The second and third are techniques called anonymization and pseudonymization. Both rely on the masking of data mentioned earlier, so that it cannot be read without proper permissions or additional steps. They differ, however, in how the masking works. Anonymization is a complete, pseudorandom transformation of the field's value (in classic IT systems it is hard to speak of full randomness), so it cannot be recovered afterwards. On one hand, this is safe for the user's personal details. On the other, there are situations where the data has to be recovered for investigations or legal proceedings. Then pseudonymization is more advisable. It also masks the data, but with a pseudorandomly generated key known only to trusted people, which can be used to decode the information. In practice, then, anonymization differs from pseudonymization in that the key used for encryption is not stored anywhere in the first case, and is stored in the second.
In such a situation, pay special attention to data security and make sure that access to the encoded information is limited to strictly authorized people. This must have a legal basis and be stated in the terms of service or the privacy policy. A separate administrator account is often created with permissions to delete and restore, and its password is even locked in a safe. In addition, since users may still be displayed in the system in connection with certain objects, make sure that recipients in such situations see a note that the person has been deleted. Under no circumstances should the hash that now stands in for the first or last name be shown anywhere.
Remove versus delete
Finally, it is worth explaining a subtle difference in English between the words remove and delete. The former refers to the "soft" treatment of deletion: it means separating the information and hiding it from people's view, but still keeping it in the database. It can also be used when an object is "detached" from another. Delete, on the other hand, is actual deletion, even wiping the information out of the system. It originally comes from Latin, where the great-great-great-grandfather of this word, dēlētus, meant "destroyed".
Summary
As you can see, the topic of deletion seems simple, but it is not. And even if you already expected that data is deactivated rather than erased, I hope I was able to add something to that knowledge and make everyone treat this operation even more seriously than before.
Best regards and thank you, Jakub Rojek.


