# Concurrency & Channels in Golang. ![rw-book-cover](https://miro.medium.com/v2/da:true/bc1f8416df0cad099e43cda2872716e5864f18a73bda2a7547ea082aca9b5632) ## Metadata - Author: [[Abati Babatunde Daniel]] - Full Title: Concurrency & Channels in Golang. - Category: #articles - Summary: Go uses goroutines for concurrency and channels for communication instead of shared memory. Channels let goroutines send, receive, and synchronize data safely. This model reduces common concurrency bugs and makes concurrent code simpler. - URL: https://medium.com/@danielabatibabatunde1/concurrency-channels-in-golang-fe66c68471ad ## Highlights - Go’s Creator (Rob Pike) famously said and I quote “Don’t communicate by sharing memory; share memory by communicating.” ([View Highlight](https://read.readwise.io/read/01kedv93x20vbak8ezrqt38v7b)) - But first, let me explain concurrency to you: *Concurrency can be defined as the process of a system managing and executing multiple tasks or instructions seemingly at the same time even if they are not truly running simultaneously*. This means concurrency gives your system the ability to run different parts of a program independently for which each won’t overlap the other in real time. ([View Highlight](https://read.readwise.io/read/01kedva5bks6zvaz85sakb70cs)) - This led me into digging & researching what he meant and alas I understood it, as it simply meant that Golang’s approach to concurrency was; Instead of sharing memory & states directly , goroutines (processes or threads) communicate by sending and receiving data through **channels (***which are simple lightweight threads connected between multiple goroutines*). Traditional languages like Java and C++ handle concurrency by having threads directly access shared memory, requiring complex locks and mutexes to prevent race conditions. This approach is notoriously error-prone. ([View Highlight](https://read.readwise.io/read/01kedvarwd8c2r2vd7hn67z0pv)) - **Channels** excel in facilitating communication between goroutines. They provide a **safe and efficient** way to **pass data** and **synchronize** goroutines’ execution. ([View Highlight](https://read.readwise.io/read/01kedvcp17fc8wdnq0m01y73vw)) - When you create a channel using make(chan T), Go allocates a data structure that includes: • A buffer (for buffered channels) • A mutex (lock) • Send and receive queues for goroutines ([View Highlight](https://read.readwise.io/read/01kedvezk13p0gs9kwwwqd37j3)) - The mutex ensures that channel operations are atomic — only one goroutine can send or receive at a time. This built-in locking mechanism means you don’t need to implement your own synchronization when using channels for communication between goroutines. ([View Highlight](https://read.readwise.io/read/01kedvg1swahbtzpt4tgsnrpkj)) - For example, when multiple goroutines try to send to a channel simultaneously: 1. Each goroutine attempts to acquire the channel’s mutex 2. Only one succeeds and performs its operation 3. The others wait in line until the mutex is released 4. The runtime handles all this scheduling transparently ([View Highlight](https://read.readwise.io/read/01kedvgcbaztcedqwc8h72h9s3)) - Financial systems use channels to process transactions in parallel while maintaining strict ordering and atomicity requirements ([View Highlight](https://read.readwise.io/read/01kedvmr4vrqt8cq0xex83vk6a)) - Kubernetes leverage Go’s concurrency for orchestrating containers, with channels facilitating communication between control plane components ([View Highlight](https://read.readwise.io/read/01kedvmjzh11ygz9fh3japt623))