Golang / GoLang Production Patterns and Web Standards Interview Questions
What is the production readiness checklist for a Go HTTP service?
This summary covers the essential checks interviewers probe when asking 'is this service production-ready?' It combines all the topics from this set into a concise reference.
| Category | Requirement |
|---|---|
| Error handling | All errors wrapped with %w; errors.Is/As used for inspection; typed nil trap avoided |
| Context | context.Context propagated to all blocking operations; cancel always deferred |
| HTTP server | ReadTimeout, WriteTimeout, IdleTimeout configured; graceful shutdown implemented |
| Middleware | Recovery, logging, auth, metrics, rate limiting applied in correct order |
| Logging | Structured logging (slog) with request IDs; no sensitive data logged |
| Metrics | Prometheus /metrics endpoint; request count, latency, error rate tracked |
| Health checks | /healthz (liveness) and /readyz (readiness) endpoints |
| Configuration | Loaded and validated at startup; no os.Getenv in business logic |
| Security | JWT validated (alg checked); input sanitised; CORS configured |
| Database | Connection pool configured; all queries use context; rows.Close deferred |
| Graceful shutdown | SIGTERM handled; in-flight requests drained; connections closed |
| Testing | Table-driven tests; -race flag in CI; goleak in goroutine tests |
| Profiling | pprof on internal port; not public-facing |
| Linting | golangci-lint + govulncheck in CI pipeline |
// One-line checklist for interview answers: // 1. Errors: always wrap (%w), never swallow, typed nil trap avoided // 2. Context: propagate to all I/O, defer cancel(), use r.Context() in handlers // 3. HTTP server: set all timeouts, graceful shutdown on SIGTERM // 4. Middleware chain: recovery â logging â auth â rate limiting â handler // 5. Configuration: load + validate at startup, inject as struct // 6. Health: /healthz (alive?) + /readyz (ready?) separate endpoints // 7. Observability: structured logs + Prometheus metrics + pprof // 8. Security: validate JWT alg, sanitise inputs, whitelist CORS origins // 9. Testing: table-driven, -race, httptest.NewRecorder, mock via interfaces // 10. CI: vet + golangci-lint + govulncheck + go test -race
More Related questions...