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.
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.
Use when code runs things at the same time - threads, async/await, queues and workers, parallel requests, cron jobs, webhooks that retry - or when a bug only happens "sometimes" or under load. Covers race conditions, deadlocks, mutexes/locks, atomic operations, idempotency, message queues and backpressure, with Laravel and database examples.
Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.