Slide 1

Slide 1 text

Parental advisory Borken English

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Cooking gRPC

Slide 6

Slide 6 text

Who knows what is gRPC?

Slide 7

Slide 7 text

What «g» in «gRPC» stands for?

Slide 8

Slide 8 text

1.google What «g» in «gRPC» stands for?

Slide 9

Slide 9 text

1.google 2.good What «g» in «gRPC» stands for?

Slide 10

Slide 10 text

1.google 2.good 3.generous What «g» in «gRPC» stands for?

Slide 11

Slide 11 text

1.google 2.good 3.generous 4.gRPC What «g» in «gRPC» stands for?

Slide 12

Slide 12 text

1.google 2.good 3.generous 4.gRPC What «g» in «gRPC» stands for?

Slide 13

Slide 13 text

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'

Slide 14

Slide 14 text

So, what is gRPC?

Slide 15

Slide 15 text

So, what is gRPC? • gRPC is the specification

Slide 16

Slide 16 text

So, what is gRPC? • gRPC is the specification • gRPC is the framework

Slide 17

Slide 17 text

So, what is gRPC? • gRPC is the specification • gRPC is the framework • gRPC is the community

Slide 18

Slide 18 text

Specification gRPC over HTTP/2

Slide 19

Slide 19 text

Why HTTP/2?

Slide 20

Slide 20 text

Why HTTP/2? • Works with existing HTTP/2 infrastructure (encryption, compression, load balancing, authentication, etc.)

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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.

Slide 23

Slide 23 text

Why not HTTP 1.1?

Slide 24

Slide 24 text

Why not HTTP 1.1? • No concurrent streams over a single connection

Slide 25

Slide 25 text

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)

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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)

Slide 28

Slide 28 text

Response example HEADERS (flags = END_HEADERS) :status = 200 grpc-encoding = gzip content-type = application/grpc+proto DATA HEADERS (flags = END_STREAM, END_HEADERS) grpc-status = 0 # OK trace-proto-bin = jher831yy13JHy3hc

Slide 29

Slide 29 text

Framework

Slide 30

Slide 30 text

What’s inside?

Slide 31

Slide 31 text

What’s inside? • protobuf as a default message serialization format

Slide 32

Slide 32 text

What’s inside? • protobuf as a default message serialization format • Server and client code generation

Slide 33

Slide 33 text

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.

Slide 34

Slide 34 text

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.

Slide 35

Slide 35 text

Why protobuf?

Slide 36

Slide 36 text

Why protobuf? • RPC, not only messages

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

Metadata

Slide 45

Slide 45 text

Metadata • Key-value pairs for each request and response

Slide 46

Slide 46 text

Metadata • Key-value pairs for each request and response • Once per RPC call, not per message

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

Error handling

Slide 51

Slide 51 text

Error handling • 17 standard response codes

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

Embedded error message Status { int32 code = 1; string message = 2; repeated google.protobuf.Any details = 3; } message MyResponse { Status status = 1; … }

Slide 57

Slide 57 text

More framework features

Slide 58

Slide 58 text

More framework features • Retries and back-off strategies

Slide 59

Slide 59 text

More framework features • Retries and back-off strategies • Server reflection

Slide 60

Slide 60 text

More framework features • Retries and back-off strategies • Server reflection • Service configuration

Slide 61

Slide 61 text

Community

Slide 62

Slide 62 text

Use cases

Slide 63

Slide 63 text

Use cases • Backend to backend (microservices)

Slide 64

Slide 64 text

Use cases • Backend to backend (microservices) • Mobile apps

Slide 65

Slide 65 text

Use cases • Backend to backend (microservices) • Mobile apps • Browsers (both moderns and old)

Slide 66

Slide 66 text

Use cases • Backend to backend (microservices) • Mobile apps • Browsers (both moderns and old) • Ad-hoc scripts (curl and duct tape)

Slide 67

Slide 67 text

Middlewares

Slide 68

Slide 68 text

Middlewares • Cascading interceptors

Slide 69

Slide 69 text

Middlewares • Cascading interceptors • Authentication, validators, panic recovery, logging, metrics, tracing, etc.

Slide 70

Slide 70 text

Alternative transports

Slide 71

Slide 71 text

Alternative transports • gRPC Web (over HTTP/2 for browsers)

Slide 72

Slide 72 text

Alternative transports • gRPC Web (over HTTP/2 for browsers) • gRPC Websocket Proxy (over HTTP/1.1)

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

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*

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

Learn more

Slide 77

Slide 77 text

Learn more • https://grpc.io

Slide 78

Slide 78 text

Learn more • https://grpc.io • https://github.com/grpc/grpc/tree/master/doc

Slide 79

Slide 79 text

Learn more • https://grpc.io • https://github.com/grpc/grpc/tree/master/doc • https://github.com/grpc/grpc-go/tree/master/ Documentation

Slide 80

Slide 80 text

Learn more • https://grpc.io • https://github.com/grpc/grpc/tree/master/doc • https://github.com/grpc/grpc-go/tree/master/ Documentation • https://github.com/grpc-ecosystem

Slide 81

Slide 81 text

Even more!

Slide 82

Slide 82 text

Even more! • http://gophercon-russia.ru

Slide 83

Slide 83 text

Even more! • http://gophercon-russia.ru • https://www.percona.com/about-percona/careers

Slide 84

Slide 84 text

Questions? https://speakerdeck.com/aleksi