tezvyn:

Using context.Context across microservice calls in Go

Source: interviewintermediate

WHAT IT TESTS: request-scoped context propagation. OUTLINE: context carries cancellation, deadlines, and values; pass ctx as first arg, set one WithTimeout at the edge, attach a request ID via WithValue, thread it through downstream calls so all cancel…

WHAT IT TESTS: practical use of context for deadlines and request-scoped data across services. ANSWER OUTLINE: context.Context propagates cancellation signals, an absolute deadline, and request-scoped values through a call chain as the first parameter. At the API edge, derive ctx with context.WithTimeout for the whole request budget and attach a request ID via context.WithValue. Pass that ctx into every downstream HTTP or RPC call; if the deadline fires or the client disconnects, all in-flight calls cancel.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Using context.Context across microservice calls in Go · Tezvyn