Distributed Lock

Problem

Five application instances can all run: GenerateDailyReport() but only one should execute it at a time. A normal in-process lock protects only one machine.

Solution — Distributed Lock

Coordinate ownership through shared infrastructure. For example, a small file named report.lock in Azure Blob Storage represents the lock. Before generating the report, every application instance asks Azure for exclusive ownership of that file for 60 seconds—called a lease. Azure grants the lease to instance A and rejects B and C's attempts, so their application code waits and retries. A generates the report, renews its lease if it needs more time, and releases it when finished. If A crashes, the lease expires and another instance can acquire it. The application code starts work only after acquiring the lease and must stop if ownership is lost. Azure protects the lock file; the application controls report execution.
Instance A → owns lock
Instance B → wait
Instance C → wait
Core idea: distributed locks coordinate exclusive work across multiple processes or machines.