In a REST or GraphQL architecture we have Client sending request Server giving response
But this process is
- Slow
- Synchronous
- Not Scalable
How to make the client server intercation Scalable?
For that we use Remote Procedure Calls (RPC)RPC directly calls functions from client to server Instead of JSON, we use protobuf files Here, payload size is small and accelerates communication
- Client Server communication can happen via Streaming (sequences of mesages)
- Stream is continous flow of data
- Its asynchronous
- Extremely scalable
Usecase: MICROSERVICES!, Blockchains
There are mainly 4 types of communications in GRPC
- Regular request-response
-
Client sends a request to server
-
Server sends a stream of data to client
-
Client sends a stream of data to server
-
Server provides a simple response to client
-
Both client and server can communicate via streaming.
-
And they can do this parallely,
-
Not like request response wehre client sneds first and then server gives response - not like this.
-
Its like a two way-traffic
-
Even though its a stream, not a queue, sequence of messages is preserved
Install the dependencies
go mod init grpc-example
go mod tidy
Update the Path
export PATH="$PATH:$(go env GOPATH)/bin"
Run the server
go run server/*.go
Run the client
go run client/*.go
For Go-grpc check Official docs