Skip to content

Latest commit

 

History

History
90 lines (58 loc) · 1.64 KB

README.md

File metadata and controls

90 lines (58 loc) · 1.64 KB

Golang gRPC demo


Why?

In a REST or GraphQL architecture we have Client sending request Server giving response

But this process is

  • Slow
  • Synchronous
  • Not Scalable

How?

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

1. Unary API

  • Regular request-response

2. Server Streaming

  • Client sends a request to server

  • Server sends a stream of data to client

3. Client Streaming

  • Client sends a stream of data to server

  • Server provides a simple response to client

4. Bi-Directional Streaming

  • 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


To Run the project

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