Stage 3 · Build
Concurrency in Depth
Race Detector & Worker Pools
go test -race, bounded workers, backpressure, and errgroup coordination.
Race Detector
The race detector finds data races at runtime. It instruments every memory access to detect unsynchronized reads and writes. Always run tests with -race in CI.
# Run tests with race detector
go test -race ./...
# Run benchmarks with race detector
go test -race -bench=. ./...
# Run a specific test
go test -race -run TestConcurrent ./...
# Build with race detector
go build -race -o myapp ./cmd/myapp
# Run with race detector
./myappThe race detector adds 2-10x overhead and uses 5-10x more memory. It is not for production — use it in testing and development. The overhead comes from instrumenting every memory access with thread sanitizer code.
Common Race Conditions
Bounded Worker Pools
Bounded worker pools limit concurrent goroutines. This prevents resource exhaustion and provides natural backpressure.
Backpressure
Backpressure slows down producers when consumers are overwhelmed. Without backpressure, producers can exhaust memory or overwhelm downstream services.
errgroup Coordination
errgroup coordinates goroutine groups with error handling, concurrency limits, and context cancellation.
Testing Concurrent Code
The race detector is the most reliable way to find data races. Run every test suite with -race in CI. The overhead is acceptable for tests. Never ship code that has not been tested with the race detector.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.