Go Development Patterns

Golang Concurrency Patterns : Fan in, Fan out

Supratim Samanta
Geek Culture
4 min readSep 9, 2021

--

One of the most prominent reasons of loving Golang personally, is how easy we can build a highly available concurrent and non blocking program.

Photo by Annie Spratt on Unsplash

In this series of posts, I will try to reminisce the patterns available in Golang. I will take every pattern and discuss in detail where they fit and how to use them effectively.

What is Fan in and Fan out. It’s a way to converge and diverge data into a single data stream from multiple streams or from one stream to multiple streams or pipelines.

A generator function

For this pattern to discuss, we need a data source first. Here is a generator of data which can be used as a data source.

The above function as it is evident returns a receive only channel.

The consumer of this function can only receive data from the channel.

--

--

Supratim Samanta
Geek Culture

300K+views 🙏🏼#Unconventional #ProblemSolver #Tech #Dev #Productivity . Join my fascinating journey.🕺 Support me at https://susamn.medium.com/membership