Database locks, lost updates and idempotency

Jozef Cipa
16 min readMay 13, 2023

Web applications are often complex systems consisting of several parts such as UI (frontend), API (backend), database and often other 3rd party services that the application depends on. Designing the API service properly so it’s robust, secure, and works as expected goes without saying but sometimes there are other factors that should be considered and handled adequately.

One of them is concurrency & duplication. It is important to know about it and be aware of the challenges it entails and how to deal with them. In this article, we will look at three situations in which our API would normally work just fine but would encounter issues once concurrent or duplicate requests would come in.

Where’s my data?

Imagine a situation where you’re working as a copywriter at a company. As part of your job, you prepare posts for the company blog and also proofread the posts written by employees. One day an employee wrote a new post and asked you to review it. As you started reading it you noticed a typo.

The quick brown fox jmps over the lazy dog

Naturally, you’re going to correct it and save the post, so it would look like this.

The quick brown fox jumps over the lazy dog

But at the same time as you’re reviewing the article, that employee was reading it as well and realized that they forgot to add something important.

The quick brown fox jmps over the lazy dog…

--

--

Jozef Cipa

Backend developer and AWS Solutions Architect @ STRV