The fan-out/fan-in pattern is a concurrency design pattern commonly used in Go for parallelizing and coordinating concurrent tasks. It is particularly useful when you have a time-consuming task that can be divided into smaller subtasks that can be executed concurrently.
Fan-out: In the fan-out stage, a single task is divided into multiple smaller subtasks, which are then executed concurrently. Each subtask can be assigned to a separate goroutine (lightweight concurrent thread in Go) to run in parallel. This stage distributes the workload across multiple goroutines, allowing for parallel processing.
Fan-in: In the fan-in stage, the results or outputs from all the concurrently executing subtasks are collected and combined into a single result. This stage waits for all the subtasks to complete and aggregates their results. The fan-in stage can also handle synchronization and coordination between the goroutines to ensure that all results are collected before proceeding.
![Screenshot 2024-04-07 at 1 42 53 AM](https://private-user-images.githubusercontent.com/60144525/320232108-6760b5e3-a509-4f7e-9cd0-91b992f15895.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIzNzYwOTIsIm5iZiI6MTcyMjM3NTc5MiwicGF0aCI6Ii82MDE0NDUyNS8zMjAyMzIxMDgtNjc2MGI1ZTMtYTUwOS00ZjdlLTljZDAtOTFiOTkyZjE1ODk1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzMwVDIxNDMxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQwZTY1NzlmNDAwYTk3ZmRiNDFiYmRhZjQ3MTk0YTE5MjA2YmY2ZGJmYTQ2ZGE1ZDEyNDdiMTZjNjgwNWRhNmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.58VjqZM_bV8_csS_gYNde_CqrmTV781F2bgqZy9B2yU)
- Go installed on your machine. You can download and install it from here.
- Clone the repository to your local machine:
git clone https://github.com/AmitrajitDas/go-fan-out-fan-in-pipeline.git
- Execute
go run main.go