---
title: "Go Concurrency Patterns: Pipelines and cancellation - The Go Programming Language"
description: "Go pipelines are built as stages of goroutines connected by channels, with fan-out to spread work across workers and fan-in (via a sync.WaitGroup-based merge) to combine results."
url: "https://swe.quest/articles/go-concurrency-patterns-pipelines-and-cancellation-the-go-programming-language-ce3e4fe9c1ba792c"
canonical: "https://go.dev/blog/pipelines"
source: "The Go Blog"
difficulty: "medium"
kind: "How-to"
reading_minutes: 15
tags: ["go","concurrency"]
---

# Go Concurrency Patterns: Pipelines and cancellation - The Go Programming Language

A post on [The Go Blog](https://swe.quest/sources/go.md), 15 min read, How-to. Original: [https://go.dev/blog/pipelines](https://go.dev/blog/pipelines)

## Summary

Go pipelines are built as stages of goroutines connected by channels, with fan-out to spread work across workers and fan-in (via a sync.WaitGroup-based merge) to combine results. When downstream stages stop reading early, upstream senders block forever and leak goroutines. Sizing buffers to avoid this is fragile. The robust fix is a shared done channel that is closed (via defer) to broadcast cancellation, with every send wrapped in a select. The patterns are applied to a parallel MD5 digest of a directory tree.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Go](https://swe.quest/tags/go.md) (Languages)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)

## Prerequisites

- Go syntax ([easy posts on Go](https://swe.quest/tags/go.md?difficulty=easy))
- goroutines and channels

## Keywords

goroutines, channels, sync.WaitGroup, select, MD5, filepath.Walk

## Related posts

- [Leveraging Go Worker Pools to Scale Server-side Data Sharing](https://swe.quest/articles/leveraging-go-worker-pools-to-scale-server-side-data-sharing-5ace4b0b544c8996.md): Shopify Engineering · 2022-09-09 · Medium · 7 min read · Go, Concurrency, Performance engineering, Queues & messaging, Scaling
  Shopify's Server Pixels service, a Go pipeline that consumes over a billion customer events per day from Kafka, fell behind on consumer lag because it spawned an unbounded number of goroutines to process and produce event batches.
- [Keep the monolith, but split the workloads](https://swe.quest/articles/keep-the-monolith-but-split-the-workloads-a46b5ee6a5f1e352.md): incident.io · 2023-04-12 · Medium · 9 min read · Resilience, System design, PostgreSQL, Go, Microservices
  A Go monolith can get much of the reliability isolation of microservices by splitting workloads into separate deployments of the same binary, instead of breaking it into services.
- [Goroutine Leak Profiles](https://swe.quest/articles/goroutine-leak-profiles-28367c8af5986ce1.md): The Go Blog · 2026-09-02 · Medium · 23 min read · Go, Concurrency, Memory management, Debugging, Runtimes & VMs
  Go 1.27 adds a goroutineleak profile that finds goroutines permanently blocked on channels or sync primitives (Mutex, RWMutex, WaitGroup, Cond) in running programs, including production, with few or no false positives.
- [Simple trick to save environment and money when using GitHub Actions](https://swe.quest/articles/simple-trick-to-save-environment-and-money-when-using-github-actions-14be6ffdb9f9e911.md): Turso · 2024-07-30 · Medium · 2 min read · CI/CD, Cost optimization
  GitHub Actions keeps running workflows for outdated pull request commits until they finish or fail.
- [Intermittent downtime from repeated crashes](https://swe.quest/articles/intermittent-downtime-from-repeated-crashes-9e00050b528fb037.md): incident.io · 2022-11-30 · Medium · 11 min read · Incidents & postmortems, Go, Resilience, Queues & messaging
  A poison-pill Pub/Sub message crashed incident.io's Go monolith on Heroku repeatedly, causing 13 minutes of downtime over 32 minutes.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
