Race Condition
PronunciationRAYS kun-DISH-un
Definition
A race condition is a bug where the result depends on the timing of two actions, such as two requests both checking that a seat is free and then both booking it.
Where you hear it
In bug reports that only happen "sometimes", payment and booking systems, and concurrency discussions.
Examples
Two clicks at once created two payments; it's a race condition.
A unique constraint closes the race at the database level.
Two admins clicked approve together, so the request was processed twice, a race condition.
Common mistake
Checking in code and then writing, assuming nothing changes in between. Use a database constraint, a lock or an atomic update.
Don't confuse with
A deadlock, where two operations wait for each other forever. A race produces wrong results; a deadlock produces a freeze.
Say it at work
- In a meeting or chat
We can't reproduce it, so I suspect a race condition.
- In an email or ticket
Wrap the check and the write in one transaction.
Keep exploring
More in Architecture & Design