DELAPARRA
Index
Color
NL
Category: Core glossary

Race condition

Explained by Updated

What is Race condition?

Race condition: A bug that occurs when a program's behaviour depends on the timing or sequence of uncontrollable events (e.g. two threads modifying the same data simultaneously). A race condition is a bug where the outcome depends on timing: which of two operations happens first. Two requests read the same stock level of one, both decide the product is available, and both sell it.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Race condition

How is Race condition used in practice?

These bugs are hard to find. They rarely appear in development, where you click through things one at a time, and appear under real traffic, often only occasionally.

What should you keep in mind with Race condition?

The fixes are well known. Let the database do the check and the change in one atomic statement, use unique constraints so duplicates are impossible, lock rows inside a transaction, or use a cache lock for jobs that must not overlap. When you write code that reads a value and then writes based on it, ask what happens if two requests do this at the same moment.

At a glance

CategoryCore glossary
Explained by
Updated

More Core glossary terms

All terms starting with R

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.