You need a distributed lock when multiple instances must ensure only one performs a critical section (e.g., one scheduler job). Risks: lock leaks, split-brain, clock/network issues, and added latency; prefer idempotency and DB constraints when possible.
Expanding on the short answer — what usually matters in practice:
A tiny example (an explanation template):
// Example: discuss trade-offs for "distributed-locks-—-when-do-you-need-them-and-wh"
function explain() {
// Start from the core idea:
// You need a distributed lock when multiple instances must ensure only one performs a critic
}