Interview preparation
Intermediate·Discussion·2 min read

Where could a race condition happen?

Practice this question
Discussion template: use your own project facts, ownership, and measured outcomes. Bracketed text is a placeholder.

Short explanation:

A race condition happens when overlapping operations can violate a rule because their checks and writes are not coordinated. It can occur across requests even in a single-threaded Node process, and across multiple app instances. Identify the shared state and the exact interleaving that produces a wrong result.

Key points:

  • Concurrent stock/allocation updates, duplicate jobs or shared counters.

  • Protect the rule with atomic writes, constraints, locks or version checks.

  • For a one-time reward, two requests can both observe no reward record before either inserts it; a unique constraint can close that race.

Interview point:

  • Tie the protection to the invariant, such as one allocation per order, rather than saying “use a transaction” without detail.
Adapted from 10_RESUME_PROJECT_DEEP_DIVE.md · “Where could a race condition happen?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.