Skip to content

Lesson 03 · Backend & Systems with Go

Go: Goroutines & Channels

Run work concurrently with goroutines, pass it safely through unbuffered and buffered channels, coordinate fan-out with sync.WaitGroup, cancel work with context.Context - and meet the honest failure modes: deadlocks, goroutine leaks and data races.

50 minadvancedBackend & Systems: Go

Prerequisites: Go: Structs, Interfaces & Errors

Learning objectives
By the end of this lesson, you will be able to:
  • Launch work with the go keyword and reason about cheap, runtime-scheduled goroutines - not raw OS threads
  • Pass data between goroutines over unbuffered and buffered channels, and close them safely using the comma-ok form
  • Multiplex channel operations with select, including non-blocking attempts and time.After timeouts
  • Coordinate fan-out with sync.WaitGroup - Add before launch, defer Done inside, Wait before moving on
  • Cancel work through context.Context by selecting on ctx.Done(), and recognize deadlocks, goroutine leaks and data races (go run -race)