172
Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika [email protected]

Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika [email protected]

  • Upload
    others

  • View
    24

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Teach your (micro)services speak Protocol Buffers with gRPC.

Mihai Iachimovschi

@mishunika [email protected]

Page 2: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

What’s inside?

Page 3: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

What’s inside?

–Message serialization and deserialization

Page 4: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

What’s inside?

–Message serialization and deserialization

–Message transport

Page 5: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

What’s inside?

–Message serialization and deserialization

–Message transport

–Services diversity

Page 6: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How it works in real life

A

B

C

D

Page 7: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How it works in real life

A

B

C

D

Page 8: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

In a nutshell

Client Service

Page 9: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

In a nutshell

–Over HTTP

–Serialized to JSON

Client Service

Page 10: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

In a nutshell

–Over HTTP

–Serialized to JSON

Client Service

–Proprietary protocol

–Remote objects

Page 11: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON advantages

Page 12: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON advantages

–Human readable

Page 13: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON advantages

–Human readable

–Schema-less

Page 14: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON advantages

–Human readable

–Schema-less

–Language agnostic

Page 15: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON disadvantages

Page 16: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON disadvantages

–Human readable

Page 17: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON disadvantages

–Human readable Isn’t it a benefit?

Page 18: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON disadvantages

–Human readable

–Schema-less

Isn’t it a benefit?

Page 19: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON disadvantages

–Human readable

–Schema-less

Isn’t it a benefit?Isn’t it a benefit as well?

Page 20: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

JSON disadvantages

–Human readable

–Schema-less

–Type-less

Isn’t it a benefit?Isn’t it a benefit as well?

Page 21: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers?

“Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.”

— https://developers.google.com/protocol-buffers/

Page 22: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers?

“Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.”

— https://developers.google.com/protocol-buffers/

Page 23: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers?

“Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.”

— https://developers.google.com/protocol-buffers/

JSON

Page 24: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers example

message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Page 25: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers example

message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Page 26: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers example

message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Page 27: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers example

message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Page 28: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers example

message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Page 29: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers example

message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Page 30: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Protocol Buffers example

message Person {   reserved 1, 2, 5; reserved "name";   int32 id = 3;   repeated string aliases = 4; }

Page 31: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Why protocol buffers

Binary format

Page 32: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Why protocol buffers

Enforcing the schema

Page 33: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Why protocol buffers

Language neutral

Page 34: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Out-of the box backward compatibility

Why protocol buffers

Page 35: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Out-of the box backward compatibility

Why protocol buffers

Page 36: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Out-of the box backward compatibility

 if version == 3:    ...  elif version > 4:    if (version == 5):      ...    ...

Why protocol buffers

Page 37: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Why protocol buffers

Generally faster

Page 38: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How to…message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Page 39: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How to…message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Proto message definition

Page 40: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How to…message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Person john = Person.newBuilder()     .setId(1234)     .setName("John Doe")     .addAliases("ionel")     .build();

Proto message definition

Page 41: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How to…message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

Person john = Person.newBuilder()     .setId(1234)     .setName("John Doe")     .addAliases("ionel")     .build();

Proto message definition

Object creation

Page 42: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How to…message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

john = Person() john.id = 1234 john.name = 'John Doe' john.aliases.add(‘ionel’)

Proto message definition

Object creation

Page 43: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How to…message Person {   string name = 1;   int32 id = 2;   repeated string aliases = 3; }

john = Person(id=1234, name='John Doe', aliases=['ionel'])

Proto message definition

Object creation

Page 44: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Communication (REST-ish)

1. URI: https://api.example.com/person/42

2. Make an HTTP GET Request

3. Receive a plaintext JSON

4. Parse it

5. …

Page 45: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Request

GET /person/42 HTTP/1.1 Accept: */* Accept-Encoding: gzip, deflate Connection: keep-alive Host: api.example.com ...

Page 46: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Response headers

HTTP/1.1 200 OK Access-Control-Allow-Credentials: true Cache-Control: public, max-age=14400 Content-Encoding: gzip Content-Type: application/json; charset=utf-8 ...

Page 47: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Response body{ "name": "John Doe", "id": 42, "aliases": [ "ionel", "honzík" ] }

Page 48: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

HTTP2

https://www.youtube.com/watch?v=DtTKF5OcpsU

Page 49: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Distributed objects

https://en.wikipedia.org/wiki/Distributed_object

Page 50: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Distributed objects

“First Law of Distributed Object Design:don't distribute your objects”.

— Martin Fowlerhttps://martinfowler.com/articles/distributed-objects-microservices.html

Page 51: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

The 8 Fallacies of distributed computing

1. The network is reliable.

2. Latency is zero.

3. Bandwidth is infinite.

4. The network is secure.

5. Topology doesn't change.

6. There is one administrator.

7. Transport cost is zero.

8. The network is homogeneous.

http://www.rgoarchitects.com/Files/fallacies.pdf

Page 52: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Keep in mind…

“Anything that can go wrong will go wrong.”

—Murphy’s Law

Page 53: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

So, what’s next?

Page 54: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Services not Objects, Messages not References

http://www.grpc.io/blog/principles

Page 55: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Coverage & Simplicity

http://www.grpc.io/blog/principles

Page 56: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

How does it work

Page 57: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 58: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 59: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 60: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 61: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 62: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 63: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

message GetRoutesRequest { Location origin = 1; Location destination = 2; }

message GetRoutesResponse { repeated Route routes = 1; }

Page 64: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Generate server code

$ python -m grpc_tools.protoc \ --proto_path=../protos \ --python_out=. \ --grpc_python_out=. \ ../protos/route_planner.proto

Page 65: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Generate server code

$ python -m grpc_tools.protoc \ --proto_path=../protos \ --python_out=. \ --grpc_python_out=. \ ../protos/route_planner.proto

Page 66: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Generate server code

$ python -m grpc_tools.protoc \ --proto_path=../protos \ --python_out=. \ --grpc_python_out=. \ ../protos/route_planner.proto

Page 67: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Generate server code

$ python -m grpc_tools.protoc \ --proto_path=../protos \ --python_out=. \ --grpc_python_out=. \ ../protos/route_planner.proto

Page 68: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Generate server code

$ python -m grpc_tools.protoc \ --proto_path=../protos \ --python_out=. \ --grpc_python_out=. \ ../protos/route_planner.proto

Page 69: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Generate server code

$ python -m grpc_tools.protoc \ --proto_path=../protos \ --python_out=. \ --grpc_python_out=. \ ../protos/route_planner.proto

Page 70: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Generate server code

$ python -m grpc_tools.protoc \ --proto_path=../protos \ --python_out=. \ --grpc_python_out=. \ ../protos/route_planner.proto

Page 71: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Generated code

$ tree . ├── route_planner_pb2.py └── route_planner_pb2_grpc.py

0 directories, 2 files

Page 72: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Implementing the service

Page 73: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Implementing the service

Page 74: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service code

class Servicer(route_planner_pb2_grpc.RoutePlannerServicer): """Service implementation."""

def GetRoutes(self, request, context): return process_magically_the_request(request)

Page 75: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service code

server = grpc.server( futures.ThreadPoolExecutor(max_workers=10))

route_planner_pb2_grpc.add_RoutePlannerServicer_to_server( Servicer(), server)

server.add_insecure_port('[::]:12345') server.start()

Page 76: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service code

server = grpc.server( futures.ThreadPoolExecutor(max_workers=10))

route_planner_pb2_grpc.add_RoutePlannerServicer_to_server( Servicer(), server)

server.add_insecure_port('[::]:12345') server.start()

Page 77: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service code

server = grpc.server( futures.ThreadPoolExecutor(max_workers=10))

route_planner_pb2_grpc.add_RoutePlannerServicer_to_server( Servicer(), server)

server.add_insecure_port('[::]:12345') server.start()

Page 78: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service code

server = grpc.server( futures.ThreadPoolExecutor(max_workers=10))

route_planner_pb2_grpc.add_RoutePlannerServicer_to_server( Servicer(), server)

server.add_insecure_port('[::]:12345') server.start()

Page 79: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service code

server = grpc.server( futures.ThreadPoolExecutor(max_workers=10))

route_planner_pb2_grpc.add_RoutePlannerServicer_to_server( Servicer(), server)

server.add_insecure_port('[::]:12345') server.start()

Page 80: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Implementing the client

Page 81: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Implementing the client

Page 82: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Client code

channel = grpc.insecure_channel(‘localhost:12345')

stub = route_planner_pb2_grpc.RoutePlannerStub(channel)

request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS)

response = stub.GetRoutes(request)

Page 83: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Client code

channel = grpc.insecure_channel(‘localhost:12345')

stub = route_planner_pb2_grpc.RoutePlannerStub(channel)

request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS)

response = stub.GetRoutes(request)

Page 84: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Client code

channel = grpc.insecure_channel(‘localhost:12345')

stub = route_planner_pb2_grpc.RoutePlannerStub(channel)

request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS)

response = stub.GetRoutes(request)

Page 85: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Client code

channel = grpc.insecure_channel(‘localhost:12345')

stub = route_planner_pb2_grpc.RoutePlannerStub(channel)

request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS)

response = stub.GetRoutes(request)

Page 86: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Client code

channel = grpc.insecure_channel(‘localhost:12345')

stub = route_planner_pb2_grpc.RoutePlannerStub(channel)

request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS)

response = stub.GetRoutes(request)

Page 87: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Client code

channel = grpc.insecure_channel(‘localhost:12345')

stub = route_planner_pb2_grpc.RoutePlannerStub(channel)

request = route_planner_pb2.GetRoutesRequest( origin=CURRENT_LOCATION, destination=DESTINATION_COORDS)

response = stub.GetRoutes(request)

Page 88: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Client code (async)

response_future = stub.GetRoutes.future(request)

response_future.result()

Page 89: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

grpc_cli

$ grpc_cli call localhost:12345 \ RoutePlanner.GetRoutes \ <<- PROTO origin: <long: 0.0 lat: 0.0> destination: <long: 1.1 lat: 1.1> PROTO

Page 90: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

grpc_cli

$ grpc_cli call localhost:12345 \ RoutePlanner.GetRoutes \ <<- PROTO origin: <long: 0.0 lat: 0.0> destination: <long: 1.1 lat: 1.1> PROTO

Page 91: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

grpc_cli

$ grpc_cli call localhost:12345 \ RoutePlanner.GetRoutes \ <<- PROTO origin: <long: 0.0 lat: 0.0> destination: <long: 1.1 lat: 1.1> PROTO

Page 92: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

grpc_cli

$ grpc_cli call localhost:12345 \ RoutePlanner.GetRoutes \ <<- PROTO origin: <long: 0.0 lat: 0.0> destination: <long: 1.1 lat: 1.1> PROTO

Page 93: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

grpc_cli

$ grpc_cli call localhost:12345 \ RoutePlanner.GetRoutes \ <<- PROTO origin: <long: 0.0 lat: 0.0> destination: <long: 1.1 lat: 1.1> PROTO

Page 94: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

grpc_cli

Rpc succeeded with OK status Response: routes: <...> routes: <...> routes: <...> routes: <...>

Page 95: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 96: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition - response streaming

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (stream GetRoutesResponse) {} }

Page 97: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition

service RoutePlanner { rpc GetRoutes (GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 98: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition - request streaming

service RoutePlanner { rpc GetRoutes (stream GetRoutesRequest) returns (GetRoutesResponse) {} }

Page 99: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Request streaming? Response streaming?

Page 100: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Request streaming? Response streaming?

Page 101: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Service definition - bidirectional streaming

service RoutePlanner { rpc GetRoutes (stream GetRoutesRequest) returns (stream GetRoutesResponse) {} }

Page 102: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Keep in mind…

Things will go wrong

Page 103: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Timeouts

Client Service B

A

C

D

E

? ms ? ms

? ms

? ms

? ms

? ms

Page 104: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Uniform timeout

Client Service A B

Page 105: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Uniform timeout

Client Service A B

500 ms timeout 500 ms timeout 500 ms timeout

Page 106: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Uniform timeout

Client Service A

20 ms

B

500 ms timeout 500 ms timeout 500 ms timeout

Page 107: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Uniform timeout

Client Service A

20 ms 30 ms

B

500 ms timeout 500 ms timeout 500 ms timeout

Page 108: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Uniform timeout

Client Service A

20 ms 30 ms

B

40 ms

500 ms timeout 500 ms timeout 500 ms timeout

Page 109: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Uniform timeout

Client Service A

20 ms 30 ms

B

40 ms

420 ms

500 ms timeout 500 ms timeout 500 ms timeout

Page 110: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Uniform timeout

Client Service A

20 ms 30 ms

B

40 ms

420 ms

500 ms timeout 500 ms timeout 500 ms timeout

X

Page 111: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Uniform timeout

Client Service A

20 ms 30 ms

B

40 ms

20 ms 420 ms

500 ms timeout 500 ms timeout 500 ms timeout

X X

Page 112: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Fine-tuned timeout

Client Service A B

Page 113: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Fine-tuned timeout

Client Service A B

300 ms timeout 280 ms timeout 50 ms timeout

Page 114: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Fine-tuned timeout

Client Service A

20 ms

B

300 ms timeout 280 ms timeout 50 ms timeout

Page 115: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Fine-tuned timeout

Client Service A

20 ms 30 ms

B

300 ms timeout 280 ms timeout 50 ms timeout

Page 116: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Fine-tuned timeout

Client Service A

20 ms 30 ms

B

15 ms

300 ms timeout 280 ms timeout 50 ms timeout

Page 117: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Fine-tuned timeout

Client Service A

20 ms 30 ms

B

15 ms

40 ms

300 ms timeout 280 ms timeout 50 ms timeout

Page 118: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Fine-tuned timeout

Client Service A

20 ms 30 ms

B

15 ms

40 ms

300 ms timeout 280 ms timeout 50 ms timeout

X

Page 119: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A B

Page 120: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A B

200 ms timeout

Page 121: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A

20 ms

B

200 ms timeout

Page 122: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A

20 ms

B

200 ms timeout 200ms - 20ms = 180 ms

Page 123: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A

20 ms 30 ms

B

200 ms timeout 200ms - 20ms = 180 ms

Page 124: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A

20 ms 30 ms

B

200 ms timeout 200ms - 20ms = 180 ms

180ms - 30ms = 150ms

Page 125: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A

20 ms 30 ms

B

15 ms

200 ms timeout 200ms - 20ms = 180 ms

180ms - 30ms = 150ms

Page 126: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A

20 ms 30 ms

B

15 ms

40 ms

200 ms timeout 200ms - 20ms = 180 ms

180ms - 30ms = 150ms

Page 127: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A

20 ms 30 ms

B

15 ms

20 ms 40 ms

200 ms timeout 200ms - 20ms = 180 ms

180ms - 30ms = 150ms

Page 128: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Adaptive timeout

Client Service A

20 ms 30 ms

B

15 ms

40 ms 20 ms 40 ms

200 ms timeout 200ms - 20ms = 180 ms

180ms - 30ms = 150ms

Page 129: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

gRPC: Deadlines

Page 130: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

gRPC: Deadlines

–Timeout is relative

Page 131: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

gRPC: Deadlines

–Timeout is relative

–Deadline is absolute

Page 132: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

Page 133: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600000

Page 134: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600000

Page 135: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020TS: 3600000

Page 136: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020TS: 3600000

Page 137: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050TS: 3600000

Page 138: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

15 ms

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050TS: 3600000

Page 139: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

15 ms

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050 TS: 3600045TS: 3600000

Page 140: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

15 ms

40 ms

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050 TS: 3600045TS: 3600000

Page 141: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

15 ms

40 ms

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050 TS: 3600045

TS: 3600085

TS: 3600000

Page 142: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

15 ms

20 ms 40 ms

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050 TS: 3600045

TS: 3600085

TS: 3600000

Page 143: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

15 ms

20 ms 40 ms

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050 TS: 3600045

TS: 3600105 TS: 3600085

TS: 3600000

Page 144: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

15 ms

40 ms 20 ms 40 ms

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050 TS: 3600045

TS: 3600105 TS: 3600085

TS: 3600000

Page 145: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

20 ms 30 ms

B

15 ms

40 ms 20 ms 40 ms

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600020 TS: 3600050 TS: 3600045

TS: 3600105 TS: 3600085TS: 3600145

TS: 3600000

Page 146: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

Page 147: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600000

Page 148: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

150ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600000

Page 149: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

150ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600150TS: 3600000

Page 150: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

150ms 100 ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600150TS: 3600000

Page 151: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

150ms 100 ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600150 TS: 3600250TS: 3600000

Page 152: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

150ms 100 ms

B

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600150 TS: 3600250TS: 3600000

X

Page 153: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

150ms 100 ms

B

DEADLINE_EXCEEDED

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600150 TS: 3600250TS: 3600000

X

Page 154: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Deadline propagation

Client Service A

150ms 100 ms

B

DEADLINE_EXCEEDED DEADLINE_EXCEEDED

Start TS: 3600000 Timeout: 200 Deadline: 3600200

TS: 3600150 TS: 3600250TS: 3600000

X

Page 155: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Cancellation

Page 156: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Cancellation

–Can be initiated by both client/server

Page 157: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Cancellation

–Can be initiated by both client/server

– Immediately terminates the RPC

Page 158: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Cancellation

–Can be initiated by both client/server

– Immediately terminates the RPC

– It is not a roll-back

Page 159: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Cancellation

–Can be initiated by both client/server

– Immediately terminates the RPC

– It is not a roll-back

–Automatically cascaded

Page 160: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Backward compatibility

https://github.com/grpc-ecosystem/grpc-gateway

Page 161: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

gRPC language support

–C++

–Python

–Java

–Go

–Ruby

–C#

–JS (Node)

–Android Java

–Objective-C

–PHP

Page 162: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

gRPC Platform support

–Linux

–macOS

–Windows

–Android

– iOS

Page 163: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Success stories

Page 164: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Success stories

Page 165: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Benefits

Page 166: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Benefits–Focus on the API design & contract

Page 167: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Benefits–Focus on the API design & contract

–HTTP2 is awesome

Page 168: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Benefits–Focus on the API design & contract

–HTTP2 is awesome

–Bi-directional streaming

Page 169: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Benefits–Focus on the API design & contract

–HTTP2 is awesome

–Bi-directional streaming

–Freedom to pick any language

Page 170: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Benefits–Focus on the API design & contract

–HTTP2 is awesome

–Bi-directional streaming

–Freedom to pick any language

–Service-to-Service and Service-to-Mobile friendly

Page 171: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Benefits–Focus on the API design & contract

–HTTP2 is awesome

–Bi-directional streaming

–Freedom to pick any language

–Service-to-Service and Service-to-Mobile friendly

–Production ready

Page 172: Teach your (micro)services speak Protocol Buffers with gRPC.€¦ · Teach your (micro)services speak Protocol Buffers with gRPC. Mihai Iachimovschi @mishunika mihai.iachimovschi@gmail.com

Fin.

Thank you.