Go Concurrency in Practice: Learning by Doing, Not Just Reading!
Sound familiar? You open yet another article or book about concurrency in Go, start reading, and somewhere around the middle you realize that theory is one thing, but applying it in practice is a completely different story. Goroutines, channels, mutexes, wait groups – it all sounds logical until you encounter a real task and try to write code that works, and most importantly, correct code.
That's exactly why the wonderful go-concurrency-exercises repository by Long Hoang was created. It's not just a collection of problems, but an interactive trainer that forces you to do rather than just read. And in my opinion, it's the most effective way to truly understand how concurrency works in Go.

Why Every Go Developer Needs This
The project author, loong, makes a very accurate observation: there are plenty of resources on Go concurrency, but who really wants to read all of it? And I completely agree with him! Our brains are wired so that we remember information best when we process it through practical experience. This project offers exactly that approach – "learning through action."
Imagine: you're not just reading about the producer-consumer pattern, but implementing it yourself, encountering pitfalls, fixing bugs, and watching your code come alive and work. That's invaluable experience that no theory can replace.
How the "Trainer" Works
It's very simple and intuitive. Each "challenge" is a separate folder with a task that already has code scaffolding and, most importantly, tests! Yes, tests that verify the correctness of your solution. It's like a personal mentor who always points you back on track when you stray from the right path.
Here are the main rules the author suggests:
- Only modify
main.go: This is a key constraint. You're given a project skeleton, and your job is to insert your logic into just one file without touching the others. This disciplines you and helps you focus on solving a specific concurrency problem. - Use
go test: After you've written your solution, simply rungo testin the task folder. If the tests pass – congratulations, you've succeeded! If not – that's a reason to dig deeper into the problem and find the bug. This resembles the TDD approach, but for learning purposes. - Don't be afraid to ask for help: If you're stuck, the author suggests joining Go communities on Discord or Slack. There's always someone ready to help with code review or give valuable advice. It's great when learning happens in a supportive environment.
Diving into the Tasks: What Awaits You?
The repository contains tasks that simulate real-world developer scenarios. Let's look at some of them:
0. Limit Your Crawler
Imagine you're writing a web crawler that needs to collect data but shouldn't overload target servers. Here you'll need to implement a mechanism to limit the number of concurrent requests. This is an excellent task for mastering patterns related to rate limiting and load management using channels and sync.WaitGroup.
1. Producer-Consumer
A classic! The producer-consumer pattern is found everywhere – from message queue processing to working with data streams. This task will teach you to effectively use buffered channels to coordinate work between goroutines that generate data and those that process it. Here you'll encounter the need to properly close channels and handle termination signals.
2. Race Condition in Caching Cache
Oh, those races! One of the most insidious problems in concurrent programming. In this task, you'll need to find and fix a race condition in a caching scenario. This is a great opportunity to work with mutexes (sync.Mutex) or RWMutex and learn to protect shared resources from concurrent access that could lead to unpredictable results.
3. Limit Service Time for Free-tier Users
How do you give free-tier users limited time to complete an operation? This task will make you think about timeouts and deadlines. You'll use context.WithTimeout or time.After to automatically interrupt operations that take too long. A very useful skill for building fault-tolerant systems.
4. Graceful SIGINT Killing
Your application should be able to shut down gracefully when receiving a SIGINT signal (for example, when pressing Ctrl+C). It's not as simple as it sounds, especially when there are active goroutines. The task will teach you to intercept system signals and use context.WithCancel or channels to smoothly stop all background processes, close connections, and save data, avoiding information loss and hangs.
5. Clean Inactive Sessions to Prevent Memory Overflow
Imagine you're managing user sessions and need to regularly delete inactive ones to avoid memory leaks. This task requires implementing a background goroutine that periodically checks and cleans up old sessions. Here you'll encounter working with timers (time.NewTicker) and the need for safe access to shared data, as well as preventing goroutine leaks.
Who Will Benefit Most from This Repository?
- Go beginners: If you're just starting to learn Go and want to quickly master concurrency, this repository is your best friend. It will give you a solid foundation and practical experience.
- Developers who want to refresh their knowledge: Even if you've been writing Go for a long time but feel that some concurrency patterns are "fuzzy" – this is an excellent way to systematize and deepen your knowledge.
- Those preparing for interviews: The tasks are very similar to what often appears in technical interviews. Working through them, you'll feel much more confident.
- Fans of "learning by doing": If you don't like reading long texts and prefer to jump straight into code – this project was made for you.
Conclusion: Is It Worth Trying?
Absolutely, yes! go-concurrency-exercises is not just a set of exercises, but a full-fledged interactive course on concurrent programming in Go. It teaches you not only to write code, but to think about parallelism, anticipate problems, and build reliable systems.
The author has done tremendous work providing such a valuable resource. The DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE license only underscores the openness and desire to share knowledge. So don't waste time, clone the repository and start your journey to concurrent Go mastery!
Good luck in your concurrent adventures!
Related projects