Intrigued by why some of the world's largest companies (Netflix, Google, Cisco, Twitter, Uber etc) are using gRPC? In this demo based talk we delve into the world of gRPC in .Net, what it does and why we should use it. We compare the interface with both Rest and graphQL. We will show you how to ...
Intrigued by why some of the world's largest companies (Netflix, Google, Cisco, Twitter, Uber etc) are using gRPC? In this demo based talk we delve into the world of gRPC in .Net, what it does and why we should use it. We compare the interface with both Rest and graphQL. We will show you how to implement grpc server-side in .net and in the web. Finally, I will show you how the tooling helps you deliver powerful interfaces and interact with them quickly and simply.
Size: 1.32 MB
Language: en
Added: May 24, 2024
Slides: 17 pages
Slide Content
Demystifying gRPC By John Staveley MVP 23/05/2023 https://uk.linkedin.com/in/johnstaveley/ @ johnstaveley
Overview Who uses it? What is it? Why use it? Basic gRPC method calls in C# Tooling in VS Streaming Using over the web
Who uses gRPC ? created in 2015
What is gRPC ? Http2 Protocol buffers Binary formatting TLS Support for cross cutting concerns such as authentication and error handling Good language support: C# / .NET, C++, Dart, Go, Java, Kotlin, Node, Objective-C, PHP, Python, Ruby, JavaScript
Why? gRPC vs Both cross platform gRPC 7 to 10 times faster than REST REST has native browser support, gRPC has support via gRPC -Web REST has loose contracts, gRPC has strict contracts Json is human readable REST is better for massive payloads
Both: gRPC and Released 2015/2016 Advantages over Rest Interface Definition Language Open source Publish Single Endpoint
Why? gRPC vs Transport Agnostic (Mostly http) Uses Json Can get all data together (easier to combine method calls) Weaker coupling One-way streaming Caching of Get requests does not work by default Used over Http/2 Uses Protobuf (Smaller packet size, faster serialisation) Single method at a time Stronger coupling Two-way streaming
How? Getting started with C# NuGet packages Default project ( ASP.NET Core gRPC service) Setting up your service project The .proto file Startup
DEMO 1: Hello world Server Basic gRPC project Greeter service Call using postman or grpccurl
Protocol buffers Interface Definition Language Types: bool, string, bytes, float, double, int32, int64, uint32, uint64, sint32, sint64. Full list here: https://protobuf.dev/programming-guides/proto3/#scalar Other types: import " myproject / other_protos.proto "; E.g. Timestamp Field numbers must be unique!
DEMO 2: Client Console project Install packages Add a service reference of type gRPC Add client code DEMO: Calling new method from client code
Extending the basic service Timestamp Enum Reserve keyword Optional keyword Empty type Streaming (1 way / 2 way) Authentication https://protobuf.dev/reference/csharp/api-docs/
Cloud gRPC support EC2 and Application Load Balancer Azure App Service Http = 2.0 Http 2.0 Proxy = On/ gRPC Only End to End Encryption = On Both support unary and streaming modes
Calling from the web Server uses grpc -web proxy Install-Package grpc.aspnetcore.web Web client Install Npm packages Talk through and execute Generate.ps1 Talk through send.js
In Summary gRPC : High speed, well supported Good for streaming and polyglot services Used on the web via grpc -web proxy Well supported with tooling in VS, Postman etc