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

Cooking gRPC

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Cooking gRPC

Avatar for Alexey Palazhchenko

Alexey Palazhchenko

January 11, 2018
Tweet

More Decks by Alexey Palazhchenko

Other Decks in Technology

Transcript

  1. https://github.com/grpc/grpc/blob/master/doc/g_stands_for.md Each version of gRPC gets a new description of

    what the 'g' stands for, since we've never really been able to figure it out. Below is a list of already-used definitions (that should not be repeated in the future), and the corresponding version numbers that used them: • 1.0 'g' stands for ‘gRPC’ • 1.1 'g' stands for ‘good' • 1.2 'g' stands for ‘green' • 1.3 'g' stands for ‘gentle' • 1.4 'g' stands for ‘gregarious' • 1.6 'g' stands for ‘garcia' • 1.7 'g' stands for ‘gambit' • 1.8 'g' stands for ‘generous' • 1.9 'g' stands for 'glossy'
  2. So, what is gRPC? • gRPC is the specification •

    gRPC is the framework • gRPC is the community
  3. Why HTTP/2? • Works with existing HTTP/2 infrastructure (encryption, compression,

    load balancing, authentication, etc.) • Many concurrent bidirectional logical binary streams (channels) inside a single TCP/IP connection
  4. Why HTTP/2? • Works with existing HTTP/2 infrastructure (encryption, compression,

    load balancing, authentication, etc.) • Many concurrent bidirectional logical binary streams (channels) inside a single TCP/IP connection • Advanced framing features: prioritization, flow control, server push, etc.
  5. Why not HTTP 1.1? • No concurrent streams over a

    single connection • No bidirectional streaming (without hacks like Bayeux or BOSH, or HTTP Upgrade mechanism)
  6. Why not HTTP 1.1? • No concurrent streams over a

    single connection • No bidirectional streaming (without hacks like Bayeux or BOSH, or HTTP Upgrade mechanism) • Headers can’t be compressed
  7. Request example HEADERS (flags = END_HEADERS) :method = POST :scheme

    = http :path = /PublisherService/CreateTopic :authority = pubsub.googleapis.com grpc-timeout = 1S content-type = application/grpc+proto grpc-encoding = gzip authorization = Bearer y235.wef DATA (flags = END_STREAM) <Length-Prefixed Message>
  8. Response example HEADERS (flags = END_HEADERS) :status = 200 grpc-encoding

    = gzip content-type = application/grpc+proto DATA <Length-Prefixed Message> HEADERS (flags = END_STREAM, END_HEADERS) grpc-status = 0 # OK trace-proto-bin = jher831yy13JHy3hc
  9. What’s inside? • protobuf as a default message serialization format

    • Server and client code generation • Delicacy: context propagation with timeouts and metadata, HTTP/2 PINGs, GOAWAY, etc.
  10. What’s inside? • protobuf as a default message serialization format

    • Server and client code generation • Delicacy: context propagation with timeouts and metadata, HTTP/2 PINGs, GOAWAY, etc. • A lot of (auto-) tuning possibilities: HTTP/2 WINDOW_UPDATE, etc.
  11. Why protobuf? • RPC, not only messages • Strongly typed,

    useful zero values, backward- and forward-compatibility, canonical mapping to JSON
  12. Why protobuf? • RPC, not only messages • Strongly typed,

    useful zero values, backward- and forward-compatibility, canonical mapping to JSON • Code generation
  13. Why protobuf? • RPC, not only messages • Strongly typed,

    useful zero values, backward- and forward-compatibility, canonical mapping to JSON • Code generation • Effective*
  14. Why protobuf? • RPC, not only messages • Strongly typed,

    useful zero values, backward- and forward-compatibility, canonical mapping to JSON • Code generation • Effective* • … but specification is agnostic to message serialization format
  15. Why protobuf? • RPC, not only messages • Strongly typed,

    useful zero values, backward- and forward-compatibility, canonical mapping to JSON • Code generation • Effective* • … but specification is agnostic to message serialization format • … but please use protobuf v3 by default
  16. How it looks message HelloRequest { string greeting = 1;

    } message HelloResponse { string reply = 1; } service HelloService { rpc SayHello (HelloRequest) returns (HelloResponse); }
  17. How it looks for streaming message HelloRequest { string greeting

    = 1; } message HelloResponse { string reply = 1; } service HelloService { rpc SayHello (stream HelloRequest) returns (stream HelloResponse); }
  18. Metadata • Key-value pairs for each request and response •

    Once per RPC call, not per message • Can be sent even before request message is received
  19. Metadata • Key-value pairs for each request and response •

    Once per RPC call, not per message • Can be sent even before request message is received • Standard (timeouts, authentication, etc.) and custom
  20. Metadata • Key-value pairs for each request and response •

    Once per RPC call, not per message • Can be sent even before request message is received • Standard (timeouts, authentication, etc.) and custom • Available via context.Context
  21. Error handling • 17 standard response codes • Some can

    be generated by the framework, some are not
  22. Error handling • 17 standard response codes • Some can

    be generated by the framework, some are not • Custom codes can* be used
  23. Error handling • 17 standard response codes • Some can

    be generated by the framework, some are not • Custom codes can* be used • Always available, even if underlying transport is broken
  24. Error handling • 17 standard response codes • Some can

    be generated by the framework, some are not • Custom codes can* be used • Always available, even if underlying transport is broken • google/rpc/status.proto can be used (embedded or not) for extended statuses
  25. Embedded error message Status { int32 code = 1; string

    message = 2; repeated google.protobuf.Any details = 3; } message MyResponse { Status status = 1; … }
  26. Use cases • Backend to backend (microservices) • Mobile apps

    • Browsers (both moderns and old) • Ad-hoc scripts (curl and duct tape)
  27. Alternative transports • gRPC Web (over HTTP/2 for browsers) •

    gRPC Websocket Proxy (over HTTP/1.1) • gRPC REST Gateway (both yummy and bitter)
  28. Alternative transports • gRPC Web (over HTTP/2 for browsers) •

    gRPC Websocket Proxy (over HTTP/1.1) • gRPC REST Gateway (both yummy and bitter) • gRPC JSON-RPC Gateway*
  29. Alternative transports • gRPC Web (over HTTP/2 for browsers) •

    gRPC Websocket Proxy (over HTTP/1.1) • gRPC REST Gateway (both yummy and bitter) • gRPC JSON-RPC Gateway* *does not exist