Reviewed by Aditya Kumar · Last reviewed 2026-03-24
A deadlock occurs when two or more concurrent processes or transactions are permanently blocked, each waiting for a resource that the other process holds. This creates a circular dependency where no…
This easy-level General/Other question appears frequently in data engineering interviews at companies like ZS Associates. While less common, it tests deeper understanding that distinguishes strong candidates.
Start by clearly defining the core concept being asked about. Interviewers want to see that you understand the fundamentals before diving into implementation details. Structure your answer with a definition, then explain the practical application with a concise example. The expert answer includes a code example that demonstrates the implementation pattern.
A deadlock occurs when two or more concurrent processes or transactions are permanently blocked, each waiting for a resource that the other process holds. This creates a circular dependency where no process can proceed, leading to system stagnation.
For a deadlock to occur, all four of the following conditions must simultaneously be met (often referred to as the Coffman conditions):
Prevention involves designing systems to break one or more of these conditions. A common and effective strategy is to break the circular wait condition by enforcing a strict global ordering for resource acquisition. For example, always acquire locks on tables A then B, never B then A. In distributed data systems like Spark, careful management of shared state or external resources (e.g., Delta Lake transaction logs, Kafka offsets) is crucial to avoid such contention.
Detection and Resolution are often handled by database management systems. They can build a "wait-for graph" to detect cycles (deadlocks). Upon detection, the system typically resolves the deadlock by preempting one of the involved transactions (e.g., rolling back the "victim" transaction) and allowing others to proceed. This often results in an error for the rolled-back transaction, requiring application-level retry logic.
Best practices include designing transactions to be short-lived and acquire resources quickly, and implementing timeouts for resource acquisition to prevent indefinite waits.
-- Transaction 1
START TRANSACTION;
UPDATE accounts SET balance = balance - 10 WHERE id = 1; -- Locks account 1
-- (Concurrent) Waits for lock on account 2
UPDATE accounts SET balance = balance + 10 WHERE id = 2;
COMMIT;
-- Transaction 2 (concurrently)
START TRANSACTION;
UPDATE accounts SET balance = balance - 10 WHERE id = 2; -- Locks account 2
-- (Concurrent) Waits for lock on account 1
UPDATE accounts SET balance = balance + 10 WHERE id = 1;
COMMIT;
id=1 and waits for id=2; Transaction 2 locks id=2 and waits for id=1.
In the interview, also mention how deadlocks become significantly more complex in distributed systems where resources span multiple nodes or services, often requiring distributed lock managers or sophisticated coordination protocols.
Pro-Move: 'We break circular wait by always locking tables in schema alphabetical order—simple, enforceable.' Red Flag: Not knowing all four conditions—fundamental CS.
Some links below are affiliate links. If you buy through them we may earn a small commission at no extra cost to you — it helps keep DataEngPrep free.
According to DataEngPrep.tech, this is one of the most frequently asked General/Other interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.