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(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see