Share This
//gRPC – A New Leap for Your Microservices

gRPC – A New Leap for Your Microservices

As systems transition to the Microservices model, the number of API calls increases, resulting in performance degradation due to the data transmission burden. gRPC has emerged as a potential solution to this problem.

This article will provide the concepts and basic operating principles of gRPC, helping you understand how it works, its advantages and disadvantages, and its future applicability.

1. Introduction to gRPC

gRPC is an open-source framework that supports efficient remote communication (RPC: Remote Procedure Call) between services in a distributed system.

This platform is developed by Google and uses the HTTP/2 protocol for data transmission, offering many advantages over traditional methods like RESTful APIs.

With gRPC, you can write code as if you’re calling a function on a local machine, even though the function actually resides on a different machine.

2. How gRPC Works

gRPC uses protobuf to describe services and methods that can be called remotely.

gRPC

Illustration from the gRPC website

Protobuf (Protocol Buffers) is an IDL (Interface Definition Language), a language for defining interface communication used to describe data structures.

We can define the structure of data and the methods of a service in a proto file.

Then use protoc to compile it into source code for various programming languages, which can serialize and deserialize these data structures into binary streams.

Compared to XML or JSON, the data generated is 3-10 times smaller and processed much faster.

gRPC Architecture

gRPC Architecture

gRPC provides tools to create server and client stubs from service definitions.

The client uses the stub to call methods on the server.

Data is transmitted between the server and the client in binary form.

3. Advantages of gRPC

  • High performance: gRPC uses protobuf to encode data into binary, reducing the size of transmitted data and speeding up processing compared to JSON/XML.

Protobuf outperforms in speed and size compared to JSON. See this article link (1)

  • Resource-saving: gRPC uses HTTP/2 more efficiently than HTTP/1.1, reducing CPU and memory load on both the server and client. HTTP/2 allows multiple requests/responses in a single connection. Furthermore, everything in HTTP/2 is encrypted before being sent, including the header. There are many other benefits; explore more about HTTP/2.
  • Multi-language support: gRPC supports many popular programming languages like Java, Python, Go, C++, PHP, Ruby, etc. Applications can be written in different languages, and gRPC has many libraries to support that.
  • Flexibility: gRPC can be used for various use cases, from Microservices to IoT and Streaming media.
  • Cross-platform support: gRPC can run on different operating systems and architectures, enhancing system compatibility.
  • Security: gRPC supports security protocols like TLS/SSL to protect transmitted data.
  • Efficient connection management: gRPC provides efficient connection management features like HTTP/2 multiplexing, minimizing the number of required connections and improving performance.
  • Scalability: gRPC can easily scale to support a large number of connections and handle high traffic volumes.

4. Disadvantages of gRPC

  • Higher learning curve: gRPC uses protobuf to describe services, requiring users to have knowledge of protobuf. This can create a barrier for beginners, especially when compared to RESTful API, which is more popular and easier to access.
  • Smaller community support compared to RESTful API: Since RESTful API has been widely used for a long time, its community support is much larger and stronger than gRPC’s. This could make it harder for gRPC users to find help when issues arise.
  • Harder debugging: gRPC uses binary encoding for data transmission, making it harder to trace information compared to RESTful APIs, which use JSON or XML that are easier to read.
  • Dependency on HTTP/2: gRPC depends on HTTP/2 to function, so it cannot be used in environments that do not support HTTP/2, limiting its flexibility.
  • Browser limitations: Unlike RESTful APIs, gRPC is not fully supported by all web browsers. This may create difficulties in developing web applications using gRPC, requiring workarounds such as gRPC Gateway.

However, it should be noted that these limitations are gradually being improved. gRPC frameworks are integrating more, and its community is rapidly growing, promising more resources and support in the future.

5. Comparing gRPC with RESTful API

gRPC and RESTful API are two popular remote communication methods used to transfer data between services in a distributed system. Each method has its own advantages and disadvantages.

Besides the similarities in scalability, multi-language support, cross-platform support, flexibility, and security, here are the differences:

FeaturegRPCRESTful API
PerformanceHighMedium
Resource-savingHighMedium
Learning curveHighMedium
Community supportMediumHigh
Connection managementEfficientMedium
Browser supportLimitedGood

6. Applications of gRPC

  • Microservices: gRPC is an ideal choice for communication between services in a Microservices architecture.
  • IoT: gRPC can be used to connect IoT devices to each other and to other services.
  • Streaming media, games: gRPC can be used for streaming video and audio, and for developing multiplayer games.

7. Conversion and Development Solutions

Not all applications support gRPC. During conversion, there will still be applications using RESTful API. So, how can these applications communicate with each other? There are two ways to solve this problem:

  1. gRPC Gateway: gRPC Gateway acts as a service proxy, converting HTTP requests to gRPC and vice versa. It allows the use of gRPC with applications that do not directly support gRPC.
    The downside of this is that the data will go through an additional step, which could increase latency during transmission.
    Cloud Endpoints of Google using gRPC

    Illustration of Google Cloud Endpoints using gRPC

  2. Build a service supporting both gRPC and RESTful API: The downside is that it increases the complexity of the project. However, for frameworks that support it, this can be done easily. See this article link (2) in the references section.

8. References

This article provides basic information about gRPC. You can visit the links below for more detailed information.

Conclusion

gRPC is a powerful and efficient framework for remote communication.

This platform offers several advantages over traditional methods like RESTful APIs, improving performance and saving resources for the system. However, gRPC also has some limitations to consider before using it.

Here are some tips before adopting gRPC for your system:

  • Use gRPC for distributed systems requiring high performance and resource efficiency.
  • Consider carefully before using gRPC for web applications.
  • In development, use additional tools that support gRPC to simplify development and debugging.

Good luck!

Phạm Trịnh Minh Triết
Java Developer

APPLY NOW






    Benefits

    SALARY & BONUS POLICY

    RiverCrane Vietnam sympathizes staffs' innermost feelings and desires and set up termly salary review policy. Performance evaluation is conducted in June and December and salary change is conducted in January and July every year. Besides, outstanding staffs receive bonus for their achievements periodically (monthly, yearly).

    TRAINING IN JAPAN

    In order to broaden staffs' view about technologies over the world, RiverCrane Vietnam set up policy to send staffs to Japan for study. Moreover, the engineers can develop their career paths in technical or management fields.

    ANNUAL COMPANY TRIP

    Not only bringing chances to the staffs for their challenging, Rivercrane Vietnam also excites them with interesting annual trips. Exciting Gala Dinner with team building games will make the members of Rivercrane connected closer.

    COMPANY'S EVENTS

    Activities such as Team Building, Company Building, Family Building, Summer Holiday, Mid-Autum Festival, etc. will be the moments worthy of remembrance for each individual in the project or the pride when one introduces the company to his or her family, and shares the message "We are One".

    INSURANCE

    Rivercrane Vietnam ensures social insurance, medical insurance and unemployment insurance for staffs. The company commits to support staffs for any procedures regarding these insurances. In addition, other insurance policies are taken into consideration and under review.

    OTHER BENEFITS

    Support budget for activities related to education, entertainment and sports. Support fee for purchasing technical books. Support fee for getting engineering or language certificates. Support fee for joining courses regarding technical management. Other supports following company's policy, etc.

    © 2012 RiverCrane Vietnam. All rights reserved.

    Close