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

Improving Microservice Performance with gRPC

Improving Microservice Performance with gRPC

Microservices are a great pattern to follow for complex applications, but all those REST endpoints decrease performance. One way to improve that is with gRPC. This presentation gives a brief overview then drills into how to implement it in .NET.

Craig Berntson

November 14, 2022
Tweet

More Decks by Craig Berntson

Other Decks in Programming

Transcript

  1. Who am I? • Enterprise Architect • Defrocked Microsoft MVP

    (23 years) • Conference speaker across North America and Europe • Former columnist .Net Curry magazine • Co-author Continuous Integration in .Net
  2. Today’s Topics • What is gRPC and why you should

    use it • Protocol buffers • gRPC servers and clients in .Net 6 • Testing servers • Code-first gRPC in .Net 6
  3. Process Decode Encode Encode Browser Web Server Microservice Process Decode

    Process Decode Encode Decode Request Response Microservice Process Decode Encode Microservice Process Decode Encode Encode Process Decode
  4. Process Decode Encode Browser Web Server Microservice Process Process Encode

    Decode Request Response Microservice Process Microservice Process Process
  5. gRPC • Originated at Google as the next-gen of Stubby

    • Supports TLS (https) and token-based authentication • Can do one-way, two-way, streaming • Uses Protocol Buffers to encode data • Supported in C#, C++, Dart, Go, Java, Kotlin, Node, Objective-C, PHP, Python, Ruby • gRPC-Web (not officially supported) • Adopted by Google, Uber, Square, Netflix, IBM, Docker, Cisco, Spotify, Dropbox, Microsoft, and many others
  6. gRPC in .Net 6 • Client-side load balancing • Transient

    fault handling with retries • Performance improvements
  7. “Given the impressive performance benefits of moving to .NET Core,

    our North Star goal is to migrate all Substrate processes to .NET Core and to move all internal microservices to use gRPC for communication.” https://devblogs.microsoft.com/dotnet/exchange-online-journey-to-net-core/
  8. Using gRPC in C# Server 1.Create contract 2.Create server 3.Compile

    Client 1.Consume contract 2.Create calling code 3.Compile
  9. Protocol Buffers syntax = "proto3"; option csharp_namespace = “MovieCatalog_v1”; service

    MovieCatalog { rpc SaveNewMovie (MovieItem) returns (AddMovieResponse) {} rpc FetchExistingMovie (FetchMovieRequest) returns (MovieItem) {} } message MovieItem { string name = 1; double price = 2; bool inStock = 3; } message AddMovieResponse { bool wasSaved = 1; int32 itemId = 2; } message FetchMovieRequest { string name = 1; }
  10. Issues with the .proto file approach • Uses unmanaged code

    • Difficulty sharing .proto files • Unfamiliar process/syntax to .Net developers • Code generation at compile time
  11. Code First • Community created • Supported by Microsoft •

    No .proto files -- .Net only • Uses WCF-like syntax • 100% Managed Code
  12. Cartoon Domain Studio Domain Cartoonalogue.API CartoonDomain. Shared. Commands CartoonDomain. Shared.Queries

    CartoonDomain. Command. Service CartoonDomain. Common CartoonDomain. Query. Service Cartoon StudioDomain. Shared. Commands StudioDomain. Shared.Queries StudioDomain. Command. Service StudioDomain. Common StudioDomain. Query. Service Studio Contracts Entities
  13. Today’s Topics • What is gRPC and why you should

    use it • Protocol buffers • gRPC servers and clients in .Net 6 • Code-first gRPC in .Net 6