1 / 11
Master concurrency in Go: the scheduler, goroutine lifetimes, channels and select, the Go memory model, mutexes, atomics, sync, context, timeouts and retries, errgroup, graceful shutdown, goroutine leaks, worker pools, pipelines, rate limiting, backpressure, per-key ordering, the race detector…
Goroutines, Channels, the Memory Model, and Production Patterns That Hold Up Under Load
Read before you buy: the PDF here is a free sample — the first 20 pages of the 481-page book (payments, sales and reviews on this demo site are sample data). Get the full e-book at thenexbooks on Gumroad.
For Go developers who can start a goroutine — and want to know their concurrent code is correct.
Starting a goroutine takes two letters. Keeping concurrent code correct as it grows and as load rises takes much more. Most developers learn goroutines, channels, and a WaitGroup quickly, and then production teaches the rest the hard way: a worker pool that leaks a goroutine per request, a shutdown that drops in-flight work, a counter that is wrong only under load, a deadlock that appears once a month at 3 a.m.
This book is the deep dive. It explains how the runtime schedules goroutines, exactly what channels and select guarantee, what the official Go memory model promises (and what it does not), and when each tool in sync, sync/atomic, and context is the right one. Then it turns that understanding into production patterns — and shows how to test, debug, profile, and trace them.
What's inside
- How the Go scheduler works: goroutines, OS threads, and processors (G, M, P), run queues, work stealing, preemption, and GOMAXPROCS
- Goroutine lifetimes and structured concurrency: WaitGroup, the new WaitGroup.Go, panics, and ownership
- Channels and select in depth: buffering, closing rules, nil channels, timers and tickers, and the patterns that never leak
- The Go memory model without the mystery: happens-before, data races, and exactly what each primitive guarantees
- Mutexes, RWMutex, atomics, copy-on-write snapshots, Once, Cond, Pool, and sync.Map — and when each is the wrong choice
- context in depth: cancellation trees, deadlines, causes, AfterFunc, WithoutCancel, and values
- Timeouts, retries, exponential backoff with jitter, errgroup, semaphores, singleflight, and two-phase graceful shutdown
- Goroutine leaks: the common patterns, goleak, goroutine dumps, and the goroutine leak profile
- Patterns with their failure modes: worker pools, pipelines, fan-out and fan-in, rate limiters, bounded queues and backpressure, partitioned workers for per-key ordering, and pub/sub
- Testing concurrent code without sleeps: fakes, the race detector, and virtual time with testing/synctest
- Debugging and performance: deadlock and starvation casebook, goroutine, block, and mutex profiles, execution traces and the flight recorder, honest benchmarking, and concurrent HTTP services
One running example, start to finish. You work on Driftwire Relay, the webhook delivery service of a fictional company. Customer applications publish events; Relay delivers each one to every subscribed endpoint, retries failures, respects rate limits, and must shut down without losing work. Some endpoints are fast, one is flaky, one is retired, and one is too slow for its timeout — exactly the mix that makes concurrency necessary and hard. The reference project runs completely offline with simulated endpoints, so every example is reproducible, and the timing examples use virtual time so the numbers are exact.
Current and honest. The book targets Go 1.27 and marks features that need Go 1.25, 1.26, or 1.27. Memory-model statements follow the official Go memory model. Code examples were compiled and tested with Go 1.27, including with the race detector; timings and benchmark results are real measurements, labeled as specific to one test machine. There are no invented benchmarks or statistics. Every chapter includes runnable code, Tips, Notes, Warnings, Try It Yourself exercises, and Key Takeaways, and the appendices give you a concurrency cheat sheet, tested pattern templates, a production checklist, and a glossary.
Format: PDF, 481 pages (A4), linked table of contents and bookmarks. English. First Edition, 2026. Published by thenexbooks. Includes the Driftwire Relay starter project (Go module) that the book builds on. For developers who already know the Go language. This book is independent and is not affiliated with, sponsored by, or endorsed by Google or the Go project.
Table of Contents
Part I — How Go Runs Concurrent Code
- Ch 1 · Why Concurrency Is Hard — and What Go Gives You
- Ch 2 · Goroutines and the Go Scheduler
- Ch 3 · Goroutine Lifetimes, WaitGroup, and Structured Concurrency
- Ch 4 · Channels in Depth
- Ch 5 · select, Timers, and Tickers
Part II — Shared Memory and the Memory Model
- Ch 6 · The Go Memory Model: Happens-Before Without the Mystery
- Ch 7 · Mutexes and RWMutex: Designing Critical Sections
- Ch 8 · sync/atomic: Counters, Flags, and Lock-Free Snapshots
- Ch 9 · Once, Cond, Pool, and sync.Map
- Ch 10 · The Race Detector
Part III — Coordination and Cancellation
- Ch 11 · context in Depth: Cancellation, Deadlines, Causes, and Values
- Ch 12 · Timeouts, Retries, and Backoff
- Ch 13 · errgroup, semaphore, and singleflight
- Ch 14 · Graceful Shutdown
- Ch 15 · Goroutine Leaks: Prevention and Detection
Part IV — Concurrency Patterns
- Ch 16 · Worker Pools: The Relay Dispatcher
- Ch 17 · Pipelines, Fan-Out, and Fan-In
- Ch 18 · Rate Limiting, Bounded Queues, and Backpressure
- Ch 19 · Per-Key Ordering and Partitioned Workers
- Ch 20 · Pub/Sub, Broadcast, and Event Buses
Part V — Testing and Debugging Concurrent Code
- Ch 21 · Testing Concurrent Code
- Ch 22 · Virtual Time with testing/synctest
- Ch 23 · Deadlocks, Livelocks, and Starvation: A Debugging Casebook
- Ch 24 · Profiling Concurrency: Goroutine, Block, and Mutex Profiles
Part VI — Performance and Production
- Ch 25 · Execution Tracing and the Flight Recorder
- Ch 26 · Benchmarking and Tuning Concurrent Code
- Ch 27 · Concurrency in HTTP Services
- Ch 28 · The Production Relay: Putting It All Together
Appendices
A · Concurrency Cheat Sheet
B · Pattern Templates and API Reference
C · Production Concurrency Checklist
D · Glossary
Book details
| Detail | |
|---|---|
| Pages | 481 |
| Format | PDF (A4) + starter project (Go) |
| Language | English |
| Level | Intermediate to Advanced |
| Edition | 1st Edition (2026) |
| Download on this site | Free sample, first 20 pages (PDF) |
| Publisher | thenexbooks |
Files you get
No reviews yet. Only buyers can review.
More from thenexbooks