HTTP handler with timeouts, request IDs, and context cancellation

8483
0

I treat context.Context as the contract between the edge and everything downstream. The pattern here starts by creating a per-request timeout using context.WithTimeout, then storing a requestID in the context so logs and traces can correlate without passing extra parameters everywhere. I also limit request body size early with http.MaxBytesReader to prevent memory blowups. The important operational detail is what happens when the deadline hits: any database call, HTTP call, or goroutine that uses ctx gets the same cancellation signal, which makes backpressure real instead of wishful. When this is wired in consistently, you see fewer stuck goroutines and far more predictable latency under load.