{"id":430,"date":"2026-05-23T09:00:00","date_gmt":"2026-05-23T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/"},"modified":"2026-05-23T09:00:00","modified_gmt":"2026-05-23T03:30:00","slug":"go-pipeline-fan-out-fan-in","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/","title":{"rendered":"Go Pipeline Pattern: Fan-Out and Fan-In Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Go pipeline pattern connects small steps with channels so data flows from one stage to the next. In this post, you will learn how stages work. You will also see how to split work across many goroutines and how to stop everything cleanly. Then we will build a three-part pipeline that squares numbers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-channels-examples\/\">Go channels with examples<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-context-beginners-guide\/\">Go context for beginners<\/a>. We also use ideas from <a href=\"https:\/\/smitabharat.com\/blog\/go-worker-pool-pattern\/\">Go worker pool pattern<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-select-statement\/\">Go select statement<\/a>. Because of that, a quick look at those posts will help.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is the Go Pipeline Pattern?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In short, a pipeline is a chain of stages. Each stage is a function that reads values from an input channel and does one job. After that, it sends the results to an output channel. Then the next stage picks them up.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a car wash. First, the car is soaped. Next, it is rinsed. Finally, it is dried. Each station does one job, and several cars can be inside at the same time. Similarly, in the Go pipeline pattern, every stage works while the others work too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Every stage follows the same shape. It takes <code>&lt;-chan int<\/code> as input and returns <code>&lt;-chan int<\/code> as output. As a result, you can plug stages together like building blocks. For example, you could add a filter stage between two others without touching the rest of the code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why the Go Pipeline Pattern Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A long function that does everything is hard to test and hard to speed up. Splitting it into stages is the main idea of the Go pipeline pattern. Fortunately, pipelines fix that problem. So here is what the Go pipeline pattern gives you.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Small stages<\/strong>: each function does one job, so it is easy to read and test.<\/li>\n\n\n\n<li><strong>Built-in concurrency<\/strong>: stages run in parallel without extra locks.<\/li>\n\n\n\n<li><strong>Easy scaling<\/strong>: you can run a slow stage in several goroutines.<\/li>\n\n\n\n<li><strong>Clean stopping<\/strong>: one context can cancel every stage at once.<\/li>\n\n\n\n<li><strong>Low memory use<\/strong>: values flow one by one, so you never hold the whole data set.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Because of this, pipelines suit file processing, image resizing, log parsing and data imports. For instance, a log tool can read lines, parse them and count errors in three stages. Meanwhile, each stage can use its own number of goroutines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Go Pipeline Pattern Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the Go pipeline pattern, a source stage first creates the data and sends it into a channel. Next, middle stages read, change and forward the values. Finally, the last stage collects the results. When a stage has no more values, it closes its output channel. As a result, the next stage ends its <code>range<\/code> loop on its own.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-1-1024x640.png\" alt=\"Go Pipeline Pattern diagram showing a generator, three square workers and a merge stage\" class=\"wp-image-409\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">A generator stage feeds three square workers through one channel. A merge stage then joins their outputs into a single result channel.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Notice the two special words used in this pattern. First, fan-out means that several goroutines read from the same channel to share the work. Second, fan-in means that one function merges many channels into a single channel.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Stage Rules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Good stages follow three simple rules, so the table below lists them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Rule<\/th><th>Why it matters<\/th><\/tr><\/thead><tbody><tr><td>The stage that creates a channel closes it<\/td><td>Readers can stop with <code>range<\/code><\/td><\/tr><tr><td>Stages read from <code>&lt;-chan<\/code> and return <code>&lt;-chan<\/code><\/td><td>Types prevent wrong sends<\/td><\/tr><tr><td>Every send also listens to <code>ctx.Done()<\/code><\/td><td>Stages can stop early without leaking<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you follow these rules, your pipeline will not leak goroutines. Otherwise, a stuck sender may wait forever. In practice, this single habit prevents most pipeline bugs. Because the Go pipeline pattern depends on closing channels, always check who owns each one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why Order Can Change<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With one worker, results keep their order. However, with several workers, whichever worker finishes first sends first. As a result, the output order can change. So sort the results at the end, or attach an index to each value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Pipeline Pattern vs Worker Pool<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Both patterns use goroutines and channels, but they solve different problems. For that reason, the table below compares them.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Pipeline<\/th><th>Worker pool<\/th><\/tr><\/thead><tbody><tr><td>Main idea<\/td><td>Many different stages in a line<\/td><td>Many workers doing the same job<\/td><\/tr><tr><td>Data flow<\/td><td>Output of one stage feeds the next<\/td><td>Jobs go in, results come out<\/td><\/tr><tr><td>Typical use<\/td><td>Read, transform, then save<\/td><td>Process a big queue of tasks<\/td><\/tr><tr><td>Scaling<\/td><td>Fan-out a slow stage<\/td><td>Add more workers<\/td><\/tr><tr><td>Complexity<\/td><td>Medium<\/td><td>Low<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-2-1024x640.png\" alt=\"Go Pipeline Pattern diagram comparing a pipeline with a worker pool\" class=\"wp-image-410\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">A pipeline passes data through different stages one after another, while a worker pool sends identical jobs to a group of equal workers.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when should you use which? Use a pipeline when the work has clear steps. On the other hand, use a worker pool when every task is the same. In fact, you can combine them by fanning out one stage of a pipeline.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Pipeline Pattern Hands-On: Square Numbers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s build a real pipeline. It sends the numbers 1 to 8 through a generator, three square workers and a merge step. Because everything uses only the standard library, you can run it as it is. Also, every output below comes from a real run on Go 1.24.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Generator and Square Stages<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, <code>gen<\/code> is the source. It sends each number into a channel. However, it stops early if the context is cancelled.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func gen(ctx context.Context, nums ...int) &lt;-chan int {\n\tout := make(chan int)\n\tgo func() {\n\t\tdefer close(out)\n\t\tfor _, n := range nums {\n\t\t\tselect {\n\t\t\tcase out &lt;- n:\n\t\t\tcase &lt;-ctx.Done():\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\treturn out\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, <code>square<\/code> reads numbers, squares them and sends the results on.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func square(ctx context.Context, in &lt;-chan int) &lt;-chan int {\n\tout := make(chan int)\n\tgo func() {\n\t\tdefer close(out)\n\t\tfor n := range in {\n\t\t\tselect {\n\t\t\tcase out &lt;- n * n:\n\t\t\tcase &lt;-ctx.Done():\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\treturn out\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Both stages use <code>select<\/code> with <code>ctx.Done()<\/code>. Because of this, a cancel call frees every goroutine, even if nobody is reading the output any more.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: The Fan-In Merge Function<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Then <code>merge<\/code> joins many channels into one. It starts one goroutine per input. Also, it uses a <code>WaitGroup<\/code> to know when all inputs are finished.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func merge(ctx context.Context, chans ...&lt;-chan int) &lt;-chan int {\n\tout := make(chan int)\n\tvar wg sync.WaitGroup\n\twg.Add(len(chans))\n\tfor _, c := range chans {\n\t\tgo func() {\n\t\t\tdefer wg.Done()\n\t\t\tfor v := range c {\n\t\t\t\tselect {\n\t\t\t\tcase out &lt;- v:\n\t\t\t\tcase &lt;-ctx.Done():\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}()\n\t}\n\tgo func() {\n\t\twg.Wait()\n\t\tclose(out)\n\t}()\n\treturn out\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The last goroutine waits for all workers and then closes <code>out<\/code>. In other words, the closing happens in exactly one place, which avoids a &#8220;close of closed channel&#8221; panic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Fan-Out and Run the Pipeline<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now we connect everything. Three <code>square<\/code> calls read from the same source, which is the fan-out step. After that, <code>merge<\/code> collects their results.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\tsrc := gen(ctx, 1, 2, 3, 4, 5, 6, 7, 8)\n\n\tw1 := square(ctx, src)\n\tw2 := square(ctx, src)\n\tw3 := square(ctx, src)\n\n\tvar results []int\n\tfor v := range merge(ctx, w1, w2, w3) {\n\t\tresults = append(results, v)\n\t}\n\tsort.Ints(results) \/\/ order can change, so we sort\n\tfmt.Println(\"squares:\", results)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the real output. We sort the results first, because the three workers finish in a different order on each run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>squares: [1 4 9 16 25 36 49 64]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Stop the Pipeline Early<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes you only need the first few values. In that case, call <code>cancel<\/code> and every stage exits. Here, we read two values and then stop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ctx2, cancel2 := context.WithCancel(context.Background())\ncount := 0\nfor v := range square(ctx2, gen(ctx2, 10, 20, 30, 40, 50)) {\n\tcount++\n\tfmt.Println(\"got\", v)\n\tif count == 2 {\n\t\tcancel2() \/\/ tell every stage to stop\n\t\tbreak\n\t}\n}\nfmt.Println(\"stopped early after\", count, \"values\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output confirms that the pipeline stops without waiting for the rest. In other words, the cancel call works as intended.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>got 100\ngot 400\nstopped early after 2 values<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Without the cancel call, the <code>gen<\/code> and <code>square<\/code> goroutines would stay blocked forever on a send. That is called a goroutine leak. You can also run <code>go run -race .<\/code> on this code, and the detector reports nothing. This means that the pipeline shares no memory in an unsafe way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with the Go Pipeline Pattern<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Forgetting to close channels<\/strong>: the next stage then waits forever. So always use <code>defer close(out)<\/code> in the stage that owns the channel, as every Go pipeline pattern needs.<\/li>\n\n\n\n<li><strong>Ignoring cancellation<\/strong>: a send with no <code>ctx.Done()<\/code> case can block forever. Therefore, use <code>select<\/code> on every send.<\/li>\n\n\n\n<li><strong>Closing a channel from the receiver<\/strong>: this can cause a panic. Instead, let only the sender close it.<\/li>\n\n\n\n<li><strong>Expecting the same order<\/strong>: fan-out changes the order. So sort or add an index.<\/li>\n\n\n\n<li><strong>Too many goroutines for tiny work<\/strong>: the cost of switching can be bigger than the gain. Measure first.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for the Go Pipeline Pattern<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Keep each stage small<\/strong>, because small stages are easy to test alone.<\/li>\n\n\n\n<li><strong>Pass a context to every stage<\/strong>, so you can stop the whole chain in one call.<\/li>\n\n\n\n<li><strong>Fan out only the slow stage<\/strong>, since fast stages gain nothing.<\/li>\n\n\n\n<li><strong>Use buffered channels with care<\/strong>, because a large buffer can hide a slow stage.<\/li>\n\n\n\n<li><strong>Return errors through a second channel or a result struct<\/strong>, so failures do not vanish.<\/li>\n\n\n\n<li>**Run <code>go test -race<\/code>**, since pipelines are concurrent by nature.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise the Go pipeline pattern, build a pipeline with three stages. The first reads lines from a slice. Next, the second converts them to upper case. Finally, a third stage counts the total characters. This gives you practice with every part of the pattern. Then fan out the upper-case stage to two workers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: reuse the <code>merge<\/code> function but change the type to <code>string<\/code>. Since Go 1.18 you can even make it generic with <code>func merge[T any](...)<\/code>. Then compare the results with and without fan-out.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages describe pipelines, context and the concurrency tools used here.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/blog\/pipelines\">Go Concurrency Patterns: Pipelines and cancellation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/context\">context package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/sync#WaitGroup\">sync.WaitGroup documentation<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Go pipeline pattern chains stages with channels.<\/li>\n\n\n\n<li>Each stage reads from one channel and sends to another.<\/li>\n\n\n\n<li>Fan-out means many goroutines read from one channel.<\/li>\n\n\n\n<li>Fan-in means a merge function joins many channels into one.<\/li>\n\n\n\n<li>Use <code>context<\/code> so that one cancel call stops every stage.<\/li>\n\n\n\n<li>Sort the results when order matters, because fan-out changes it.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By now, you can build flows of goroutines. However, a fast pipeline can also overload a service. So next, we will learn how to protect an API with rate limiting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next up: <a href=\"https:\/\/smitabharat.com\/blog\/go-rate-limiting\/\">Go rate limiting with the token bucket<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>The Go pipeline pattern connects small steps with channels so data flows from one stage to the next. In this post, you will learn&hellip;<\/p>\n","protected":false},"author":1,"featured_media":408,"comment_status":"","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[80,37,79,11],"swapz_series":[],"class_list":["post-430","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-advanced","tag-go-channels","tag-go-concurrency","tag-go-lang"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Pipeline Pattern: Fan-Out and Fan-In Explained<\/title>\n<meta name=\"description\" content=\"Learn the Go pipeline pattern step by step: build stages with channels, fan out work, merge results and stop everything with context.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Pipeline Pattern: Fan-Out and Fan-In Explained\" \/>\n<meta property=\"og:description\" content=\"Learn the Go pipeline pattern step by step: build stages with channels, fan out work, merge results and stop everything with context.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-23T03:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Pipeline Pattern: Fan-Out and Fan-In Explained\",\"datePublished\":\"2026-05-23T03:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/\"},\"wordCount\":1488,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pipeline-fan-out-fan-in-featured.png\",\"keywords\":[\"Advanced\",\"Go Channels\",\"Go Concurrency\",\"Go Lang\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/\",\"name\":\"Go Pipeline Pattern: Fan-Out and Fan-In Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pipeline-fan-out-fan-in-featured.png\",\"datePublished\":\"2026-05-23T03:30:00+00:00\",\"description\":\"Learn the Go pipeline pattern step by step: build stages with channels, fan out work, merge results and stop everything with context.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pipeline-fan-out-fan-in-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pipeline-fan-out-fan-in-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Pipeline Pattern featured image: source stage, fan-out workers and fan-in merge\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pipeline-fan-out-fan-in\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Pipeline Pattern: Fan-Out and Fan-In Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Pipeline Pattern: Fan-Out and Fan-In Explained","description":"Learn the Go pipeline pattern step by step: build stages with channels, fan out work, merge results and stop everything with context.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/","og_locale":"en_US","og_type":"article","og_title":"Go Pipeline Pattern: Fan-Out and Fan-In Explained","og_description":"Learn the Go pipeline pattern step by step: build stages with channels, fan out work, merge results and stop everything with context.","og_url":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-05-23T03:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Pipeline Pattern: Fan-Out and Fan-In Explained","datePublished":"2026-05-23T03:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/"},"wordCount":1488,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-featured.png","keywords":["Advanced","Go Channels","Go Concurrency","Go Lang"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/","url":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/","name":"Go Pipeline Pattern: Fan-Out and Fan-In Explained","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-featured.png","datePublished":"2026-05-23T03:30:00+00:00","description":"Learn the Go pipeline pattern step by step: build stages with channels, fan out work, merge results and stop everything with context.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pipeline-fan-out-fan-in-featured.png","width":2400,"height":1260,"caption":"Go Pipeline Pattern featured image: source stage, fan-out workers and fan-in merge"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Pipeline Pattern: Fan-Out and Fan-In Explained"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=430"}],"version-history":[{"count":0,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/430\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/408"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=430"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}