Using AI to Write Go Backends: Reviewing What It Generates

An example of AI-generated Go concurrency code that needed fixing, and why I review generated code line by line.

· 3 min read · Erik Kubica

AI assistants make it easy to get forty lines of Go that compile from a three-sentence prompt.

I call that vibecoding, and I find it genuinely useful. I use AI assistants in my development workflow most days. I can scaffold a JSON API router, generate repetitive validation schemas, and draft database migrations in twenty minutes instead of four hours. For routine scaffolding it has made me noticeably faster.

The catch I've run into is that the output needs a careful review, and what I know from past projects helps with that. Without a review, it is easy to ship code that works in a demo and fails in production.

The Goroutine Example

Recently, I prompted a model to build a concurrent event processor in Go. The task was to read a batch of 25,000 analytics events from a queue and dispatch webhook notifications to third-party endpoints.

Within 5 seconds, it generated code that looked clean and idiomatic. Here is what it gave me:

func processEvents(events []Event) {
    for _, event := range events {
        go func(e Event) {
            resp, err := http.Post(e.WebhookURL, "application/json", bytes.NewBuffer(e.Payload))
            if err != nil {
                log.Printf("failed delivery: %v", err)
                return
            }
            defer resp.Body.Close()
        }(event)
    }
}

At first glance this looks like simple concurrency. Having debugged production outages in PHP, Magento, and Node.js, I saw some problems with it.

The model spawned 25,000 simultaneous goroutines without a worker pool or a bounded channel. It used http.Post with http.DefaultClient, which has no request timeout. If an upstream webhook endpoint stalls for 30 seconds, 25,000 TCP sockets stay open. In my estimate that means memory growing by around 350 MB in twelve seconds, the file descriptor limit being hit, and the process falling over under heavy CPU load.

The model writes confident-looking code, but it has not seen how your system behaves under load, so the review stays with me.

I rejected the snippet and asked it to implement a bounded semaphore using a buffered channel with a strict 4-second timeout:

func processEventsBounded(ctx context.Context, events []Event, concurrency int) error {
    sem := make(chan struct{}, concurrency)
    client := &http.Client{Timeout: 4 * time.Second}
    var wg sync.WaitGroup

    for _, event := range events {
        select {
        case <-ctx.Done():
            return ctx.Err()
        case sem <- struct{}{}:
        }

        wg.Add(1)
        go func(e Event) {
            defer func() {
                <-sem
                wg.Done()
            }()
            req, _ := http.NewRequestWithContext(ctx, "POST", e.WebhookURL, bytes.NewBuffer(e.Payload))
            resp, err := client.Do(req)
            if err == nil {
                resp.Body.Close()
            }
        }(event)
    }
    wg.Wait()
    return nil
}

That bounded version handled about 1,200 req/s with memory staying around 18 MB.

What I Check in Generated Code

The model did not account for external networks failing or for rate limiters dropping unthrottled bursts. It produced the most likely-looking Go for the prompt.

The things I've learned from Magento indexers locking tables, Doctrine ORM hydration bloat in Symfony, and circular dependencies in React tell me where systems tend to break, so those are what I look for: unbounded concurrency, missing timeouts, and unclosed resources. When I use AI for code, I treat it as a fast typist and read every line before it goes anywhere near production. Someone with less experience can still do this well, but it helps to run the code under load and ask the model to explain its choices.

Tell me what you need built

Usually a reply within a day, by email or WhatsApp.