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

Beyond HTTP in ASP.NET Core 3 with gRPC

Steve Gordon
September 11, 2019

Beyond HTTP in ASP.NET Core 3 with gRPC

In this session, Steve will share gRPC, a modern high-performance RPC framework for inter-service communication. You'll discover how gRPC stacks up against existing REST-based communication and explore the benefits this technology has to offer, for example, its use of HTTP/2 as its transport protocol and ProtoBuf encoded content for efficient, fast communication.

You'll explore C# examples of how to build client and server gRPC components using ASP.NET Core 3.0, using the blazingly fast Kestrel web server. You'll learn how to define your proto3 service definition (contract) and integrate with MSBuild tooling to code-gen the server and client components you'll need. You'll be amazed at how quickly a service can be created with little effort or boilerplate code required. You'll also see how additional clients can easily be generated for other languages such as Node.js to make connecting polyglot systems a breeze.

It's a great time to begin taking notice of gRPC as a worthy contender to take over from REST for inter-service communication in microservice-based environments. It's time to start letting service talk their own language!

Steve Gordon

September 11, 2019
Tweet

More Decks by Steve Gordon

Other Decks in Technology

Transcript

  1. BEYOND HTTP IN ASP.NET CORE 3.0 WITH gRPC Steve Gordon

    @stevejgordon | stevejgordon.co.uk http://bit.ly/dotnet-grpc
  2. @stevejgordon www.stevejgordon.co.uk • Contract based • Supports code generation •

    Multi-platform C#, C++, Dart, Go, Java, Node, Objective-C, PHP, Python, Ruby • HTTP/2 • Uses a binary, Protobuf payload
  3. @stevejgordon www.stevejgordon.co.uk 2001 Google Stubby March 2015 gRPC open sourced

    August 2016 gRPC v1.0.0 Sept 2019 gRPC .NET with .NET Core 3.0
  4. @stevejgordon www.stevejgordon.co.uk syntax = "proto3"; option csharp_namespace = "HelloWorld"; package

    Greet; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; }
  5. @stevejgordon www.stevejgordon.co.uk syntax = "proto3"; option csharp_namespace = "HelloWorld"; package

    Greet; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; }
  6. @stevejgordon www.stevejgordon.co.uk syntax = "proto3"; option csharp_namespace = "HelloWorld"; package

    Greet; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; }
  7. @stevejgordon www.stevejgordon.co.uk syntax = "proto3"; option csharp_namespace = "HelloWorld"; package

    Greet; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; }
  8. @stevejgordon www.stevejgordon.co.uk syntax = "proto3"; option csharp_namespace = "HelloWorld"; package

    Greet; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; }
  9. @stevejgordon www.stevejgordon.co.uk SERVICE B (NODE) SERVICE C (.NET) SERVER SERVICE

    A (.NET) SERVER CLIENT SERVICE D (GO) SERVER CLIENT CLIENT PROTO A PROTO A PROTO B PROTO B PROTO C PROTO C
  10. @stevejgordon www.stevejgordon.co.uk • Unary Single request with a single response

    – A normal function call • Server Streaming Single request with a stream of responses for the client to consume • Client Streaming Client sends a stream of requests, each receiving a single response • Bidirectional Streaming Client sends a stream of requests and consumes a stream of responses
  11. @stevejgordon www.stevejgordon.co.uk • No need for *.proto • Apply attributes

    to .NET interfaces and classes • Interface(s) define your services • Classes define your message models • Can also use a *.proto to generate the C# code • Share contracts as libraries between .NET servers and clients
  12. @stevejgordon www.stevejgordon.co.uk • Performance • Efficient binary serialisation (low CPU

    overhead) using Protobuf • Smaller payloads • HTTP/2 is fundamentally quicker • Code-gen server and clients for many languages/frameworks • Contract based • Supports first class streaming
  13. @stevejgordon www.stevejgordon.co.uk • Code generation in .NET is C# only

    • Kestrel doesn't support HTTP/2 with TLS on macOS https://docs.microsoft.com/en-us/aspnet/core/grpc/aspnetcore?view=aspnetcore-3.0&tabs=visual-studio#grpc-and-aspnet-core-on-macos • Harder to exercise without tools such as Postman
  14. @stevejgordon www.stevejgordon.co.uk • A great choice for microservice communication •

    A good way to support server-to-server communication in polyglot environments • Easy to get started using the gRPC service template • gRPC .NET libraries make creating servers and clients very easy https://github.com/grpc/grpc-dotnet