Fiber gRPC Under the Microscope: Prompts That Make an LLM Design Contracts, Hunt Goroutine Leaks, and Admit When Your Service Is Degrading

A service that returns 200 while its goroutine count climbs from 400 to 9,000 is not healthy — it is quiet. That is the failure mode prompts can catch earlier than dashboards, if you point them at the right artifact.

Below is a working kit for Go backends on Fiber and gRPC. Each prompt is paired with what the model actually returns, and where it lies to you.

Stage 1: Contract first — make the LLM design the interface before code

The strongest use of an LLM in Go is not writing handlers. It is arguing with you about the contract. Ask for the proto and the REST surface in one pass, then force it to justify every field.

You are a Go backend architect. Design a gRPC service Orders and a Fiber REST gateway for it.
Requirements: idempotent CreateOrder, paginated ListOrders, cancellable WatchOrder.
Output: (1).proto with comments on every field explaining why it exists; (2) mapping table gRPC method -> REST route -> status codes; (3) list of fields you deliberately left out and why.
Do not write Go code yet.

You get a proto draft, a route table, and — the useful part — a list of omissions. In practice the model puts google.protobuf.Timestamp everywhere and forgets that WatchOrder needs a context cancellation story on the gateway side.

Where it helps: naming, field granularity, proto3 optional vs wrapper types, HTTP mapping via google.api.http. Where it does not: it will happily invent a google.api.http annotation that your grpc-gateway version does not support. Check the annotation against your actual generated code, not against the model's confidence.

Stage 2: Timeouts and context — the prompt that exposes the lie

Most "context-aware" code from an LLM is ctx, cancel:= context.WithTimeout(ctx, 5*time.Second) pasted at the top of a handler, with the cancel deferred inside a loop. Ask for the trace instead of the snippet.

Here is my Fiber handler and the gRPC client call it makes. Trace the context from the HTTP request to the gRPC call: where is the deadline set, what is the remaining budget at each hop, and what happens to in-flight goroutines when the client disconnects at t=2s?
Point out every place where a cancel func is not deferred or a context is stored in a struct.

Feed it 30 lines of real handler. The answer you want is a timeline: HTTP deadline 5s, minus 200ms middleware, minus retry budget — and a flag that context.WithTimeout inside a retry loop multiplies your goroutines by attempt count. That specific mistake is the one that shows up in pprof as thousands of goroutines parked in select.

Ask for the budget, not the boilerplate Never accept "add a timeout" as an answer. Demand the remaining milliseconds at each hop — that number is what you actually review.

Stage 3: Reading pprof and race reports together

A goroutine dump alone is noise. The prompt that works gives the model the shape of the graph, not the whole file.

Here is go tool pprof -top output for goroutines (top 15) and a race detector report. Identify: (1) which goroutine stacks share a common blocking call; (2) whether the race is on shared state or on a channel close; (3) the two most likely lines in my code to inspect first.
Do not propose a fix until you state what evidence would confirm your hypothesis.

That last sentence is the whole trick. Without it you get a confident rewrite of code the model has never seen. With it, you get a hypothesis and a test — usually "grep for go func inside this handler and check whether the channel is buffered".

The model is genuinely good at pattern-matching chan receive stacks against unbuffered-send deadlocks. It is bad at knowing your scheduler pressure. Treat its answer as a search direction, not a diagnosis.

Stage 4: The degradation prompt — where the model earns its keep

Silent degradation is a design question, not a bug. Ask the LLM to stress the failure story.

My Fiber service depends on a gRPC backend. Under load, p99 latency triples but error rate stays at 0.1%. List every mechanism that can produce this signature, ranked by likelihood for a Go service using connection pooling and a semaphore.
For each, give one metric or log line that would confirm or rule it out.

This is where prompts beat search results: you get a ranked hypothesis table instead of a tutorial. Typical output — connection pool exhaustion, goroutine queueing behind a semaphore, and gRPC MaxConcurrentStreams throttling — each with a confirming signal.

Symptom Likely cause What confirms it
p99 up, errors flat pool/semaphore queueing runtime.NumGoroutine() climbing, wait time metric
errors flat, CPU flat stream limit throttle gRPC MaxConcurrentStreams in server logs
latency up after deploy retry amplification request count vs upstream count ratio

The boundary: the model cannot tell you your actual pool size or your load balancer's behavior. It gives you the checklist; you run the check.

Stage 5: What to verify by hand, every time

After any LLM answer on Go concurrency, run this list before merging:

  • Does every context.WithTimeout have a matching defer cancel() on the same scope?
  • Is any context.Context stored in a struct field?
  • Are goroutines started in a handler tied to the request context?
  • Does the race detector output actually name your code, or library internals?
  • Do the generated proto annotations match your protoc plugin version?
  • Is the retry policy bounded, or does it multiply goroutines?

If the model's answer passes all six, it is probably fine. If it fails even one, the confident prose around it was decoration.

The honest summary: prompts save hours on contract design, timeout tracing, and hypothesis generation from profiles. They create false safety when you accept rewritten concurrency code without running it under -race and real load. The model reads artifacts well and the Go scheduler not at all.

Start with Stage 1 on your current service — the omissions list alone usually finds a field you will regret shipping.

← All posts

Ask AI about this article

Ask a question about this article — ASI Biont will answer based on its text.