Solving Race Conditions With EF Core Optimistic Locking
How often do you think about concurrency conflicts when writing code?
You write the code for a new feature, confirm that it works, and call it a day.
But one week later, you find out you introduced a nasty bug because you didn't think about concurrency.
The most common issue is race conditions with two competing threads executing the same function. If you don't consider this during development, you introduce the risk of leaving the system in a corrupted state.
In this week's newsletter, I'll challenge you to spot the race condition in a method for reserving a booking. The business requirement is you can't have two overlapping reservations for the same dates.
And then, I'll show you how to solve this race condition using EF Core optimistic concurrency.
Let's dive in!