DeadlocksLivelock & StarvationMedium⏱️ ~2 min

What is Livelock?

Definition
Livelock occurs when threads are not blocked, they keep running and responding to each other, but none of them make any real progress. It is like two polite people in a hallway who keep stepping aside for each other.

The Hallway Problem

Two people walking toward each other in a narrow hallway. Person A steps left to let B pass. Person B steps right (their left) to let A pass. They are now still blocking each other. So A steps right. B steps left. Still blocked. They keep dancing but nobody moves forward.

Threads do exactly this. Thread 1 detects a conflict, backs off, retries. Thread 2 detects the same conflict, backs off, retries. Both keep backing off and retrying in sync. Nobody makes progress.

Why Livelock Is Tricky

CPU stays busy: Unlike deadlock where threads are blocked and use no CPU, livelock burns CPU cycles constantly. Your monitoring shows 100% utilization. Everything looks active.

Hard to detect: Health checks pass because threads are responding. Logs show activity. But throughput is zero. The system is running in circles.

Often caused by recovery code: Ironically, livelock frequently happens when you try to be too clever about avoiding deadlock. You add backoff logic that all threads follow identically.

Common Livelock Patterns

Identical retry logic: All threads use same backoff timing, retry at same moment.

Symmetric conflict resolution: Both threads use same rule like "give up your lock if someone else wants it" - so both give up simultaneously.

Overly polite protocols: Each thread tries too hard to accommodate others.

Key Difference from Deadlock: In deadlock, threads are blocked waiting. In livelock, threads are running but accomplishing nothing. Deadlock is frozen. Livelock is spinning wheels.
💡 Key Takeaways
Livelock: threads keep running but make zero progress - spinning wheels
The hallway problem: two polite people stepping aside for each other forever
Burns 100% CPU while accomplishing nothing - hard to detect via monitoring
Often caused by identical retry/backoff logic that synchronizes threads
Key difference: deadlock is frozen waiting, livelock is active but useless
📌 Examples
1Network retry: two services keep backing off and retrying at the same intervals forever
2Lock acquisition: threads detect conflict, release locks, retry, conflict again - loop
3Message passing: both senders wait for other to go first, both send simultaneously, both back off
← Back to Livelock & Starvation Overview
What is Livelock? | Livelock & Starvation - System Overflow