The context package carries cancellation signals, deadlines, and request-scoped values across API boundaries and goroutines. It's the standard mechanism for controlling the lifetime of operations — especially for cancelling work and propagating timeouts through a chain of function calls.
The core problem it solves
A request starts work across many goroutines/functions (DB query, API call, etc.).
If the client disconnects or a timeout hits, you want to CANCEL all that work
so goroutines don't keep running uselessly (wasting resources / leaking).
→ context propagates the "stop now" signal down the entire call chain.
