Technical Senior Level

Describe the fan-out/fan-in concurrency pattern. When would you use it and what pitfalls should you watch for?

Quick Tip

Show production awareness: "I use errgroup.Group with a concurrency limit. Each worker reads from a shared channel, processes, and sends results to an output channel. The group handles error propagation and cancellation."

What good answers include

Fan-out: launch multiple goroutines to process work from a shared channel. Fan-in: merge results from multiple goroutines into a single channel. Use cases: parallel HTTP calls, batch processing, pipeline stages. Pitfalls: unbounded goroutine creation (use a worker pool with a semaphore or fixed goroutine count), error propagation (use errgroup.Group), result ordering if needed, and clean shutdown via context cancellation. Strong candidates mention the sync and errgroup packages.

What interviewers are looking for

Senior concurrency question. Candidates who can whiteboard fan-out/fan-in with proper shutdown and error handling demonstrate real concurrent systems experience. Ask about backpressure handling.

← All Go questions