Production Go: Concurrency, Services & Profiling
Production Go code with leak-free goroutines, context-correct services, wrapped errors, and pprof-driven performance fixes.
Before & after
Same prompt, same agent — the only difference is the skill.
Designing a concurrent Go service is a great use of Go's strengths. You'll want to think about goroutines for concurrent execution, channels for communication between goroutines, and probably a worker pool or queue pattern to manage load. You might also want to consider error handling, graceful shutdown, and maybe some monitoring. The architecture depends on factors like request volume, processing time, and how much state you need to maintain. If you can tell me more about your expected throughput, what each request does, and any specific requirements you have, I can suggest a more tailored approach.
CONCURRENT REQUEST PROCESSOR PATTERN
ARCHITECTURE: Worker pool + buffered channel queue
CORE STRUCTURE
type RequestHandler struct {
input chan Request
workers int
timeout time.Duration
}
DESIGN DECISIONS
• Worker count: CPU core count (runtime.NumCPU()) for CPU-bound; 2x cores for I/O-bound
• Channel buffer size: 100-1000 (backpressure point; tune via benchmarks)
• Context timeout: Per-request, propagate to goroutines via context.WithCancel
FLOW
1. Main goroutine spawns N workers at startup
2. Each worker reads from input channel (blocks until request arrives)
3. Worker processes request (I/O calls use context.WithTimeout)
4. Results sent to output channel (non-blocking via separate channel)
5. Graceful shutdown: Close input channel, wait for workers via sync.WaitGroup
ERROR HANDLING
• Panic recovery per worker (recover() in defer)
• Timeout errors: Context.DeadlineExceeded logged, request marked failed
• Backpressure: If input channel full, reject with 429 to caller
OBSERVABILITY
• Metrics: Channel queue depth, worker busy count, request latency p99
• Logging: Structured logs (slog) with request ID and worker ID
• Pprof: Enable profiling endpoint for goroutine leaks checkAbout this skill
Your goroutines leak when a caller times out. Your service hangs on SIGTERM. Someone added sync.Pool and nobody can say whether it helped. This skill makes Claude write and review Go the way a strict reviewer on a high-traffic service would. Every goroutine gets an owner and an exit, every blocking call honors a context, and every performance claim comes with a profile.
What it does
- Writes fan-out and worker code with errgroup, bounded concurrency, and index-addressed results, so nothing leaks and there's no channel-closing guesswork
- Hardens HTTP and gRPC services: server and client timeouts, body limits, correct gRPC status codes, and graceful shutdown on SIGTERM
- Reviews pasted Go code by severity, with races, leaks, and deadlocks first, and catches traps like typed-nil errors, loop-variable capture, and copied mutexes
- Fixes error handling: useful %w wrapping, sentinel vs typed errors, and handling each error exactly once
- Picks the right profile for the symptom (CPU, heap, goroutine, block/mutex, trace) and compares changes with benchstat instead of a single run
- Pushes back on wrong premises, such as "channels are faster than mutexes" or "more goroutines will speed up this CPU-bound job"
What you get
Complete, gofmt-ready Go code or ranked review findings. Each comes with a short concurrency contract (who starts, cancels, and waits) and the exact vet, race, benchmark, or pprof commands to verify it.
Best for
Backend engineers shipping Go services, CLIs, and workers who want concurrent code that survives production. Also for teams chasing leaks, hangs, or slowdowns in existing Go code.
SKILL.md preview
---
name: production-go-concurrency-services-profiling
description: Writes and reviews production Go. Covers goroutines with explicit lifetimes and cancellation, context-correct HTTP/gRPC services with graceful shutdown, wrapped errors, table-driven tests, and pprof/benchstat-driven performance work. Use when the user says "write this in Go", "my goroutines are leaking", "my Go service hangs on shutdown", "fan out these requests concurrently", "why is my Go program eating memory", "review my Go code", "set up a gRPC service", "my benchmark got slower and I don't know why".
---
# Production Go: Concurrency, Services & Profiling
… (sign up to view the full skill)Featured in
More development skills
View all Development skills →Backend Feature Build Plan
Builds one backend feature through gates: confirmed requirements, one-screen design, small tested slices, and a deploy/rollback handoff.
Consistent, Safe Application Logging
Adds structured, correlated logs with useful severity, safe fields, bounded volume, and targeted verification.
Reliable WebSocket Messaging and Scaling
Build WebSocket and Socket.IO systems with authorized rooms, reconnect recovery, bounded queues, and multi-node presence.
Laravel App Build: Eloquent, Sanctum, Queues, Livewire
Laravel 12/13 code that ships: N+1-free Eloquent, correct Sanctum mode, idempotent queued jobs, lean Livewire, and Pest tests.