Skip to content
All posts

gRPC: The Beauty of Simplicity

simplicity-header-imageWe often overlook the value of simplicity, particularly in our modern technology ecosystem where futuristic tooling seems to debut continuously. However, simple options can usually be elegant and save teams time (and money). In that spirit, let's look at a simple tool: gRPC.

What is gRPC?

Before we get into the nitty-gritty of gRPC, which is considered an alternative to REST, let's start by familiarizing ourselves with remote procedure calls (RPC). A local procedure call is a function call within a program to execute a piece of code--while remote procedure calls allow one machine to invoke a program on another machine as if it were a local function call from a user's perspective. In 2015, Google released its implementation of an RPC, which is now known as gRPC. Since then, many organizations like Netflix, Square, and Cisco have adopted gRPC as their go-to RPC implementation to connect large numbers of microservices within and across data centers.

Now that we have a basic understanding of an RPC, we can dive deeper. gRPC is an open-source, high-performance RPC framework widely used by developers to create distributed applications running on different machines. Built on top of HTTP/2, gRPC allows client and server applications to efficiently connect, operate, and communicate with one another in a variety of environments. Furthermore, one of gRPC's core strengths is that it supports many languages (language agnostic). This means you can build a server in Java with clients in Python, C++, or even Ruby.

infographic showing three pieces of grpc: Application (with software updates, microservices, internet of things, and streaming), Data Format (with some code around deviceinfo), and Transmission (showing how client and server applications are connected via hhtp/2)

Where does gRPC shine?

Exploring the benefits of gRPC will reveal the heart of its success, especially when considered as an alternative to the more established REST. First, gRPC leverages protocol buffers and HHTP/2 as its transport protocol, proven to outpace REST and JSON in performance. Unlike REST, which typically operates over HTTP/1.1 with several TCP connections, gRPC leverages HTTP/2. gRPC's use of HTTP/2 allows several data streams to travel over a single TCP connection. Consequently, the gRPC framework can handle simultaneous RPC calls over TCP connections between clients and servers.

gRPC's adoption of HTTP/2 features means it faces limited browser support. Most web browsers do not permit low-level access to HTTP/2 primitives, which is necessary for gRPC web clients and servers. Despite this limitation, gRPC has gained popularity for its interoperability and features like authentication, load balancing, and streaming. These characteristics make gRPC a compelling choice for businesses to adopt into their projects since improved performance and efficiency can translate to cost savings. Compared to REST, gRPC offers an efficient and versatile framework, making it an appealing alternative in scenarios where performance and scalability are prioritized.

gRPC and Protocol Buffers

gRPC leverages protocol buffers as its interface definition language instead of traditional formats like XML or JSON. Using this method, developers can encode structured data in any language. Subsequently, a protocol compiler transforms proto-text files into the desired language and compresses messages into binary format at runtime. gRPC's binary encoding format significantly contributes to its efficiency. It is said to be up to five times faster than JSON. Moreover, protocol buffers offer the advantage of a clearly defined schema, ensuring smooth data transfer between client and server, which yields fewer errors. Thanks to the tooling support of protocol buffers, converting the schema in the proto file into data access classes for popular programming languages is trivial.

gRPC in Action

Let's make sense of gRPC through an example highlighting its role in modern software communication. Many of us have a smart home ecosystem designed to have centralized control over all our devices inside our homes. In this example, your mobile app (centralized IoT management platform) will act as the gRPC client, which enables you to control your smart home devices. As the gRPC client, it sends requests to various IoT devices to retrieve status updates, adjust settings, or trigger other actions. Meanwhile, IoT devices like smart thermostats, lights, and security cameras will represent the gRPC servers. These devices listen and wait for commands from your mobile app before executing them.

Let's say you want to reduce your gas bill this month, so you decided to lower the thermostat temperature for the entire house using your mobile app. The app (gRPC client) sends a gRPC call to the smart thermostat, instructing it to lower the temperature. The thermostat (gRPC server) processes the request, lowers the temperature, and confirms the action has been completed by responding to your app.

In this scenario, a protocol buffer would define the schema for device information, such as device ID, type, status, and other relevant attributes. Additionally, protobufs would be used to define control commands sent from your mobile app to the devices for adjusting temperature and other settings. This highlights gRPC's ability to support multiple programming languages, allowing for compatibility across many devices.

BBI and gRPC

Understanding the benefits of gRPC, BBI has implemented it into several projects. BBI works with data across several languages, requiring a language-agnostic system capable of efficiently processing and translating information through different services. By leveraging HTTP/2 and protocol buffers, gRPC provides the high-speed data exchange necessary for BBI's international projects, reducing latency and improving the overall efficiency of data communication. Additionally, some of BBI's clients already have systems that may use various technologies. Hence, our solutions need to seamlessly integrate with what our clients have already built— this is where gRPC comes into play. Most importantly, gRPC provides built-in security features by incorporating transport-level security and other authentication mechanisms. This allows BBI to build secure communication channels.

For example, BBI is developing a real-time inventory management system for a global retail chain, requesting the synchronization of inventory data across its stores in different regions. Using gRPC, BBI could design a system that seamlessly integrates with the retailer's existing point-of-sale system, programming languages, and technologies. By using HTTP/2 and protocol buffers, the retailer can maintain a high-speed data exchange between stores, warehouses, and their e-commerce platforms. This would reduce latency, ensuring real-time inventory updates. This would let customers know that they always have an accurate number of stocks, improving customer satisfaction and sales.

Modernization Requires Simplicity

The race to modernize and establish the proper foundation for technical excellence has been and will continue. While the shiniest innovations can be attractive and valuable, take notice of the basics. Learn more about BBI's dedication to a strong foundation in this post from CEO Ravneet Singh.

BBI Java Intern Alex Perez also contributed to this article.