Monolith vs Microservices in Go

When to Split

Web
Split a Go monolith into microservices when you need independent scaling or team autonomy, starting by extracting a bounded context into a new module.

Split your Go monolith into microservices when you need independent scaling, deployment, or team ownership for specific business domains. Start by extracting a bounded context into a new module and running it as a separate service.

go mod init example.com/order-service
go run main.go
  1. Identify a cohesive business domain (e.g., "orders") and move its code to a new directory.
  2. Initialize a new Go module in that directory with go mod init <domain-name>.
  3. Define a public API using net/http or gRPC and implement the handlers.
  4. Run the new service locally with go run main.go to verify it starts independently.
  5. Update the original monolith to call the new service via HTTP or gRPC instead of internal function calls.
  6. Deploy the new service to a separate container or VM using docker build -t <name> . and docker run -p 8080:8080 <name>.
  7. Configure your load balancer or service mesh to route traffic to the new service endpoint.