HTTP up front, Protobufs in the rear
Small, runnable example of Go microservices with:
frontend, search, profile, geo, rate)/hotels)search fans out to geo + rate)/healthz, /readyz, traces)flowchart LR
B["Browser"] --> F["frontend (HTTP :5001)"]
F --> S["search (gRPC :8084)"]
F --> P["profile (gRPC :8083)"]
S --> G["geo (gRPC :8081)"]
S --> R["rate (gRPC :8082)"]
F --> J["Jaeger/OTLP (:4317, UI :16686)"]
S --> J
P --> J
G --> J
R --> Jgo.mod)protoc + codegen tools (only for regenerating protobuf stubs)go-bindata (only for regenerating embedded JSON assets)Install codegen tooling:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/go-bindata/go-bindata/...@latestmake run-localcurl "http://localhost:5001/hotels?inDate=2015-04-09&outDate=2015-04-10"make runThe frontend is available at http://localhost:5001/.
GET /hotelsRequired query params:
inDate (YYYY-MM-DD)outDate (YYYY-MM-DD, must be after inDate, max range 30 days)Example:
curl "http://localhost:5001/hotels?inDate=2015-04-09&outDate=2015-04-10"Success response shape:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "hotel-id",
"properties": {
"name": "Hotel Name",
"address_line": "123 Main St, San Francisco, CA, 94105",
"description": "Hotel description",
"rating": 4.7,
"logo_url": "/logos/example.svg"
},
"geometry": {
"type": "Point",
"coordinates": [-122.4, 37.78]
}
}
]
}Validation or upstream error shape:
{
"error": {
"code": "INVALID_ARGUMENT",
"message": "invalid inDate format, expected YYYY-MM-DD"
}
}To demonstrate readiness behavior when a dependency is down:
search (local run: interrupt and restart without search, Docker run: docker-compose stop search).curl -i http://localhost:5001/readyzExpected: 503 Service Unavailable with NOT_READY.
Run all Go checks:
make checkRegenerate protobuf stubs:
make protoRegenerate embedded data:
make dataVerify generated files are current:
make check-generatedNo open issues yet, or sync has not completed.