Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OZON. Making microservices from scratch

OZON. Making microservices from scratch

How we build microservices in OZON.

Ivan Korolev

April 13, 2019
Tweet

More Decks by Ivan Korolev

Other Decks in Programming

Transcript

  1. gRPC vs http • protobuf - fixed and extendable API

    contract • binary protocol - lower bandwidth • bidirectional data streams on a single socket • client/server code generation
  2. gRPC + http? Shiny new gRPC API or legacy HTTP

    REST? • Implement both "transports" separately 
 + native transport support
 – code duplication
  3. gRPC + http? Shiny new gRPC API or legacy HTTP

    REST? • Implement both "transports" separately 
 + native transport support
 – code duplication • Implement gRPC + deploy grpc-gateway 
 + don't need http implementation
 – intermediate service deployment
  4. gRPC + http? Shiny new gRPC API or legacy HTTP

    REST? • Implement both "transports" separately 
 + native transport support
 – code duplication • Implement gRPC + deploy grpc-gateway 
 + don't need http implementation
 – intermediate service deployment • HTTP server code generation
  5. clay github.com/utrack/clay • protoc plugin
 .proto as single service description

    source
 mapping flexibility: Google API HTTP Annotations • Swagger (OpenAPI) support (grpc-gateway) • single handler implementation on top of gRPC • slim transport library: - errors handling - custom marshallers for any content type - HTTP headers - gRPC metadata translation • go-modules friendly :)
  6. $ curl 
 http://localhost:8080/strings/to_upper/foo {"str":"FOO"} 
 
 $ curl -XPOST

    -d '{"str": "bar"}' 
 http://localhost:8080/strings/to_upper {"str":"BAR"}
  7. $ curl -XPOST -d '["foo", "bar"]' http://localhost:8080/strings/to_upper ["FOO","BAR"] 
 


    $ curl http://localhost:8080/strings/ to_upper/v2?str=foo&str=bar ["FOO","BAR"]
  8. clay + protoc-compatible HTTP client/server generator + bindings flexibility (Google

    API HTTP Annotations) + no business-logic code duplication – protoc configuration
  9. scratch Goal: make new service ASAP • Framework - metrics

    - tracing - middlewares - ... • Project skeleton (project structure, deployments) • Library and project updates
  10. scratch Framework: • public http & grpc servers • "debug"

    server: • swagger, • live/ready, • pprof, • metrics • default middlewares (panic, metrics, tracing, etc...) • realtime-config support
  11. scratch scratch tool • init - creates new service from

    .proto (or without) • upgrade - drop-in binary upgrade • update - various project updates between version • vendor.pb - downloads .proto dependencies respecting go.mod • generate - various generators, like realtime-config helpers • install - some install helpers • check - checks system requirements (go, protoc versions, etc...) • version - prints version
  12. Deployment configs service.proto Binary dependencies Main Implementation Client libs Vendored

    .proto files CI config golangCI-lint Modules stuff Custom make targets Generated makefile
  13. scratch vendor.pb • Respect go.mod • Respect well-known types •

    Full-Qualified Names for imports • All proto dependencies in one place protoc -I$(CURDIR)/api/:$(CURDIR)/vendor.pb
 ...
  14. scratch update • update project structure • remove vgo :)

    • clean go cache • .gitlab-ci stuff • ...
  15. What do we get? Support from platform team Common project

    structure Easy updates Fun coding No problems with scratch. Using it from the very first version. Godlike tool, transforming service development to awesome Golang odyssey. I always upgrade to the latest scratch when creating a new service or updating an old one. Renars Freimanis, C# developer @ OZON team
  16. Thank you! Slides: ozon.ru/t/2M Google API HTTP Annotations github.com/utrack/clay github.com/grpc-ecosystem/grpc-gateway


    
 Ashley McNamara: Gophers artwork habr.com/ru/company/ozontech github.com/ozonru Ivan Korolev Senior Go Developer @ Platform team [email protected]
 github.com/mwf