Interview frequency: …
Short answer
They define strongly typed service and message contracts in .proto files, and the C# compiler generates fast base classes that communicate over HTTP/2 using compact binary serialization.
Explanation
gRPC is well suited to direct communication between .NET Microservices. Protocol Buffers reduce network payload size and serialization time compared with JSON (the improvement depends on the data). gRPC also natively supports bidirectional streaming (Client & Server Streaming) and strongly defined contracts across languages.
Code example
// Greeter.proto
syntax = "proto3";
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest { string name = 1; }
message HelloReply { string message = 1; }Common mistakes
- Reusing field numbers or changing existing field numbers in a .proto file, breaking binary compatibility with older versions.