Skip to main content

A strange way to make an update to items from database

Last week I heard an interesting discussions between a tester and a developer.
The tester was upset that he discovered the following flow on an update action of an item from database:
  • Client: request and get an item from server
  • Client: change some data from the item
  • Client: send an update command to the server
  • Server: get the update command request
  • Server: delete from database the given item
  • Server: recreate the item as a new item with the updated data
What do you see wrong in this flow? (I hope that you spotted the problem already)
For each update, the server deletes the item from database and recreates the item. Each deleted item is marked only as deleted in database but is not physical removed, because we need a tracking mechanism. This is a very bad practice. We are talking about a small web-application that recreates each item when the user changes some fields on it.
Imagine the following scenario: The web application is an e-commerce solution and has around 10.000 items listed. Each week, we receive from each producer updates related to each product that we import from Excel files. Because of this in only 3 months, our database will have around 120.000 items, even if only 10.000 are active.
The developer said to the testers that was the most convenient way for him. But this solutions is farthest the best one.
So what we can do to solve these problems? First of all we should look what we should do when an item is updated. If we need some tracking capabilities, that we should create a separate table/tables that track the changes.
If you are a tester, you should never accept a response like “It was the most convenient”. The “tracking” should never be made in the same table. Also if this was the most easier way to update an item from the database that say no again.

Comments

  1. I keep hearing this a lot and I don't agree. It really depends on how the DB is handling it. Using, for example, a table partition upon the table in question, splitting it on two or more HDDs will allow 100 million+ records and still perform well.

    ReplyDelete
    Replies
    1. But why whould you like an update action to contain a delete and an add action - for general cases.
      There can be some custom cases when you have more versions of a product, but in this case you will not marker a product as deleted. You will add a new version of a product.
      Depends very much on what you want to do when you want to update an item. But if you don’t have any tracking or versioning on the given item I don’t see way you delete the existing item and add a new one. Only because for the developer is more easily to implement in this way I don’t think is it enough.

      Delete
    2. Indeed, if we are not talking about some 'temporal database' or other case when reverting to some previous point in time is a common requirement, it doesn't make sense to replace all updates with a 'mark as deleted'+insert operations, even if from a performance point of view the performance won't be affected so much.

      Delete

Post a Comment

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(...

How to audit an Azure Cosmos DB

In this post, we will talk about how we can audit an Azure Cosmos DB database. Before jumping into the problem let us define the business requirement: As an Administrator I want to be able to audit all changes that were done to specific collection inside my Azure Cosmos DB. The requirement is simple, but can be a little tricky to implement fully. First of all when you are using Azure Cosmos DB or any other storage solution there are 99% odds that you’ll have more than one system that writes data to it. This means that you have or not have control on the systems that are doing any create/update/delete operations. Solution 1: Diagnostic Logs Cosmos DB allows us activate diagnostics logs and stream the output a storage account for achieving to other systems like Event Hub or Log Analytics. This would allow us to have information related to who, when, what, response code and how the access operation to our Cosmos DB was done. Beside this there is a field that specifies what was th...

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills)

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills) The idea that moving to the cloud reduces the costs is a common misconception. The cloud infrastructure provides flexibility, scalability, and better CAPEX, but it does not guarantee lower costs without proper optimisation and management of the cloud services and infrastructure. Idle and unused resources, overprovisioning, oversize databases, and unnecessary data transfer can increase running costs. The regional pricing mode, multi-cloud complexity, and cost variety add extra complexity to the cost function. Cloud adoption without a cost governance strategy can result in unexpected expenses. Improper usage, combined with a pay-as-you-go model, can result in a nightmare for business stakeholders who cannot track and manage the monthly costs. Cloud-native services such as AI services, managed databases, and analytics platforms are powerful, provide out-of-the-shelve capabilities, and increase business agility and innovation. H...