Skip to content
Lesson 1 of 7

Step 1 of 5 · Reading · ~1 min

Learn

Concurrency at Scale

context.Context is how Go propagates cancellation, deadlines, and request-scoped values through call chains.

Every Go function that does I/O or blocks should accept a ctx context.Context as its FIRST argument.

go

Creating contexts:

go

Patterns:

go

The key must be your own unexported type, not a bare string or int — two packages that both use "user_id" would silently overwrite each other's value, and go vet flags the bare-string form.

context.WithValue is for request-scoped data only — request ID, trace span, auth user. Don't use it as a function-arg replacement.

The cardinal rule: if a goroutine outlives its caller, it should accept a context and check ctx.Done(). Goroutine leaks are the #1 Go bug at scale.

Up nextsync Primitives in DepthConcurrency at Scale

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…