Presentation is loading. Please wait.

Presentation is loading. Please wait.

Talking Between Services with gRPC

Similar presentations


Presentation on theme: "Talking Between Services with gRPC"— Presentation transcript:

1 Talking Between Services with gRPC
Marc Gravell @marcgravell

2 Talking Between Services with gRPC
Marc Architecture Team, Stack Overflow Microsoft MVP network focus, meta-programming focus protobuf-net Dapper StackExchange.Redis FastMember (etc) 00:00 – 00:30

3

4 Agenda What is gRPC and why would I want to use it?
How would I use gRPC, today? What are the strengths and weaknesses? What is new in gRPC and .NET Core 3 (part 1)? What is new in gRPC and .NET Core 3 (part 2)? Summary . 0:30-2:30

5 The world of services 2:30-3:30

6 What is gRPC and why would I want to use it?
RPC stack developed and used by Google Open sourced in Feb 2015 Platform independent High performance Based on “protocol buffers” (“protobuf”) and HTTP/2 Necessary if talking to external services that are gRPC (e.g. Google) A good choice for your own systems if you want efficient, robust, well- designed/implemented/tested, cross-platform RPC! Usually, gRPC is used with protobuf, so to understand gRPC, we first need to understand protobuf . 3:30-5:30

7 What is protocol buffers and why would I want to use it?
Binary serialization protocol designed and used by Google (JSON variant added later, but doesn’t apply to gRPC) Open sourced in July 2008 Platform independent High performance Low CPU to process Low bandwidth to transmit Version tolerant . 5:30-7:30

8 How would I use gRPC, today?
DEMO 7:30-17:30

9 How would I use it, today? We should have seen:
Setting up a basic project with protobuf support Creating a .proto schema The generated code for data contracts, service clients, and service implementations How to implement and host a service How to create a client A working client and server! (?) Getting hold of metadata Cancellations (not covering security/auth, but those things exist etc) . 17:30-19:30

10 Today (generated code) Grpc.Core.Api Grpc.Core 19:30-20:30 chttp2

11 What are the strengths and weaknesses?
+ DSL is strong for cross-platform; same contract can be used from many languages / frameworks - having to create and maintain the schema in .proto can be a nuisance for simple work - awkward setup and tooling +/- API is “idiomatic protobuf/gRPC, in C#” rather than “idiomatic .NET, doing protobuf/gRPC” - code-gen is C#-only (for .NET-land) - code-gen is proto3-only (for .NET-land) - gRPC stack is native/unmanaged and doesn’t play nicely with Kestrel, HttpClient, etc - generated code with full implementation is verbose and restrictive - the streaming API is … just weird! . 20:30-23:30

12 What is new in gRPC and .NET Core 3? (part 1)
Microsoft writing new libraries that work with the existing generated code for gRPC (HTTP/2) in managed code New client bindings that use HttpClient New server bindings that use Kestrel (ASP.NET Core server) . 23:30-25:30

13 Today (generated code) Grpc.Core.Api Grpc.Core 25:30 chttp2

14 (generated code) Grpc.Core.Api Grpc.Net.Client Grpc.Core HttpClient
.NET Core 3 Today (generated code) Grpc.Core.Api Grpc.Net.Client Grpc.Core 25:30-26:00 HttpClient chttp2

15 Grpc.AspNetCore.Server
Today .NET Core 3 (generated code) Grpc.Core.Api Grpc.Net.Client Grpc.Core Grpc.AspNetCore.Server 26:00-26:30 HttpClient chttp2 ASP.NET Core

16 What is new in gRPC and .NET Core 3? (part 1)
DEMO 26:30-31:30

17 What is new in gRPC and .NET Core 3? (part 1)
We should have seen: Creating a server in Kestrel Creating a client with HttpClient That other than actual setup of the client and server, everything else stays the same – just now: less unmanaged… …which means we still have all the other pain points . 31:30-33:30

18 .proto schema (generated code) Google.Protobuf Grpc.Core.Api
Today via Grpc “contract-first” .proto schema (generated code) 33:30-34:30 Google.Protobuf Grpc.Core.Api

19 What is new in gRPC and .NET Core 3? (part 2)
New protobuf-net tooling (protobuf-net.Grpc) Works against either the old unmanaged bindings or the new managed bindings, for both client and server Defaults to protobuf-net (put configurable) Re-imagines the API surface of services Fully supports both code-first and contract-first styles of code Supports both “proto2” and “proto3” Isn’t limited to C# …does anyone remember WCF? (…I mean the good bits of WCF, not everything) . 34:30-35:30

20 .proto schema (generated code) Google.Protobuf Grpc.Core.Api
Today via Grpc “contract-first” .proto schema (generated code) 35:30 Google.Protobuf Grpc.Core.Api

21 .proto schema .NET types (generated code) (meta-programming)
Today via Grpc protobuf-net.Grpc (preview) “contract-first” “code-first” .proto schema .NET types (generated code) (meta-programming) 35:30-37:30 Google.Protobuf protobuf-net (…+?) Grpc.Core.Api

22 What is new in gRPC and .NET Core 3? (part 2)
DEMO 37:30-42:30

23 What is new in gRPC and .NET Core 3? (part 2)
We should have seen: Defining our data and services in code as simple classes and interfaces Creating a server (with either Grpc.Core or Kestrel) Creating a client (with either Grpc.Core or HttpClient) Creating nice clean code from a .proto schema Using other languages Idiomatic .NET code Streaming made simple via asynchronous streams Avoiding Grpc.Core means : no native libraries! . 42:30-43:30

24 Summary gRPC is a great tool for general purpose calls between services By default, it takes a little bit of effort; it may be more effort than simpler tools The unmanaged implementation makes deployment awkward With .NET Core 3, Microsoft are fixing half of the problems… …and tools like protobuf-net.Grpc can be used to fix the other half (other similar tools exist; MagicOnion, etc) Mostly pre-preview – “here be dragons”; maybe wait for preview7? Please feel free to come and find me to discuss in more depth! . 43:30-44:30

25 THANKS! (and questions?) https://github.com/grpc/grpc
THANKS! (and questions?) Marc Gravell @marcgravell


Download ppt "Talking Between Services with gRPC"

Similar presentations


Ads by Google