{"id":46,"type":"blog","title":"Why Go Keeps HTTP Services Small","slug":"why-go-keeps-http-services-small","canonicalUrl":"https://docs.phatysd.me/content/why-go-keeps-http-services-small","status":"published","revision":1,"publishedAt":"2026-09-19T17:51:06.174Z","updatedAt":"2026-09-19T17:51:06.174Z","hierarchyPath":"Go > Engineering Journal > Service Design","topics":["Go","HTTP","Service design","Engineering lessons"],"tags":["golang","go-http","architecture","maintainability"],"related":[{"slug":"go-http-service-foundations","title":"Go HTTP Service Foundations","type":"docs","canonicalUrl":"https://docs.phatysd.me/content/go-http-service-foundations"}],"body":"# Why Go Keeps HTTP Services Small\n\nThe first surprise in a Go HTTP service is how little framework is required.\n`net/http` gives you handlers, a multiplexer, a server, and a testable seam.\nThat simplicity is useful, but it also removes excuses: ownership, timeouts,\nerror mapping, and shutdown behavior have to be designed by the team.\n\n## The small surface is a feature\n\nA handler can be read from the outside in. It receives a request, calls an\napplication dependency, and writes a response. There is less hidden lifecycle\nand less magic between the route and the code that owns the behavior.\n\nThe trade-off is that a team must decide where validation, logging, metrics,\nauthentication, and dependency construction live. Go's restraint does not\nremove architecture. It makes architecture visible.\n\n## Modules make the dependency story explicit\n\n`go.mod` and `go.sum` make dependency changes reviewable. That matters for a\nservice that will run for a long time: the build should tell us which module\nversion was selected, rather than relying on a developer's global environment.\n\nThe habit that helped most was keeping the entrypoint boring. `main` wires the\nrouter, service, store, and server. It does not contain business decisions.\nWhen the entrypoint is boring, the interesting behavior becomes easier to test.\n\n## Context is the quiet contract\n\nPassing the request context through the service and store layers is not about\nsyntax. It is a promise that work can stop when the request is cancelled or its\ndeadline expires. Without that propagation, a client can disappear while\nexpensive work continues invisibly.\n\nThe same idea applies to shutdown. A service should stop accepting new work,\ngive current work a bounded window, and then close its dependencies. The\nshutdown path deserves the same design attention as the happy path.\n\n## What I would check in a review\n\n- Can I find the module and process entrypoint immediately?\n- Does every handler pass context to downstream work?\n- Are server timeouts explicit?\n- Can the service map expected domain errors without leaking internals?\n- Is there an HTTP-level test for each meaningful route?\n- Does SIGTERM produce a predictable exit instead of a hard kill?\n\nGo feels simple when these answers are clear. It feels unfinished when the\nteam expects the standard library to make those decisions automatically.\n\n## References\n\n- [Go modules tutorial](https://go.dev/doc/tutorial/call-module-code)\n- [Writing web applications with `net/http`](https://go.dev/doc/articles/wiki)\n- [`net/http` package reference](https://pkg.go.dev/net/http)\n- [`context` package reference](https://pkg.go.dev/context)"}