Slide 1

Slide 1 text

@saturnism @googlecloud @grpcio gRPC Microservices 201 for Java Developers Ray Tsang (@saturnism), Google Cloud Platform

Slide 2

Slide 2 text

@saturnism @googlecloud @grpcio Ray Tsang Developer Advocate Google Cloud Platform @saturnism | +RayTsang

Slide 3

Slide 3 text

@saturnism @googlecloud @grpcio BigQuery Big Data Pub/Sub Dataflow Dataproc Datalab Compute Compute Engine App Engine Container Engine Storage Cloud Storage Cloud SQL Cloud Datastore Bigtable Machine Learning Speech API Machine Learning Translate API Vision API cloud.google.com

Slide 4

Slide 4 text

@saturnism @googlecloud @grpcio A B C D gRPC

Slide 5

Slide 5 text

@saturnism @googlecloud @grpcio Microservices Concerns Concern What you can use, e.g. Load Balancing https://github.com/grpc/grpc/blob/master/doc/load-balancing.md Server-side: Lyft Envoy, NGinx, or Client-side: With Central Registry Service Registry (Client Side LB) Consul, Zookeper, Eureka, gRPC LB Health Checking https://github.com/grpc/grpc/blob/master/doc/health-checking.md gRPC Health Check Protocol Or, Expose endpoints Security TLS, Token headers Authorization Token headers Distributed Tracing Zipkin Monitoring Prometheus

Slide 6

Slide 6 text

@saturnism @googlecloud @grpcio Microservices Concerns Concern What you can use, e.g. Load Balancing https://github.com/grpc/grpc/blob/master/doc/load-balancing.md Server-side: Lyft Envoy, NGinx, or Client-side: With Central Registry Service Registry (Client Side LB) Consul, Zookeeper, Eureka, gRPC LB Health Checking https://github.com/grpc/grpc/blob/master/doc/health-checking.md gRPC Health Check Protocol Or, Expose endpoints Security TLS, Token headers Authorization Tokens, JWT, OAuth Distributed Tracing Zipkin Monitoring Prometheus

Slide 7

Slide 7 text

@saturnism @googlecloud @grpcio It was pretty easy w/ HTTP/1 Used HTTP Headers What do we do in gRPC?!

Slide 8

Slide 8 text

@saturnism @googlecloud @grpcio Header Greeting Service Client greeting(HelloRequest) POST /…./GreetingService Client-ID: GreetingClientV1 … [HelloRequest payload] Client-ID: GreetingClientV1

Slide 9

Slide 9 text

@saturnism @googlecloud @grpcio Metadata! Greeting Service Client greeting(HelloRequest) Type-safe construct for attaching Header/Trailer to the requests Metadata metadata = new Metadata(); metadat.put(key, value); stub = MetadataUtils.attach(stub, metadata); stub.greeting(request); Client-ID: GreetingClientV1 Metadata: { Client-ID: GreetingClientV1 }

Slide 10

Slide 10 text

@saturnism @googlecloud @grpcio Getting the Metadata Greeting Service Client greeting(HelloRequest) On the server side, intercept the call to get the metadata. Client-ID: GreetingClientV1 Metadata: { Client-ID: GreetingClientV1 } Metadata: { Client-ID: GreetingClientV1 }

Slide 11

Slide 11 text

@saturnism @googlecloud @grpcio How to access? Context! Greeting Service Client greeting(HelloRequest) Client-ID: GreetingClientV1 Metadata: { Client-ID: GreetingClientV1 } Metadata: { Client-ID: GreetingClientV1 } Context Client-ID: GreetingClientV1

Slide 12

Slide 12 text

@saturnism @googlecloud @grpcio So what is Context again? Carries scoped values across API call / threads in the same process But NOT across the wire!

Slide 13

Slide 13 text

@saturnism @googlecloud @grpcio Propagate - MD → Ctx → MD Greeting Service Client Context Client-ID: GreetingClientV1 Client 2 Metadata: { Client-ID: GreetingClientV1 } Translation Service Client-ID: GreetingClientV1

Slide 14

Slide 14 text

@saturnism @googlecloud @grpcio Use Client Interceptor Greeting Service Client Context Client-ID: GreetingClientV1 Client 2 Metadata: { Client-ID: GreetingClientV1 } Translation Service Client-ID: GreetingClientV1

Slide 15

Slide 15 text

@saturnism @googlecloud @grpcio Answer to everything Metadata → Context → Metadata Auth Token Deadline Distributed Trace ID

Slide 16

Slide 16 text

16 Let's see it...

Slide 17

Slide 17 text

17 grpc is Open Source We want your help! http://grpc.io/contribute https://github.com/grpc irc.freenode.net #grpc @grpcio [email protected]

Slide 18

Slide 18 text

Google Cloud Platform 18 @saturnism @googlecloud @grpcio https://github.com/saturnism/grpc-java-demos Thanks!