跪拜 Guibai
← Back to the summary

Go Concurrency: The Right Way to Parallelize API Calls (Context, Errgroup, and Boundary Protection)

🤔🤔Go concurrency keeps growing, but online stability keeps getting worse?

Author: Sailing

Tags: Backend, Go, Interview

An interface originally needed 600ms, but the product required it to return logs, metrics, and alerts at the same time.

The developer naturally thought: since the three downstreams are independent of each other, why not just start three goroutines to make the requests in parallel?

After the change, the interface latency did drop.

But shortly after going live, new problems began to appear:

At first, the goal was just to make the interface faster, but in the end, more time is spent dealing with timeouts, resource leaks, and production failures.

Where did the problem go wrong?

The truly dangerous part of Go concurrency is not that too many goroutines are created, but that concurrent tasks lack a clear lifecycle, error handling, panic boundaries, and resource limits.

This article starts from a typical aggregation interface and addresses three problems:

  1. Why is go func() plus sleep dangerous?
  2. How to use context + errgroup to manage concurrent tasks and handle panic and error aggregation?
  3. How to control request-level, service-level, and entry-level concurrency simultaneously to prevent goroutine pile-up and downstream overload?

The 4 pitfalls most likely to be stepped on during concurrency refactoring

First, look at a typical scenario.

An Overview interface needs to query three downstreams simultaneously:

                  Overview API
                       |
             +---------+---------+
             |         |         |
           日志服务   指标服务   告警服务
             |         |         |
           Log      Metrics    Alerts
             +---------+---------+
                       |
                    合并结果
                       |
                    返回响应

Yes, that’s right. The three requests have no dependencies and can definitely be executed in parallel.

Ideally, the interface latency is determined by the slowest of the three downstreams, not the sum of the three request latencies.

But if you only consider parallelism and ignore task management, you’re likely to encounter the following problems.

Pitfall 1: Using sleep to wait for goroutines, no guarantee of result completeness

First, look at a wrong example:

func LoadOverview(svc string) (Overview, error) {
    var (
        logs    LogSummary
        metrics MetricSummary
        alerts  AlertSummary
    )

    go func() {
        logs = queryLogs(svc)
    }()

    go func() {
        metrics = queryMetrics(svc)
    }()

    go func() {
        alerts = queryAlerts(svc)
    }()

    // Wrong approach: fixed wait of 300ms, cannot guarantee all three tasks have completed
    time.Sleep(300 * time.Millisecond)

    // May return data that hasn't been written yet, and there is a concurrent read/write risk
    return Overview{
        Logs:    logs,
        Metrics: metrics,
        Alerts:  alerts,
    }, nil
}

This code has three problems:

Remember: sleep can only wait for time, not for task completion.

Pitfall 2: Only adding locks and channels, while synchronization is solved, lifecycle is not

Some people might continue patching:

var (
    mu      sync.Mutex
    logs    LogSummary
    metrics MetricSummary
    alerts  AlertSummary
)

done := make(chan struct{}, 3)  // Create a buffered channel with capacity 3

go func() {
    v := queryLogs(svc)   // 1. Query logs
    mu.Lock()             // 2. Lock
    logs = v              // 3. Write shared variable
    mu.Unlock()           // 4. Unlock
    done <- struct{}{}    // 5. Notify the main goroutine: I'm done
}()

// The main goroutine loops three times, each time receiving a signal from `done`.
// The first `<-done` blocks until some goroutine sends a signal, the second blocks until the second, and the third blocks until the third.
// After receiving all three, it means all three goroutines have executed `done <- struct{}{}`.
for i := 0; i < 3; i++ {
    <-done
}

// metrics and alerts are handled similarly

Compared to the first version, at least there is a clear waiting mechanism. But the problems still exist:

Locks and channels solve synchronization, not the complete management of concurrent tasks.

Pitfall 3: Only limiting a single request, still can overwhelm downstream

Suppose each request can concurrently access up to three downstreams.

Looking at a single request, it seems completely fine. But if there are 1000 requests at the same time:

1000 API requests
       |
       | Each request has 3 concurrent tasks
       |
       v
Up to 3000 downstream concurrent requests

This is an easy-to-ignore problem: request-level concurrency limits are not service-level concurrency limits.

Even if you use errgroup.SetLimit(3), it only limits the number of concurrent tasks within this single request. Moreover, when the total number of tasks is exactly equal to the limit, SetLimit(3) does not provide a rate-limiting queue effect; its value lies in handling scenarios where more tasks are dynamically submitted, constraining the concurrency ceiling in advance.

Without global concurrency control, connection pool limits, or downstream rate limiting, peak periods can still overwhelm the dependency services.

Pitfall 4: Only limiting downstream concurrency, no entry-level rate limiting, goroutines still pile up

This is a more subtle problem.

A service-level semaphore can indeed limit the number of requests concurrently accessing a downstream, but it does not limit the number of goroutines waiting to acquire the semaphore.

With high QPS and downstream slowdown, each request still creates 3 goroutines, and a large number of goroutines block on Acquire. The HTTP handler goroutines are also waiting. The result is that downstream pressure just becomes the service’s own goroutine, memory, and queue pressure.

10000 entry requests
       |
       | Each request creates 3 goroutines
       |
       v
30000 goroutines, most of which are blocked on semaphores

So concurrency control must be layered. The entry layer must quickly reject or queue, rather than create goroutines indefinitely.

So, how do you do concurrency correctly?

1-48.jpeg

🔥🔥 The correct concurrency model: context + errgroup + boundary protection

Now that the problems are clear, don’t keep patching the original code.

A more reasonable approach is to redefine the management boundary of concurrent tasks. Here we use two core tools:

Tool Problem it solves
context Timeout control, request cancellation, task lifecycle
errgroup Concurrent task management, waiting for completion, error propagation

They each handle different things, and only when combined do they form a complete request-level concurrency model. On top of that, panic boundaries, error aggregation, and partial success strategies must be added.

1. Establish a unified context lifecycle

// Add an 800ms timeout to the original request context
ctx, cancel := context.WithTimeout(ctx, 800*time.Millisecond)
defer cancel()

Two key points:

context is only responsible for propagating cancellation signals; it does not forcibly terminate goroutines. The downstream Client must actively listen to and respond to this signal.

2. Use errgroup to manage concurrent tasks, adding panic boundaries

First, define the aggregation data structure and Client interfaces:

type Overview struct {
    Logs    LogSummary
    Metrics MetricSummary
    Alerts  AlertSummary

    // Marks whether any downstream failed, for the caller to judge data completeness
    Partial bool
    // Records downstream names that failed, for observability and troubleshooting
    // Use []error instead of []string to preserve original error types; callers can still use errors.Is to judge.
    // Load always returns Partial=false, Failed=nil; these fields are only for LoadPartial.
    Failed  []error
}

type LogClient interface {
    QuerySummary(ctx context.Context, svc string) (LogSummary, error)
}

type MetricClient interface {
    QuerySummary(ctx context.Context, svc string) (MetricSummary, error)
}

type AlertClient interface {
    QuerySummary(ctx context.Context, svc string) (AlertSummary, error)
}

type Loader struct {
    Logs    LogClient
    Metrics MetricClient
    Alerts  AlertClient
}

errgroup does not automatically recover. If a Client panics, the entire process may crash. So we need a helper function with panic protection:

// Wrap an errgroup task with panic protection
// safeGo receives two things: an *errgroup.Group and a “business function” f.
// It does not directly execute f, but wraps f with an anonymous function and hands it to g.Go.
func safeGo(g *errgroup.Group, name string, f func() error) {
    // The key is the anonymous function signature: func() (err error). It uses a named return value err, which is the core of this trick.
    // Without this wrapper, f() panic would directly escape the goroutine, the Go runtime prints a stack trace and terminates the entire process.
    // errgroup's Wait() only waits for goroutines to finish and collects return values; it does not recover panics.
    g.Go(func() (err error) { 
        defer func() {
            if r := recover(); r != nil {
                err = fmt.Errorf("%s: panic: %v\n%s", name, r, debug.Stack())
            }
        }()
        return f()
    })
}

Tip: The example puts the full stack trace into the error for debugging convenience; in production, it is not recommended to package the full stack trace into the returned error. The stack trace should be logged separately to avoid error message bloat.

Concurrent aggregation logic:

func (l *Loader) Load(ctx context.Context, svc string) (Overview, error) {
    // Unified timeout and cancellation. When the client actively cancels, or when 800ms expires, `ctx` will enter the cancelled state. `defer cancel()` ensures that timer resources are released when the function exits.
    ctx, cancel := context.WithTimeout(ctx, 800*time.Millisecond)
    defer cancel()

    // Create an errgroup and limit concurrency.
    // The `ctx` returned by `errgroup.WithContext` will be cancelled when the first task returns a non-nil error, and also after `Wait()` returns.
    g, ctx := errgroup.WithContext(ctx)
    g.SetLimit(3) // Limit the maximum number of tasks running at once in this group to 3.

    // The three variables are each written by only one goroutine; the main goroutine reads them after `g.Wait()` returns.
    // There is no data race here because `Wait()` returning establishes a happens-before relationship: all child goroutine writes happen before the main goroutine reads. So these three variables do not need locks.
    var (
        logs    LogSummary
        metrics MetricSummary
        alerts  AlertSummary
    )

    // Error collection. Thread-safe collection of all downstream errors, not just the first one.
    var (
        errMu sync.Mutex
        errs  []error
    )
    addErr := func(name string, err error) {
        errMu.Lock()
        // Because all three goroutines may append to `errs`, a mutex is required. This is the only place in this code that needs a lock.
        errs = append(errs, fmt.Errorf("%s: %w", name, err))
        errMu.Unlock()
    }

    // The following are the three tasks.
    // Each task has the same structure. On success, write to its own variable; on failure, record the error and return it. `safeGo` converts panics into errors.
    safeGo(g, "logs", func() error {
        v, err := l.Logs.QuerySummary(ctx, svc)
        if err != nil {
            addErr("logs", err)
            return err
        }
        logs = v
        return nil
    })

    safeGo(g, "metrics", func() error {
        v, err := l.Metrics.QuerySummary(ctx, svc)
        if err != nil {
            addErr("metrics", err)
            return err
        }
        metrics = v
        return nil
    })

    safeGo(g, "alerts", func() error {
        v, err := l.Alerts.QuerySummary(ctx, svc)
        if err != nil {
            addErr("alerts", err)
            return err
        }
        alerts = v
        return nil
    })

    // Wait and merge errors
    waitErr := g.Wait()

    // Merge all errors, preserving complete troubleshooting information
    errMu.Lock()
    allErrs := errors.Join(errs...)
    errMu.Unlock()

    if waitErr != nil {
        // Decide based on business: all-or-nothing, or partial success
        if allErrs != nil {
            return Overview{}, errors.Join(waitErr, allErrs)
        }
        return Overview{}, waitErr
    }

    return Overview{
        Logs:    logs,
        Metrics: metrics,
        Alerts:  alerts,
    }, nil
}

Several key points here:

Another easy-to-ignore detail: the context created by errgroup.WithContext gets cancelled when a task returns an error, and also after Wait() returns. Therefore, do not use this context for other business logic after Wait().

3. Partial success strategies must be explicitly designed

The Load above uses an “all-or-nothing” strategy. But aggregation interfaces often need partial success: one downstream being unavailable shouldn’t make the entire interface unavailable. Users seeing logs and metrics is better than seeing nothing, even if the alert query fails.

However, there is a constraint that must be stated upfront:

LoadPartial cannot reuse Load's errgroup.WithContext. errgroup cancels the shared context when the first task returns an error, so other downstreams would be interrupted early, making LoadPartial “nominally partial success, but actually fail-fast.” The correct approach is to use sync.WaitGroup to start tasks, letting each downstream execute to completion independently, and finally collect results and errors together.

// Overview is already defined in Section 2, no need to redefine it here.

func (l *Loader) LoadPartial(ctx context.Context, svc string) (Overview, error) {
    ctx, cancel := context.WithTimeout(ctx, 800*time.Millisecond)
    defer cancel()

    // Key difference: do not use errgroup.WithContext.
    // A single downstream failure must not cancel the others, otherwise it's not “partial success.”
    var wg sync.WaitGroup

    var (
        logs    LogSummary
        metrics MetricSummary
        alerts  AlertSummary
    )

    // Collect all downstream errors, not just the first one
    var (
        errMu sync.Mutex
        errs  []error
    )
    addErr := func(err error) {
        errMu.Lock()
        errs = append(errs, err)
        errMu.Unlock()
    }

    // run is responsible for starting tasks, recovering panics, and uniformly adding downstream names before collecting errors.
    // f returns the raw error only, no longer wrapping it, to avoid duplicate error messages.
    run := func(name string, f func() error) {
        wg.Add(1)
        go func() {
            defer wg.Done()
            defer func() {
                if r := recover(); r != nil {
                    addErr(fmt.Errorf("%s: panic: %v\n%s", name, r, debug.Stack()))
                }
            }()
            if err := f(); err != nil {
                addErr(fmt.Errorf("%s: %w", name, err))
            }
        }()
    }

    run("logs", func() error {
        v, err := l.Logs.QuerySummary(ctx, svc)
        if err != nil {
            return err
        }
        logs = v
        return nil
    })

    run("metrics", func() error {
        v, err := l.Metrics.QuerySummary(ctx, svc)
        if err != nil {
            return err
        }
        metrics = v
        return nil
    })

    run("alerts", func() error {
        v, err := l.Alerts.QuerySummary(ctx, svc)
        if err != nil {
            return err
        }
        alerts = v
        return nil
    })

    wg.Wait()

    // Important boundary: if it's client cancellation or overall timeout, it's not a “downstream partial failure.”
    // It should directly return the ctx error instead of masquerading as partial success.
    if err := ctx.Err(); err != nil {
        return Overview{}, err
    }

    // wg.Wait() has established happens-before, so reading results here needs no additional locks.
    ov := Overview{
        Logs:    logs,
        Metrics: metrics,
        Alerts:  alerts,
    }

    errMu.Lock()
    ov.Failed = append(ov.Failed, errs...)
    errMu.Unlock()

    ov.Partial = len(ov.Failed) > 0

    if ov.Partial {
        // Partial success is the scenario that most needs measurement; don't just log one line.
        // It's recommended to also report structured metrics, for example:
        // overview_partial_total{failed_downstream="logs"}
        for _, e := range ov.Failed {
            log.Warnf("partial overview: %v", e)
        }
    }

    return ov, nil
}

Note: sync.WaitGroup will wait for all tasks to complete; it does not automatically stop waiting on ctx timeout. If the business requires giving up waiting immediately after a timeout, you need to listen to ctx.Done() in a loop.

Several key points of this implementation:

Callers must be clear about the contract: LoadPartial returning a nil error does not mean data is complete; you must check ov.Partial. If you’re worried about callers missing this, you can also agree that when Partial == true, return a recognizable sentinel error, forcing callers to enter the branch with err != nil. Neither approach is absolutely better; it depends on which contract the team is more used to.

Test must cover these cases:

Scenario Expected
All three downstreams succeed Partial == false, Failed empty, err == nil
One downstream fails Partial == true, Failed contains only that downstream's error, other fields have normal data
Multiple downstreams fail Failed contains all failed downstreams, and errors.Is can identify the original error type
Client cancels / overall timeout Returns ctx.Err(), cannot return partial success
One downstream panics Process doesn't crash, Failed contains a panic error with the downstream name

This way, Load handles “strong consistency, fail-fast” while LoadPartial handles “best-effort, explicitly marking completeness.” The two strategies have clear boundaries, and callers can choose based on business semantics.

4. Downstream timeout and retry budgets

An overall 800ms timeout is not granular enough. Production should also consider:

// Set a tighter timeout for a single downstream, automatically taking the smaller of parent ctx remaining time and configured timeout
logDeadline, hasDeadline := ctx.Deadline()
logTimeout := 300 * time.Millisecond
if hasDeadline {
    if remain := time.Until(logDeadline); remain < logTimeout {
        logTimeout = remain
    }
}
logCtx, logCancel := context.WithTimeout(ctx, logTimeout)
defer logCancel()

v, err := l.Logs.QuerySummary(logCtx, svc)

Be cautious with retries. Combining concurrency, retries, and timeouts all at once can easily hammer the downstream even harder. It’s recommended to first complete the concurrency model refactor, then adjust the retry strategy separately.

5. The Client layer must genuinely support context

The Loader above has passed the context down, but if the Client doesn’t use it, the cancellation mechanism still won’t take effect.

func (c *LogClient) QuerySummary(ctx context.Context, svc string) (LogSummary, error) {
    // NewRequestWithContext binds ctx to the request; ctx cancellation/timeout will terminate this http request
    req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.url(svc), nil)
    if err != nil {
        return LogSummary{}, err
    }

    // Do executes the request and listens to the ctx bound to the request; it interrupts IO when receiving a cancellation signal
    resp, err := c.httpClient.Do(req)
    if err != nil {
        return LogSummary{}, err
    }
    // Must close the body to prevent http connection leaks
    defer resp.Body.Close()

    if resp.StatusCode != http.StatusOK {
        return LogSummary{}, fmt.Errorf("logs service returned status: %d", resp.StatusCode)
    }

    // Parse the response body
    return parseLogSummary(resp.Body)
}

The most important part is http.NewRequestWithContext(ctx, ...). It associates the HTTP request with the current context.

Whether a concurrent task can truly exit ultimately depends on whether the lowest-level I/O operation supports cancellation.

d522cab57c4deb76f9c290abe51e94890319fe0d.jpeg

🤔🤔 Beyond request-level, service-level, entry-level, and connection pool control are needed

Use a semaphore to limit global downstream concurrency (fix the race)

Many partners only use errgroup for concurrency control within a single request, ignoring the cross-request shared downstream concurrency ceiling. The errgroup limit only applies to the current request; when multiple requests arrive simultaneously, the total downstream concurrency stacks up and overwhelms the dependency.

An in-process semaphore is used to constrain the global concurrency of the entire service instance accessing one downstream. It is service-side resource protection.

// Semaphore is an in-process semaphore that limits the maximum number of concurrent accesses to a downstream service by a single instance
type Semaphore struct {
    slots chan struct{}
}

// NewSemaphore creates a semaphore; limit is the maximum number of concurrent slots
func NewSemaphore(limit int) (*Semaphore, error) {
    if limit <= 0 {
        return nil, fmt.Errorf("semaphore limit must be positive")
    }
    return &Semaphore{slots: make(chan struct{}, limit)}, nil
}

// Acquire acquires a semaphore slot, supporting context timeout/cancellation
// select is atomic: either you get the slot successfully, or ctx is cancelled first; there is no race risk of returning a slot after acquiring it
func (s *Semaphore) Acquire(ctx context.Context) error {
    // Fast path: if ctx is already cancelled, return directly; no need to enter select
    if err := ctx.Err(); err != nil {
        return err
    }
    select {
    case s.slots <- struct{}{}:
        // Successfully acquired slot
        return nil
    case <-ctx.Done():
        // Request cancelled/timed out, acquire failed
        return ctx.Err()
    }
}

// Release releases a slot; must be paired with Acquire, preferably with defer
func (s *Semaphore) Release() {
    <-s.slots
}

Usage:

// Try to acquire the downstream concurrency quota
if err := semaphore.Acquire(ctx); err != nil {
    return LogSummary{}, err
}
// Release the slot when the function exits
 defer semaphore.Release()

return client.QuerySummary(ctx, svc)

The semaphore should be shared by the service instance, not created per request. As mentioned, if the three downstreams have different capacities, it’s best to set separate concurrency limits.

In multi-instance deployments, an in-process semaphore is not a cluster-level limit. It needs to be combined with gateway, downstream rate limiting, or distributed resource control.

Entry in-flight limit: prevent goroutine pile-up

In-flight refers to requests that have entered the service but have not yet finished processing. A semaphore only limits downstream concurrency; it does not limit waiting goroutines. The entry layer also needs fast rejection or queuing:

// InFlightLimiter controls the total number of concurrent requests handled by a single instance
 type InFlightLimiter struct {
    sem chan struct{}
}

// NewInFlightLimiter creates an entry concurrency limiter
func NewInFlightLimiter(limit int) *InFlightLimiter {
    return &InFlightLimiter{sem: make(chan struct{}, limit)}
}

// TryAcquire non-blockingly attempts to acquire a slot; returns false on failure, fail-fast
func (l *InFlightLimiter) TryAcquire() bool {
    select {
    case l.sem <- struct{}{}:
        return true
    default:
        return false
    }
}

// Release releases a slot; ensure release with defer
func (l *InFlightLimiter) Release() {
    <-l.sem
}

Native net/http handler example:

// Try to acquire the entry processing slot
if !limiter.TryAcquire() {
    http.Error(w, "too many requests", http.StatusTooManyRequests)
    return
}
defer limiter.Release()

With the Gin framework, the handler looks like:

// In-flight limiter in a Gin handler
if !limiter.TryAcquire() {
    // Return the standard 429 rate limit response
    c.JSON(http.StatusTooManyRequests, gin.H{"code": 429, "msg": "too many requests"})
    return
}
defer limiter.Release()

In this way, peak periods fail fast rather than creating goroutines indefinitely. Combined with monitoring in-flight counts, rejection rates, and semaphore wait times, you can detect capacity issues early.

Connection pool and Transport limits

Connection pool and Transport refer to Go http.Client's underlying TCP connection reuse manager, which controls the establishment, reuse, and reclamation of TCP connections to downstreams. It is an often-ignored underlying bottleneck.

Only relying on semaphores is not enough. The HTTP Client also needs attention to the underlying connection pool configuration to avoid connection exhaustion:

transport := &http.Transport{
    MaxConnsPerHost:     50,  // Maximum concurrent connections per host
    MaxIdleConnsPerHost: 20,  // Maximum idle connections per host
    IdleConnTimeout:     90 * time.Second, // Idle connection timeout, auto recycle
}

Also configure http.Server read/write timeouts and request body size limits. Otherwise, concurrency control logic and connection pool behavior will be inconsistent, still leading to connection leaks and connection saturation.

Concurrency control is divided into four layers

Control layer Main role Common solutions
Entry-level Limit the number of concurrent requests handled by a single instance, fast rejection InFlightLimiter
Request-level Limit the number of tasks per request errgroup.SetLimit
Service-level Limit the total concurrency of a single instance to downstreams Semaphore
Cluster-level Control the overall traffic and downstream quota of multiple instances APISIX/Gateway gateway rate limiting, downstream quota

Additional note: Cluster-level rate limiting (APISIX, Ingress Gateway) is usually configured via gateway console rules, not requiring business code. It intercepts large external traffic surges, while the in-process InFlightLimiter acts as a service-side fallback to solve internal goroutine pile-up caused by downstream RT degradation. The two are used together.

Another point worth noting: concurrency limits do not equal QPS limits. Concurrency limits control the number of tasks currently executing; QPS limits control the total number of requests initiated per unit time. If the downstream has strict request frequency quotas, you additionally need a rate limiting mechanism like a token bucket.

Additional note: The semaphore implemented in this article is an in-process single-machine semaphore, effective only for the current Pod. In multi-Pod, multi-cluster deployments, each Pod counts independently and cannot perceive other instances' concurrency, so a global concurrency ceiling is not possible. Engineering trade-off recommendations:

  • Preferred: Have the downstream service itself perform rate limiting, circuit breaking, and quotas. This is the most stable and lowest-ops-cost approach.
  • Alternative: If the business strictly requires our side to uniformly control the total concurrency of all instances to downstreams, then introduce a Redis-based distributed token bucket or distributed semaphore. However, this brings extra network overhead, race conditions, and availability issues, with significantly higher complexity. Do not use unless necessary.

Here is a common misconception: horizontal scaling of Pods does not conflict with fan-out concurrency inside an interface.

Scaling out is to handle higher entry QPS, while parallel downstream calls within a single request are to reduce response latency. However, as the number of Pods increases, the concurrency inside each Pod stacks up, and the total downstream pressure is amplified in sync. This is also a core reason to rely on downstream protection first.

4bed2e738bd4b31cfc6dad318efea5749f2ff89e.webp

Final summary: Go concurrency must guard these 4 boundaries

Returning to the original problem.

Parallel calls to three downstreams do shorten the interface response time.

But the real deliverable of concurrency refactoring is not just faster execution, but controllable task lifecycle, clear error propagation, panic boundaries, and stable resource boundaries.

You can remember these four points:

  1. Synchronization boundary: Do not use sleep to wait for task completion; use errgroup or WaitGroup to establish a clear synchronization point.
  2. Lifecycle boundary: Pass context from Handler to Client so cancellation and timeout run through the entire call chain.
  3. Failure boundary: Add recover at goroutine entry, aggregate errors instead of keeping only the first, and explicitly design partial success strategies.
  4. Resource boundary: Use in-flight fast rejection at the entry, errgroup.SetLimit at the request level, semaphores at the service level, and supplement with connection pool and gateway cluster rate limiting.

The biggest mistake in Go concurrency is seeing only the performance gain from goroutines and ignoring the resource consumption and lifecycle management issues they bring.

I hope this article is helpful and provides insights.