Slide 1

Slide 1 text

gRPC Widya Rarasati Software Engineer Widya Rarasati - Software Engineer

Slide 2

Slide 2 text

What is gRPC? gRPC stands for gRPC Remote Procedure Calls. Open sourced version of Stubby RPC used in Google. https://github.com/grpc/grpc/blob/master/doc/g_stands_for.md

Slide 3

Slide 3 text

Why gRPC? ● strict service contracts using Protobuf ● data serialization ● efficient network communication ● Support many common languages: C++, Java, Python, Ruby, Node.js, C#, Go, PHP, Objective-C TL;DR gRPC replace HTTP+JSON.

Slide 4

Slide 4 text

https://www.slideshare.net/borisovalex/enabling-googley-microservices-with-http2-and-grpc

Slide 5

Slide 5 text

What makes gRPC faster ● More efficient data encoding data is kept in binary (in client memory and on the wire) ● HTTP/2 multiplexed requests over a single connection

Slide 6

Slide 6 text

https://www.slideshare.net/borisovalex/enabling-googley-microservices-with-http2-and-grpc

Slide 7

Slide 7 text

https://www.slideshare.net/borisovalex/enabling-googley-microservices-with-http2-and-grpc

Slide 8

Slide 8 text

https://www.slideshare.net/borisovalex/enabling-googley-microservices-with-http2-and-grpc

Slide 9

Slide 9 text

How To Use gRPC

Slide 10

Slide 10 text

Protobuf as Service Definition

Slide 11

Slide 11 text

Deadline instead of Timeout1 How long the client is willing to wait for an answer. When deadline reached RPC will fail with DEADLINE_EXCEEDED status code response = blockingStub.withDeadlineAfter( deadlineMs, TimeUnit.MILLISECONDS) .sayHello(request);

Slide 12

Slide 12 text

gRPC Deadline1 Deadline are automatically propagated, and can be accessed by the receiver Context context = Context.current(); context.getDeadline().isExpired(); context.getDealine().timeRemaining( MILLISECONDS); context.getDeadline().runOnExpiration(() -> { cleaupResources(); logger.info(“Deadline exceded” ); })

Slide 13

Slide 13 text

gRPC Cancellation When the caller is not interested in the result any more… RPC will fail with CANCELLED status code. Server (receiver) access cancellation status by: streamObserver.isCancelled(); streamObserver.setOnCancelHandler(() -> { cleaupResources(); logger.info(“Call canceled by client.” ); })

Slide 14

Slide 14 text

Reference 1)https://cloudplatform.googleblog.com/2016/08/gRPC-a-true-Internet-scale-RPC-framework-is- now-1-and-ready-for-production-deployments.html 2)https://cloud.google.com/blog/big-data/2016/03/announcing-grpc-alpha-for-google-cloud-pub sub 3)https://www.slideshare.net/borisovalex/enabling-googley-microservices-with-http2-and-grpc 4)https://developers.google.com/protocol-buffers/docs/reference/overview 5)https://grpc.io/blog/deadlines

Slide 15

Slide 15 text

Existing GGB gRPC Implementation PROS CONS Service Contract Manageable contract version No status code for each rpc in protobuf Connection Efficiency Using single TCP connection Infrequently request traffic Logging Can do it in gRPC interceptor Missing readability of HTTP request traffic

Slide 16

Slide 16 text

Other things about gRPC: - Channel https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-ap i.md - Reflection Server https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflectio n-tutorial.md - Client cancel StreamObserver response = blockingStub.sayHello(request); ((ClientCallStreamObserver) response.).cancel()

Slide 17

Slide 17 text

Thank You