Why gRPC?
gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.
gRPC vs REST
REST vs. gRPC: Battle of the APIs
When to Use What: REST, GraphQL, Webhooks, & gRPC
Is gRPC better than REST? Where to use it?
REST
REST 也许是最通用,也是最常用的接口设计方案,它是 无状态的,以资源为核心,针对如何操作资源定义了一系列 URL 约定,而操作类型通过 GET POST PUT DELETE 等 HTTP Methods 表示。
gRPC
RPC 主要用来做服务器之间的方法调用,影响其性能最重要因素就是 序列化/反序列化 效率。
gRPC 是对 RPC 的一个新尝试,最大特点是使用 protobufs 语言格式化数据,进一步提高了序列化速度,降低了数据包大小。
作为代价,双方都要知道接口定义规则才能序列化/反序列化。
1
也有一些额外手段将 gRPC 转换为 http 服务,让网页端也享受到其高效、低耗的好处。但是不要忘了,RPC 最常用的场景是 IOT 等硬件领域,网页场景也许不会在乎节省几 KB 的流量。
Video course
The complete gRPC course [Protobuf, Go, Java]
gRPC on .NET Core
Introduction to gRPC on .NET Core
The main benefits of gRPC are:
- Modern, high-performance, lightweight RPC framework.
- Contract-first API development, using Protocol Buffers by default, allowing for language agnostic implementations.
- Tooling available for many languages to generate strongly-typed servers and clients.
- Supports client, server, and bi-directional streaming calls.
- Reduced network usage with Protobuf binary serialization.
These benefits make gRPC ideal for:
- Lightweight microservices where efficiency is critical.
- Polyglot systems where multiple languages are required for development.
- Point-to-point real-time services that need to handle streaming requests or responses.
gRPC not supported on Azure App Service
ASP.NET Core gRPC is not currently supported on Azure App Service or IIS. The HTTP/2 implementation of Http.Sys does not support HTTP response trailing headers which gRPC relies on. For more information, see this GitHub issue.