A demonstration of Golang micro-services that expose a HTTP/JSON frontend and then leverages gRPC for inter-service communication.
- Services written in Golang
- gRPC for inter-service communication
- OpenTelemetry for request tracing
The example application plots Hotel locations on a Google map:
The web page makes an HTTP request to the API Endpoint which in turn spawns a number of RPC requests to the backend services.
Data for each of the services is stored in JSON flat files under the data/
directory. In reality each of the services could choose their own specialty datastore. The Geo service for example could use PostGis or any other database specializing in geospacial queries.
To make the demo as straigforward as possible; Docker Compose is used to run all the services at once (In a production environment each of the services would be run (and scaled) independently).
$ make run
Vist the web page in a browser:
cURL the API endpoint and receive GeoJSON response:
$ curl "http://localhost:8080/hotels?inDate=2015-04-09&outDate=2015-04-10"
The JSON response:
{
"type": "FeatureCollection",
"features": [{
"id": "5",
"type": "Feature",
"properties": {
"name": "Phoenix Hotel",
"phone_number": "(415) 776-1380"
},
"geometry": {
"type": "Point",
"coordinates": [-122.4181, 37.7831]
}
}, {
"id": "3",
"type": "Feature",
"properties": {
"name": "Hotel Zetta",
"phone_number": "(415) 543-8555"
},
"geometry": {
"type": "Point",
"coordinates": [-122.4071, 37.7834]
}
}]
}
The OpenTelemetry project is used for tracing inter-service requests. Jaeger is used as the OTLP compatible collector.
View dashboard: http://localhost:16686/search
If changes are made to the Protocol Buffer files use the Makefile to regenerate:
$ make proto
The example app data is stored in flat files in the /data
directory. When any of
the data files are manually editied the bindata must be regenerated.
Install the go-bindata libraries:
$ go get -u github.com/go-bindata/go-bindata/...
If changes are made to any of the raw JSON data files use the Makefile to regenerate:
$ make data
Thanks to all the contributors. This codebase was heavily inspired by the following talks and repositories: