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

grpc Malmo

Avatar for Irina Scurtu Irina Scurtu
November 09, 2022

grpc Malmo

grpc Malmo presentation

Avatar for Irina Scurtu

Irina Scurtu

November 09, 2022
Tweet

More Decks by Irina Scurtu

Other Decks in Technology

Transcript

  1. @ i r i n a _ s c u

    r t u Irina Dominte(Scurtu) ▪ Romania Based ▪ Independent Consultant & Software Architect ( .NET at heart) ▪ Organizer of DotNetIasi user group & dotnetdays.ro conference ▪ I teach .NET ▪ Blog: https://Irina.codes @irina_scurtu
  2. @ i r i n a _ s c u

    r t u Back-end Front-end Back-end Back-end
  3. @ i r i n a _ s c u

    r t u 3rd party API 3rd party API
  4. @ i r i n a _ s c u

    r t u gRPC client server .proto
  5. @ i r i n a _ s c u

    r t u gRPC client server .proto
  6. @ i r i n a _ s c u

    r t u gRPC ▪ No-code references ▪ Contract based ▪ Uses HTTP/2 => faster ▪ Efficient ProtoBuf serialization => smaller payload ▪ Available in many languages ▪ Code generation out-of-the box
  7. syntax = "proto3"; option csharp_namespace = "MyFirstGrpc"; package Fibonacci; //

    The service definition. service Fibo { rpc ComputeFibonacci(RequestedNumber) returns (FibonacciResult){} } //the request message format message RequestedNumber { int32 number = 1; } //the response message format message FibonacciResult { int32 result = 1; }
  8. syntax = "proto3"; option csharp_namespace = "MyFirstGrpc"; package Fibonacci; //

    The service definition. service Fibo { rpc ComputeFibonacci(RequestedNumber) returns (FibonacciResult){} } //the request message format message RequestedNumber { int32 number = 1; } //the response message format message FibonacciResult { int32 result = 1; }
  9. syntax = "proto3"; option csharp_namespace = "MyFirstGrpc"; package Fibonacci; //

    The service definition. service Fibo { rpc ComputeFibonacci(RequestedNumber) returns (FibonacciResult){} } //the request message format message RequestedNumber { int32 number = 1; } //the response message format message FibonacciResult { int32 result = 1; }
  10. syntax = "proto3"; option csharp_namespace = "MyFirstGrpc"; package Fibonacci; //

    The service definition. service Fibo { rpc ComputeFibonacci(RequestedNumber) returns (FibonacciResult){} } //the request message format message RequestedNumber { int32 number = 1; } //the response message format message FibonacciResult { int32 result = 1; }
  11. syntax = "proto3"; option csharp_namespace = "MyFirstGrpc"; package Fibonacci; //

    The service definition. service Fibo { rpc ComputeFibonacci(RequestedNumber) returns (FibonacciResult){} } //the request message format message RequestedNumber { int32 number = 1; } //the response message format message FibonacciResult { int32 result = 1; }
  12. syntax = "proto3"; option csharp_namespace = "MyFirstGrpc"; package Fibonacci; //

    The service definition. service Fibo { rpc ComputeFibonacci(RequestedNumber) returns (FibonacciResult){} } //the request message format message RequestedNumber { int32 number = 1; } //the response message format message FibonacciResult { int32 result = 1; }
  13. @ i r i n a _ s c u

    r t u Modes/Method types ❑ Unary ❑ Server Streaming ❑ Client Streaming ❑ Bi-directional streaming
  14. @ i r i n a _ s c u

    r t u Server Streaming service Fibo { rpc ComputeFibonacci(RequestedNumber) returns (stream FibonacciResult){} }
  15. @ i r i n a _ s c u

    r t u Server Streaming service Fibo { rpc ComputeFibonacci(RequestedNumber) returns (stream FibonacciResult){} }
  16. @ i r i n a _ s c u

    r t u Bi-directional Streaming service Fibo { rpc ComputeFibonacci(stream RequestedNumber) returns (stream FibonacciResult){} }
  17. @ i r i n a _ s c u

    r t u Bi-directional Streaming service Fibo { rpc ComputeFibonacci(stream RequestedNumber) returns (stream FibonacciResult){} }
  18. gRPC ‘internals’ ▪ Status Codes != HTTP Status Codes ▪

    RpcException ▪ Interceptors ▪ Request headers ▪ Response headers ▪ Response trailers
  19. @ i r i n a _ s c u

    r t u Tweak some things builder.Services.AddGrpc(options => { options.EnableDetailedErrors = true; // options.MaxReceiveMessageSize = 2 * 1024 * 1024; // 2 MB // options.MaxSendMessageSize = 5 * 1024 * 1024; // 5 MB options.ResponseCompressionLevel = CompressionLevel.Optimal; options.ResponseCompressionAlgorithm = "gzip"; options.CompressionProviders = new List<ICompressionProvider>() { //brotli or your own }; // options.Interceptors.Add<Type>() });
  20. @ i r i n a _ s c u

    r t u Client side load balancing
  21. @ i r i n a _ s c u

    r t u Client side load balancing • DnsResolverFactory • StaticResolverFactory • Pick first or Round robin • You can implement your own resolvers
  22. @ i r i n a _ s c u

    r t u gRPC transcoding
  23. @ i r i n a _ s c u

    r t u Performance/ Size REST/ HTTP Api vs gRPC ~ 80% SMALLER payload
  24. @ i r i n a _ s c u

    r t u Polyglot environments
  25. @ i r i n a _ s c u

    r t u Low network usage
  26. @ i r i n a _ s c u

    r t u Point-to-point communication
  27. @ i r i n a _ s c u

    r t u ▪ Contract-based ▪ Smaller payloads ▪ HTTP/2 is faaaaaaaster ▪ Supports different streaming types over a single connection ▪ .NET 6 > can be configured to run with HTTP/3
  28. @ i r i n a _ s c u

    r t u Downsides ▪ Temporal coupling ▪ You might forget that there is a network involved ▪ Not human readable (until now) ▪ You’ll need better testing ▪ Focus on CI/CD ▪ Only HTTP POST -> no caching ▪ Single point of truth (.proto file) ▪ Not supported in Azure!(yet)
  29. @ i r i n a _ s c u

    r t u Downsides ▪ Temporal coupling ▪ You might forget that there is a network involved ▪ Not human readable (until now) ▪ You’ll need better testing ▪ Focus on CI/CD ▪ Only HTTP POST -> no caching ▪ Single point of truth (.proto file) ▪ Not supported in Azure!(yet)
  30. @ i r i n a _ s c u

    r t u Summary ▪ Great choice for microservice communication, point to point ▪ Replaces gracefuly HTTPClients ▪ Polyglot environments ▪ 4 modes/methods ▪ Decouples code
  31. @ i r i n a _ s c u

    r t u Thanks for listening! https://Irina.codes https://bit.ly/embracing-grpc
  32. @ i r i n a _ s c u

    r t u @irina_scurtu https://Irina.codes bit.ly/grpc-oredev