liveBook · Manning

Fan-out

As explained in Learn Concurrent Programming with Go

A fan-out pattern distributes messages from one source among multiple concurrent consumers so that each message is processed by one consumer.

Fan-out distributes work from one channel among multiple goroutines. Each goroutine reads the next available message, like multiple baristas serving customers from one queue. section 9.2.3

A practical fan-out pipeline follows these steps:

  • Create a shared input channel, such as a stream of URLs, and start a fixed set of downloadPages goroutines reading from it. section 9.2.3
  • Store each worker's output channel, then use fan-in to merge those channels before passing results to the next pipeline stage. section 9.2.3
  • Use fan-out only when processing order does not matter, because concurrent completion is nondeterministic. section 9.2.3 section 9.4

How Learn Concurrent Programming with Go covers it

How deep it goes
Defines shared-channel worker distribution and shows Go construction, but stops short of preserving message order.
Examples
Uses concurrent URL downloads, downloadPages workers, a shared input channel, and a coffee-shop queue analogy.
What it assumes
Assumes goroutines and channels, while grounding their use in message passing and pipeline stages.
What you can do after
Build it from scratch by launching channel-reading workers and combining their outputs with fan-in.
How it connects
Connects goroutines, channels, fan-in, pipelines, message passing, and broadcast patterns.

Also explained in

Compare how 2 books explain fan-out →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.