Go Concurrency Patterns: Fan-Out and Fan-In

In our previous articles, we explored the Generator and Pipeline patterns, which are ideal for scenarios where a single consumer processes a stream of data. These patterns are powerful, but they can be limited in situations where you want to fully leverage the capabilities of modern multi-core processors or need to handle I/O-bound tasks more efficiently. To achieve this, we can extend our approach to distribute workloads across multiple consumers....

August 27, 2024 · 14 min · 2876 words · Jose Sitanggang

Go Concurrency Patterns: Pipeline

In a previous article, we explored the Generator pattern, which allows us to compute values lazily in Go. Now, we’re diving into another concurrency pattern: the Pipeline. This pattern enables us to process data step-by-step through a series of operators. If you’re familiar with Java Streams, which process data by passing each value through a set of filters, we’ll be taking a similar approach but leveraging Go’s concurrency features....

August 26, 2024 · 12 min · 2416 words · Jose Sitanggang

Go Concurrency Patterns: Generator

The generator pattern is a mechanism for producing values on demand, meaning values are generated incrementally and only when the consumer requests them. This pattern allows for infinite sequences or large datasets to be produced one element at a time, optimizing memory usage and enabling lazy evaluation. The generator pattern we’ll cover in this article is similar to the yield keyword in Python and the generator function in JavaScript....

August 25, 2024 · 8 min · 1594 words · Jose Sitanggang