Go Programming Language
Modern, statically typed language designed at Google with built-in concurrency support.
Key Concepts
- Go Channels - Typed conduits for communication
- Goroutines - Lightweight concurrent execution units
- Error Handling - Explicit error returns, no exceptions
- Context Propagation - Cancellation and deadline propagation
Concurrency Patterns
- Mutex patterns - Traditional locking mechanisms
- Channel buffering - Async communication strategies
- Worker pools - Combining channels and goroutines
- Race conditions - Common pitfalls and detection
Pattern Relationships
- Channel patterns connect to mutex patterns via synchronization needs
- Context propagation relates to graceful shutdown patterns
- Worker pools combine channels, contexts, and wait groups
- Error handling in concurrent code requires special patterns
- Testing concurrent code links to race detection tools
Error Handling
- Explicit error returns as values
- error-wrapping - Adding context to errors
- panic-recover - Exception-like mechanism for fatal errors
- Error chains and unwrapping (Go 1.13+)
Goroutines
Lightweight threads managed by the Go runtime, fundamental to Go’s concurrency model:
- Launched with
gokeyword:go doWork() - Extremely cheap: ~2KB initial stack size
- Multiplexed onto OS threads by Go scheduler
- Communicate via channels, not shared memory
- No direct control over lifecycle - use context for cancellation
- Common pitfall: goroutine leaks from unclosed channels
Go Channels
- Go channels are typed conduits for goroutines communication
- Send and receive operations block by default
- Closed channels cannot be reopened or sent to
- Receiving from closed channel returns zero value and false
- Buffered channels allow async sends up to buffer capacity
Questions
Context Propagation
- How does context cancellation propagate through nested goroutines?
- What happens to goroutines when parent context times out?
- Best practices for context value propagation vs parameters?
- When to create derived contexts vs passing parent?
TODOs
Retry Logic Implementation
- Implement exponential backoff for flaky test retries
- Add jitter to prevent thundering herd
- Configure max retries via environment variable
- Log retry attempts with context
- Success criteria: 90% reduction in CI flakiness