0% completed
Course Introduction
On This Page
A First Program
Who This Course Is For
How the Chapters Build
Running the Code
The Go Version
Concurrency lets a Go program keep working on one task while another task is waiting. Suppose a program must call three services, and each call takes 100 ms to answer. Made one after another, the three calls take about 300 ms. Made at the same time, they take about 100 ms, because the three waits overlap instead of following one another.
Go makes this kind of program short to write. The language has goroutines, which are functions that run independently of the code that started them, and channels, which carry values from one goroutine to another. The standard library adds three packages for the same kind of work: sync, sync/atomic, and context.
This course explains how to use these tools correctly, how they behave when something goes wrong, and how to choose between them.
A First Program
The program below is the running example of the whole course. The fetch function stands in for a call to a remote service. It sleeps for 100 ms instead of using the network, so every program in the course runs the same way on any machine.
Output:
one after another: 300ms at the same time: 100ms
The second half starts one goroutine per URL, and each goroutine sends its page into a channel. The main function receives three values from that channel, so it waits until all three calls have finished. The total time is the time of the slowest call rather than the sum of all three.
Who This Course Is For
The course is written for software engineers who already know basic Go. You should be comfortable with variables, slices, maps, structs, methods, interfaces, errors, and closures. You should also have started a goroutine with the go keyword and sent a value through a simple channel.
You do not need to know the select statement, the sync package, the context package, generics, or testing in Go. Each of these is taught in full before any lesson depends on it.
How the Chapters Build
Each chapter uses only what the chapters before it have taught. The first chapters cover the language features, the middle chapters combine them into patterns, and the final chapters cover bugs, tests, the runtime, and complete programs.
| Chapter | What it covers |
|---|---|
| 1. Concurrency Basics | Concurrency versus parallelism, goroutines, and simple channels |
| 2. Channels in Depth | Direction, closing, nil channels, and who should close a channel |
| 3. The Select Statement | Waiting on several channels, timeouts, and nonblocking operations |
| 4. The sync Package | Mutexes, WaitGroup, Once, Cond, Map, and Pool |
| 5. Data Races, Atomics, and the Memory Model | What a data race is, how to find one, and atomic operations |
| 6. The context Package | Cancellation, deadlines, and values carried with a request |
| 7. Core Concurrency Patterns | Pipelines, fan out and fan in, worker pools, and error groups |
| 8. Errors, Panics, and Shutdown | Returning errors from goroutines and stopping a program cleanly |
| 9. Flow Control | Rate limits, bounded queues, retries, and circuit breakers |
| 10. Concurrency Bugs | Deadlocks, livelocks, starvation, and goroutine leaks |
| 11. Testing Concurrent Code | The race detector in tests, synctest, and benchmarks |
| 12. Runtime Internals | The scheduler, GOMAXPROCS, and how channels and mutexes work inside |
| 13. Case Studies | A crawler, a message broker, an API client, and a file indexer |
Every chapter ends with a quiz that checks the main ideas of its lessons.
Running the Code
Most code blocks in the course are complete programs. Each one has a Run button in the course player, and you can change the code before you run it. Below each program, the lesson shows what it printed when it was tested.
When the output depends on how the runtime schedules goroutines, the program carries the comment // Output varies between runs. and the lesson shows one possible output. Timings also depend on the machine, so a program that measures time will print different numbers for you. Some programs fail on purpose, with a deadlock, a panic, or a data race, and the lesson shows the error text that Go prints.
Shorter code blocks without package main are fragments. They show syntax only and are not meant to be run.
The Go Version
The course targets Go 1.27 and uses current Go throughout. Programs loop with for i := range 10, use typed atomic values, and rely on the rule that each loop iteration has its own variable. When a feature was added recently, the lesson names the Go version that added it. If you run the programs on your own machine, use Go 1.27 or later so that they behave as shown.
Reading Progress
0%
On This Page
A First Program
Who This Course Is For
How the Chapters Build
Running the Code
The Go Version