From the time our industry has discovered networking by interconnecting systems, the hunt for a most advanced remote communication has begun. gRPC is a modern inter-process communication technology that allows us to build distributed applications.
When gRPC was launched, it was immediately used by CoreOS, Netflix, Square, and Cockroach Labs and many more within a year of launch. Etcd by CoreOS, a distributed key/value store, uses gRPC for peer communication. Telecom companies like Cisco, Juniper, and Arista are using gRPC for streaming the telemetry data and network configuration from their networking devices.
gRPC’s secret recipe lies in the way serialisation is handled. Internally gRPC uses binary messaging using protocol buffers which runs on top of HTTP/2. So gRPC is a strongly typed, polyglot communication protocol that allows us to build request – response , style synchronous communication, as well as we can use duplex streaming.
gRPC with protocol buffers is used for communication between app and the server. gRPC is already built on top of HTTP/2. In gRPC the streaming is easy, say we want to build other realtime opponents in the game , gRPC makes life easy. It also supports types and validations and is faster compared to JSON as we have strict type checking.
Consider any Service, you generate a gRPC service from the service definition and you have clients talking to that service. It can be a mobile client or a desktop client talking to the service, through the stubs and all the connection details are abstracted. Then, your one service could be talking to another service using a stub. In fact, it could happen that your second service talks to two other services, again through stubs.
The beauty of this model is that communication between client and server, and between microservice’s, all happen through stubs that gRPC handles.
Let’s quickly look at what are some of the advantages of gRPC :
1. Known for its functional design : Because gRPC used protoBufs as their messaging format , it favours a more functional approach to their APIs.
2. Slashes network latency to a great extent : gRPC builds on HTTP/2, which allows for faster and long-lived connections, reducing the time for setup/teardown common for individual HTTP/1.x requests.
3. Infra support : RPC often uses Kubernetes on Google Kubernetes Engine (GKE), which provides built-in proxy and load balancing support.
4. Bi-directional communication : gRPC takes advantage of HTTP/2’s bi-directional communication support, removing the need to separately support request/response.
5. Documentation: Since gRPC started within Google, documentation is extensive on the gRPC website.
Why is gRPC a right fit for multiplayer gaming applications ?
A multiplayer game project will require a modern real-time API. And the next bottleneck would be solving scalability issues. The main feature of bi-directional streaming in gRPC plays an important role in it being used to implement gaming applications. servers have a period of time where they accept requests, change game state, then broadcast all state changes at once to all clients.
In terms of gRPC integration, the client is similar to the server. It streams responses and converts them to the game engine can understand and also update the state of the game directly.
In a gaming application, the state of the game becomes very crucial at this point in time. The reduced latency that gRPC provides wins the battle to get away from the sticky states. Hence gaining advantage of a lower latency to enable quicker state management in the game.
REST has been around for 20+ years and gRPC is not a replacement for REST. gRPC APIs can offer huge performance improvements and reduced response time as compared to REST APIs, but which approach to choose comes down to what fits your particular use case.