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

gRPC Extensibility

Ryan Michela
December 05, 2018

gRPC Extensibility

gRPC is a powerful framework for building scalable, performant microservices. As the framework matured, extension points were added to allow users to customize gRPC's behavior to fit their needs. This session explores gRPC's extensibility, giving you the knowledge you need to adapt gRPC for your requirements.

This survey of gRPC's extensibility will shine a light onto some of the less well known features of gRPC, and will compare their availability across gRPC's supported platforms.

https://www.meetup.com/gRPCio/events/256718623

Ryan Michela

December 05, 2018
Tweet

Other Decks in Technology

Transcript

  1. What will we see? • Survey of gRPC’s extensibility points

    • Code examples, where practical (Java) • Cross language comparison • Not authoritative • From least arcane to most arcane
  2. How can we extend gRPC? • Interceptors + Context •

    Service config + Name resolution • Client-side load balancing • Message serialization • Reflection and Channelz • Protoc compiler plugins
  3. CTX Request/Response Interceptors • Most flexible extension point • Chainable

    middleware • Many uses • HTTP/2 headers • Message validation • Error logging • Default options • Request throttling • AuthN/AuthZ • Use Context to interface with app code Client Stub Client Interceptor Client Interceptor Client Interceptor Channel Server Stub Server Interceptor Server Interceptor Server Interceptor Channel Interceptors Java Go C++ Python Ruby C# Node.js Objective-c PHP Context Java Go C++ Python Ruby C# Node.js Objective-c PHP
  4. Service Configuration • Environmental metadata for controlling client behavior •

    Load balancing policy • Timeouts • Retry policy – status codes, backoff • Hedging policy • Throttling policy • Match criteria – canary releases • DNS TXT records - JSON • service_config.md • A2-service-configs-in-dns • A6-client-retries Java Go C++ Python Ruby C# Node.js Objective-c PHP
  5. Custom Name Resolvers • Overrides how gRPC resolves host names

    • Populates service configuration during resolution • Example uses: • Service discovery integration – Consul, Etcd • Custom Kubernetes integration (label-based name resolution?) • Bypass DNS altogether – file-based name resolution • Explicitly loaded with ManagedChannelBuilder.nameResolverFactory() • Discovered by ServiceLoader by implementing NameResolverProvider • naming.md Java Go C++ Python Ruby C# Node.js Objective-c PHP
  6. Load Balancers • Balancing-aware client - Fat client model •

    Proxy model – Envoy, Linkerd, NGINX • External load balancing service – gRPC-LB Client Server Server Server Proxy Server Server Server Client Client Server Server Server LB
  7. Client Load Balancers • Out of the box – chosen

    by service config • Pick First – default • Round-robin • gRPC-LB (external load balancing) • Create your own • Implement LoadBalancer • Implement a LoadBalancerProvider • Reference in ManagedChannelBuilder or Service Configuration • Not trivial – see PickFirstLoadBalancer Java Go C++ Python Ruby C# Node.js Objective-c PHP
  8. gRPC-LB • DNS SRV Records to configure • load-balancing.md •

    LB Server implements proto • https://github.com/grpc/grpc/tree/master/src/proto/grpc/lb/v1 • https://github.com/bsm/grpclb Java Go C++ Python Ruby C# Node.js Objective-c PHP
  9. Message Serialization • Not just protobuf. Really! • gRPC generated

    stubs bind to protobuf, not the runtime • You have to write your own stubs L • https://grpc.io/blog/grpc-with-json Java Go C++ Python Ruby C# Node.js Objective-c PHP
  10. Reflection API and Channelz API • Ask a running server

    to describe its endpoints and internals • server-reflection.md - Built on descriptor sets • A14-channelz.md • Uses • Runtime debuggers • Interactive CLIs • Diagnostic tools Reflection Java Go C++ Python Ruby C# Node.js Objective-c PHP Channelz Java Go C++ Python Ruby C# Node.js Objective-c PHP
  11. Protoc Compiler Plugins • Input: compile protobuf descriptor set •

    Output: any text • Frameworks: • Protoc-gen-star - Go • jProtoc – Java • Uses • Documentation generator • Validation frameworks • Alternate stubs and bindings • Utility code generator Java Go C++ Python Ruby C# Node.js Objective-c PHP