Under load, your service occasionally produces a wrong result — a counter that's off, a duplicate record — but it never reproduces in a single-threaded test. How do you reason about what's going wrong and fix it?

technical-conceptual · Mid level · software-engineering

What the interviewer is really asking

Assesses whether the candidate can recognize a race condition over shared mutable state, identify the non-atomic read-modify-write at its core, and choose an appropriate fix (atomic operation, narrow critical section, or eliminating shared state) rather than guessing.

What to say

What to avoid

Example answers

Strong: Intermittent, only under load, never single-threaded — that's a race condition over shared mutable state. The off-by-some counter smells like a non-atomic read-modify-write: two requests both read the same value, both add one, and one increment is lost. The duplicate record smells like check-then-act — both look up, both see 'not there', both insert. I'd fix the counter with an atomic database increment instead of read-modify-write in app code, and the duplicate with a unique constraint so the second insert fails cleanly and I handle the conflict. Where I can, I'd just remove the shared state — keep it per-request or immutable — so there's nothing to race on rather than reaching for a lock.

Weak: If it only happens sometimes under load it's probably a flaky timing thing in the framework or the database. I'd add some retries so it self-corrects, and maybe wrap the whole request handler in a synchronized block or a lock so only one thing runs at a time. We're on a modern async runtime so it should mostly be thread-safe anyway.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.