Money Forward Developers Blog

株式会社マネーフォワード公式開発者向けブログです。技術や開発手法、イベント登壇などを発信します。サービスに関するご質問は、各サービス窓口までご連絡ください。

20230215130734

How does gRPC work?

What is gRPC?

gRPC is an open-source remote procedure call (RPC) framework created by Google in 2016, but first, what's remote procedure call (RPC) ?

let's start with local procedure call is a function call within a process to execute some code. and remote procedure call (RPC) is the process that enables one machine to invoke some code on another machine as if the local machine call from the user's perspective. gRPC is a popular implementation of RPC.

How gRPC works?

Before explaining how gRPC works? Let's talk about how client-server communication. Nowadays, we mostly use HTTP (HTTP stands for hypertext transfer protocol) for communicate between clients and servers. will focus mainly on HTTP/1.1 which was created in 1997 & the new one is HTTP/2 which was created in 2015. HTTP/1.1 : communicate by textual format HTTP/2 : communicate by binary (A binary is a number expressed in the base-2 numeral system that's means HTTP/2 communicates by this format 110101010101 )

The binary is the primary language for computers, meaning computers communicate by HTTP/2 is liked we talk in our native language, and it’s also telling that communicating by HTTP/2 is faster than HTTP/1.1

This link shows how fast of HTTP/2 compare with HTTP/1.1: http://www.http2demo.io/

This is a result of the comparison between HTTP/2 and HTTP/1.1

By the way, computers need interpreters to interpret the binary code to human language. that’s why gRPC created, gRPC have its interpreter called protobuf. Protobuf is a binary format for message exchange between network services, created by Google with open-source code

Here is how machine communicate with each other by using gPRC protocol.

Trade off

Yes, gRPC is good but this is a new technology so there are not much language support and community support.

  • Since gRPC heavily relies on HTTP/2, you can’t call a gRPC service from a web browser directly, because no modern browsers can access HTTP/2 frames. So, you need to use a proxy, which has its limitations. There are currently two implementations:

  • By compressing data to a binary format, protobuf files become non-human readable, unlike XML and JSON.

When to use gRPC

  • Real-time communication services where you deal with streaming calls
  • When efficient communication is a goal
  • For internal APIs where you don’t have to force technology choices on clients
  • New builds as part of transforming the existing RPC API might not be worth it

Summary

gRPC is a new technology, and gRPC is a good framework for client-server communication because instead of communication by text, gRPC communication uses binary code for client-server communication. By the way, because it's a new technology, so old technology can't support gRPC.


マネーフォワードでは、エンジニアを募集しています。 ご応募お待ちしています。

【会社情報】 ■Wantedly株式会社マネーフォワード福岡開発拠点関西開発拠点(大阪/京都)

【SNS】 ■マネーフォワード公式noteTwitter - 【公式】マネーフォワードTwitter - Money Forward Developersconnpass - マネーフォワードYouTube - Money Forward Developers