Solving Race Conditions With EF Core Optimistic Locking

September 18, 2023
 192
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!

Hot Vacancies

.NET Developer

American startup, .NET
This week

A developer is needed for an American startup that manages the operation and maintenance of residential complexes. This is a new project from scratch with a temporary integration of the old system (Web Forms, no code access).

.NET Backend Developer

Field Complete, .NET

Field Complete is a team of passionate, young & fun-loving professionals looking to change the uneffective way that Servicing Industry works on US markets. Field Complete is growing really fast. We are looking for a Back End Developer to build a top-level modern API, ready for high load. Strong expertise with:

Senior Xamarin Developer

DraftKings, Mobile

You will join a mobile team which is working on two very exciting projects, Sportsbook and Casino. The apps are used by users in the US, where we are working on the regulated markets. We are releasing apps every two weeks. Our apps are generating almost 75% of the company revenue and the user base is growing daily. Technical stack on the project: Xamarin.Forms, MVVM with DI, NewRelic, Azure + App Center etc. Switching to .Net MAUI in the nearest 2-3 months.

Senior .NET Engineer

DraftKings, .NET

You will be working in a large US-oriented company that puts as a priority: security, performance, and stability. The candidate will work on pushing a huge number of changes (several thousand per sec) to several thousand clients in a near real-time manner.

Middle strong .NET developer

SoftServe, .NET

Our customer is an American company that develops software for businesses to help manage their networks, systems, and information technology infrastructure. The company provides purpose-built products for IT professionals, MSPs, and DevOps pros.