Fan-out distributes work across multiple goroutines reading from a shared input channel. Fan-in merges results from multiple output channels into a single channel for the consumer.
Always close channels when producers are done — ranging goroutines exit cleanly
Use context cancellation to stop all workers when one fails or timeout occurs
Buffer the merged channel to avoid one slow worker blocking others
WaitGroup in fan-in ensures merged channel is closed only after all workers finish
For CPU-bound work, limit fan-out to runtime.NumCPU() workers