Goroutines Explained 🚀
Concurrency that costs almost nothing to start.
Want to run something concurrently in Go? Put go in front of it. Done.
What is a goroutine?
A goroutine is a lightweight thread managed by the Go runtime. They start with a tiny stack (a few KB) and grow as needed, so you can spawn thousands without breaking a sweat. The scheduler multiplexes them onto OS threads for you.
Starting one
package mainimport (
"fmt"
"sync"
)func main() {
var wg sync.WaitGroup
for i := 0; i
Watch out
main returning kills every goroutine, so coordinate with sync.WaitGroup or a channel. Goroutines run independently. Use channels or mutexes to share data safely. Capture loop variables explicitly (pass i as an argument) unless you're on Go 1.22+.
Get Marcelo Domingues’s stories in your inbox
Join Medium for free to get updates from this writer.
TL;DR: go f() launches concurrent work; use WaitGroup or channels to wait for it.
Try spawning 1,000 goroutines and watch how fast they finish. 🐹







