It's kind of like a sibling to REST API or GraphQL, enabling communication with the server in a unique way. RPC stands for Remote Procedure Call, and the "g" in gRPC stands for Google, as it was created by Google.
Let's understand it now:
Suppose there are two machines—one is the client (any machine) and the other is the server (another machine). In the end, when we call an API, it executes a function on the server. With RPC, instead of making a traditional API request, the client can directly call a function on the server. Below is the architecture diagram, and we will discuss each terminology in detail.
In REST APIs, data is transferred in JSON format, but in gRPC, it happens using Protocol Buffers (Protobuf), which is an IDL (Interface Definition Language). To use gRPC, we need HTTP/2.
Just like REST APIs send serialized data over the network, gRPC also transmits protocol-serialized data. However, gRPC maintains a single long-lived connection and supports bidirectional streaming.
So, referring to the screenshot above, once an HTTP/2 request is made using gRPC, bidirectional data flow happens. Each time we call a server function, a bidirectional data flow occurs, and the connection ends after the response.
We already discussed that gRPC uses Protocol Buffers (Protobuf) instead of JSON. Now, let’s understand Protocol Buffers and how encoding and decoding take place.
Protocol Buffer (ProtoBuf) is developed by Google.
.json()
, in gRPC, we use .proto
(also called proto3).Honestly, this concept is a bit confusing, but we’ll explore it further to understand it better.
gRPC is mainly used for server-to-server communication, but we will also see how to use it in a browser. Since a browser acts as a client machine, we need a gRPC client that interacts with a gRPC server to call functions.
Here is the repo link: gRPC-first-setup
You can either clone the repo or follow the documentation to set up the client and server. If you haven’t used gRPC before, it might feel a bit complex at first, but at least try it once, as I did. Something is better than nothing 🙂
✅ 10x faster compared to REST API calls
✅ Better security since it uses HTTP/2
✅ Bidirectional streaming support
✅ Automatic code generation
✅ Language-agnostic (Define proto once and use it in any language)
✅ Service discovery support
✅ More secure communication
❌ Not human-readable (Uses binary data instead of JSON)
❌ Limited browser support
❌ No edge caching (Due to the use of POST requests)
❌ Steeper learning curve compared to REST APIs
Hey your feedback is required for me , please give this repo a star 🌟 if you liked the blog if you want to contribute in it please feel free to fork , You can see github link on top right corner of top bar or click here
Thank you so much for reading. If you found it valuable, consider subscribing for more such content every week. If you have any questions or suggestions, please email me your comments or feel free to improve it.
I am waiting for your feedback, See you in next episode,
Thanks 👋🏻
I'm Rahul, Sr. Software Engineer (SDE II) and passionate content creator. Sharing my expertise in software development to assist learners.
More about me