Similarity to WCF
Although the implementation and approach are different for gRPC, the experience of developing and consuming services with gRPC should be intuitive for WCF developers. The underlying goal is the same: make it possible to code as though the client and server are on the same platform, without needing to worry about networking.
Both platforms share the principle of declaring and then implementing an interface, even though the process for declaring that interface is different. And as you’ll see in chapter 5, the different types of RPC calls that gRPC supports map well to the bindings available to WCF services.
Benefits of gRPC
gRPC stands above other solutions for the following reasons.
Using HTTP/2 rather than HTTP/1.1 removes the requirement for human-readable messages and instead uses the smaller, faster binary protocol. This is more efficient for computers to parse. HTTP/2 also supports multiplexing requests over a single connection. This support enables responses to be sent as soon as they’re ready without the need to wait in a queue. (In HTTP/1.1, this issue is known as “head-of-line (HOL) blocking.”) You need fewer resources when using gRPC, which makes it a good solution to use for mobile devices and over slower networks.
There are gRPC tools and libraries for all major programming languages and platforms, including .NET, Java, Python, Go, C++, Node.js, Swift, Dart, Ruby, and PHP. Thanks to the Protocol Buffers binary wire format and the efficient code generation for each platform, developers can build performant apps while still enjoying full cross-platform support.
Usability and productivity
gRPC is a comprehensive RPC solution. It works consistently across multiple languages and platforms. It also provides excellent tooling, with much of the necessary boilerplate code automatically generated. So more developer time is freed up to focus on business logic.
gRPC has full bidirectional streaming, which provides similar functionality to WCF’s full duplex services. gRPC streaming can operate over regular internet connections, load balancers, and service meshes.
Deadline/timeouts and cancellation
gRPC allows clients to specify a maximum time for an RPC to finish. If the specified deadline is exceeded, the server can cancel the operation independently of the client. Deadlines and cancellations can be propagated through further gRPC calls to help enforce resource usage limits. Clients can also stop operations when a deadline is exceeded, or earlier if necessary (for example, because of a user interaction).
gRPC is implicitly secure when it’s using HTTP/2 over a TLS end-to-end encrypted connection. Support for client certificate authentication (see chapter 6) further increases security and trust between client and server.