Go's standard library is enough to build a working microservice: net/http serves and calls HTTP APIs, encoding/json handles payloads, context carries deadlines and cancellation across service boundaries, log/slog writes structured logs, and net/rpc or net support lower-level protocols. For production systems you add modules for gRPC, message brokers and tracing, but the standard library covers the core of every service and keeps dependencies small.
This article shows a service with graceful shutdown, a client with timeouts and retries, and the strategies that make a distributed Go system reliable.
Since Go 1.22 the default ServeMux supports methods and path parameters, so a small service needs no router module.
Always set a health endpoint for orchestrators such as Kubernetes, and always use http.Server rather than the bare http.ListenAndServe so you can set timeouts and shut down cleanly.
A service that is killed mid-request drops work. Handle SIGTERM, stop accepting connections and let in-flight requests finish.
The timeouts protect against slow clients that hold connections open.
Every outbound call needs a timeout. Create one shared http.Client, which reuses connections, and pass a context per request.
Retry only idempotent requests, use exponential backoff with jitter in production, and stop retrying when the context is cancelled.
| Option | Package | Best for |
|---|---|---|
| REST and JSON | net/http, encoding/json | Public APIs, simple internal calls |
| gRPC and Protocol Buffers | google.golang.org/grpc (module) | Fast typed internal calls, streaming |
| Message queues | Kafka, NATS or RabbitMQ clients (modules) | Asynchronous events, decoupling |
net/rpc | Standard library | Frozen and not recommended for new work |
The standard library has no broker or gRPC support, so those come from modules. Prefer events for workflows that cross service boundaries, and use synchronous calls where a user waits for the answer.
context.WithTimeout or client timeouts, and propagate the context down every call.golang.org/x/time/rate.log/slog, including a request or trace ID on every line.net/http/pprof on an internal port for profiling.os.LookupEnv, validated at start-up.go test -race in CI to catch data races in concurrent handlers.Package each service as a small static binary in a minimal container image, and set GOMAXPROCS correctly for container CPU limits (recent Go releases do this automatically on Linux).
No. net/http with the Go 1.22 router handles routing, middleware and JSON well, and many production services use nothing else.
Use REST for public and simple APIs. Use gRPC when you want strict schemas, streaming and lower overhead between internal services.
Listen for SIGTERM with signal.NotifyContext and call Server.Shutdown with a timeout so in-flight requests complete.
The package is frozen and does not support modern needs such as streaming. Choose gRPC or HTTP and JSON instead.
Use net/http, context, encoding/json and log/slog for the core of each Go microservice, add timeouts, graceful shutdown and retries, and bring in modules for gRPC, messaging and tracing. Keep services small, observable and idempotent.