The fan-out fan-in pattern is a Go concurrency technique where you distribute work across multiple goroutines (fan-out) and then collect their results back into a single channel (fan-in). This pattern is useful when you have independent work items that can be processed in parallel.
Fan-out refers to starting multiple goroutines to handle slices of work, each writing results to a shared channel. Fan-in refers to the central collection point that reads from that channel until all results are received. This pattern naturally expresses the idea of parallel processing and result aggregation.
The key is correctly managing channel lifetimes and knowing when all goroutines have finished so you don’t deadlock while waiting for results. Using buffered channels can help ensure goroutines don’t block while writing their results.