Case Studies Basics
11 examples to get you started with Case Studies - 8 basic and 3 intermediate.
Search across all documentation pages
11 examples to get you started with Case Studies - 8 basic and 3 intermediate.
site/go/case-studies/ pages alongside your own module.go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest for comparing lint posture to reference builds.Before reading code, list SLOs, deploy target, and external dependencies for the story.
# REST reference build contract (example)
- Target: Kubernetes Deployment behind Ingress
- SLO: p99 < 100ms for read endpoints at 500 RPS
- Dependencies: Postgres, OTel collector, Prometheus scrapecmd/, internal/, migrations, Helm or manifest snippets.Related: Learning from Production Go Systems - Why case studies matter
Draw inbound protocol to outbound dependencies before opening implementation files.
Client -> Ingress -> chi middleware -> handler -> service -> store -> Postgres
|-> slog + trace span
|-> /healthz /readyzRelated: Reference Build: Cloud-Native REST Microservice - Full HTTP slice
List which packages may import which others in the reference layout.
// Allowed direction in typical reference builds:
// cmd/api -> internal/http -> internal/service -> internal/store
// internal/service must not import cmd/apiinternal/ means "not a public module API." Reference builds keep integration at the edges.Related: Before/After: Refactoring a God Package - Boundary repair story
Copy signal requirements, not dashboard JSON.
// Minimal RED-style metric names to hunt for in a reference build
var (
httpRequests = prometheus.NewCounterVec(/* ... */)
httpDuration = prometheus.NewHistogramVec(/* ... */)
)slog with request IDs in HTTP builds.Related: Production Go: Logs, Metrics, Traces & Signals - Signal vocabulary
Find table-driven tests and integration build tags first.
func TestServiceCreateUser(t *testing.T) {
tests := []struct {
name string
input CreateUserInput
wantErr bool
}{
{name: "valid email", input: CreateUserInput{Email: "a@b.co"}},
{name: "empty email", input: CreateUserInput{}, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// ...
})
}
}httptest records handler contracts without spinning a real port.Related: Table-Driven Tests and Subtests - Test style used across builds
Study how cobra commands, config, and artifacts align.
# Signals of production CLI hygiene in reference builds
goreleaser release --clean
cosign sign-blob --key kms://... dist/myctl_linux_amd64.tar.gz
myctl version --output jsonversion, serve, and migrate concerns.Related: Reference Build: Production CLI with cobra - End-to-end CLI slice
Locate flow control and streaming patterns in data-plane stories.
func (s *server) StreamEvents(req *pb.SubscribeRequest, stream pb.Events_StreamEventsServer) error {
for evt := range s.bus.Subscribe(req.GetTopic()) {
if err := stream.Send(evt); err != nil {
return err // client disconnect or flow control
}
}
return nil
}Related: Reference Build: High-Throughput gRPC Data Plane - Streaming slice
Collect Dockerfile, probe paths, and graceful shutdown handlers.
readinessProbe:
httpGet:
path: /readyz
port: 8080
periodSeconds: 5/healthz and /readyz separately.CGO_ENABLED=0 for static binaries.SIGTERM and drains in-flight requests.Related: Health, Readiness & Liveness Probes - Probe semantics
Replay benchmark case study steps against your staging metrics.
go test -bench=. -benchmem ./internal/api/...
curl -s localhost:6060/debug/pprof/profile?seconds=30 > cpu.prof
go tool pprof -top cpu.profRelated: Benchmark Case Study: JSON API Latency - 200ms to 20ms p99 story
For Kubernetes operator reference material, trace spec → status loops.
func (r *WidgetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
var widget examplev1.Widget
if err := r.Get(ctx, req.NamespacedName, &widget); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
// compare generation, patch status, requeue on transient error
return ctrl.Result{}, nil
}Related: Reference Build: Kubernetes Operator End-to-End - CRD to bundle
Read TinyGo module exports alongside wazero host embedding.
// Host loads guest; guest exports _start or WASI main
mod, err := runtime.InstantiateModule(ctx, compiled, wazero.NewModuleConfig().
WithStdout(os.Stdout))Related: Reference Build: WASI Edge Module with wazero Host - Edge module slice
Stack versions: This page was written for Go 1.26.x (Green Tea GC default, go fix modernizers - verify patch at build), chi (latest - verify at build), gin (latest - verify at build), echo (latest - verify at build), google.golang.org/grpc (latest - verify at build), sigs.k8s.io/controller-runtime (latest - verify at build), kubebuilder (latest - verify at build), tinygo (latest - verify board targets at build), wazero (latest - verify at build), and golangci-lint (latest - verify linter set at build).
Reviewed by Chris St. John·Last updated Jul 18, 2026