# Race Condition

*noun*

say it: **“RAYS kun-DISH-un”** **/ˈreɪs kənˈdɪʃən/**

A bug where the result depends on the timing of two things happening at once, such as two people changing the same record.

## What is a **race condition** in a database?

A **race condition** is a bug where two requests read the same data and then change it at about the same time, so the result depends on which one finishes first. Both shoppers see one bike left, and both buy it.

```javascript
// Two checkouts run this at the same moment:
const bike = db.bikes.findOne({ _id: 7 });   // both read stock: 1
if (bike.stock > 0) db.bikes.updateOne({ _id: 7 }, { $set: { stock: bike.stock - 1 } });
// both sell it, and one customer pays for a bike that isn't there
```

## In a sentence

- “Checking and changing the stock in one updateOne closed the **race condition**.”
- “The **race condition** sold the last bike to two customers in the same second.”

Level: Journeyman · [More Database terms at this level](https://www.ask-codey.com/glossary?category=database&level=3)

Updated: November 19, 2026

## In other subjects

- [Race Condition in C#](https://www.ask-codey.com/glossary/race-condition-c-sharp)
- [Race Condition in Java](https://www.ask-codey.com/glossary/race-condition-java)
- [Race Condition in Python](https://www.ask-codey.com/glossary/race-condition)

Source: https://www.ask-codey.com/glossary/race-condition-database
