Background Context
We use protocols for a communication between the client and server.
Think about it like this:
- API is a set of functions, endpoints and tools defining what data is moving and why.
- Protocols set rules for how the data is exchanged and moved.
- Protocols enable APIs to work. The foundation of APIs are protocols.
- Finally, just understand that protocols operate at a lower level of abstraction than APIs.
If you've ever created an API, chances are that you have used the RESTful protocol. REST stands for "Representational State Transfer" - and is implemented over HTTP/1.1 and HTTP/2 using the classic methods like PUT, POST, GET and DELETE. RESTful protocols are super common in software engineering, and we typically send and receive payloads in JSON format. Super simple and easy to use.
gRPC
gRPC is a "newer" protocol per say, that is implemented over HTTP/2. It stands for "Google Remote Procedure Call". Instead of operating off an endpoint paradigm, it operates like functions. Streaming is built natively into the protocol, and you don't need to use WebSockets with your API to persist a connection. The data format is also protocol buffers, more popularly known as protobuf, which Google developed to serialize structured data. The protobuf compiler will essentially create code to serialize and deserialize your data, and it exists as a binary string that improves performance when processing or moving over a network or even being stored. Serialization also just simply means converting to a transmittable format.
The most common use cases for gRPC are microservice communication in distributed infrastructure and real-time data streaming. It is highly performant and interoperable due to the .proto file that specifies configurations for the protobuf compiler code generation which supports a huge range of languages.
One thing I did also observe is that gRPC does not list rust as a supported language. But there is a rust implementation of gRPC in Rust called tonic that has been growing in popularity (https://docs.rs/tonic/latest/tonic/).