TGViewer
Coding Interview Preparation Coding Interview Preparation @coding_interview_preparation · 5.9K subscribers
Post #1423 272
🧠 EDUCATIONAL CS #5 - Concurrency: Race Conditions vs. Deadlocks

Two concurrency terms that get confused constantly - here's the clean distinction.

🔹 Race condition: the outcome depends on unpredictable TIMING of operations. We saw this back in Spot the Bug #2 - two threads incrementing a shared counter, and depending on exact timing, updates get lost.

🔹 Deadlock: two or more threads are permanently stuck, each waiting for a resource the other one holds, forever.


Thread A: holds Lock 1, waiting for Lock 2
Thread B: holds Lock 2, waiting for Lock 1
→ Neither can ever proceed. Frozen forever.


The classic fix for deadlocks: always acquire locks in a consistent, agreed-upon order across your entire codebase. If EVERY thread always locks Resource 1 before Resource 2 (never the reverse), the circular waiting pattern above becomes structurally impossible.

Why this matters in interviews: system design and backend interviews increasingly probe concurrency understanding, even outside dedicated "concurrency" questions - e.g., "what happens if two requests try to update the same row at the same time?" is really asking about race conditions, often expecting you to mention database-level solutions like row locking or optimistic concurrency control (checking a version number before committing a write).

Race condition or deadlock - which one is scarier to debug in your experience, and why? 👇
More from @coding_interview_preparation
  1. Oct 8, 2026If you're prepping for system design interviews, this repo is gold It contains a curated,…
  2. Oct 6, 2026document post
  3. Oct 4, 2026💼 Why Your Resume Gets Rejected Before a Human Reads It You may have good skills and proj…
  4. Oct 2, 2026🧠 Coding Myths You Should Stop Believing There's a lot of advice online about learning to…
  5. Oct 1, 2026Most Asked Topics in AI Engineer Interviews Based on 2026 candidate reports
  6. Sep 30, 2026💼 What Companies Actually Look For in a Fresher Think companies only care about your CGPA…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →