satyajitnayk / simple-grpc

A simple gRPC server & client using go lang
MIT License
0 stars 0 forks source link

why `gRPC` over client server model ? #1

Open satyajitnayk opened 9 months ago

satyajitnayk commented 9 months ago

gRPC (gRPC Remote Procedure Calls) is a modern, open-source framework developed by Google that enables efficient and robust communication between distributed systems. It is often compared to traditional HTTP-based client-server communication, and each has its own advantages and use cases. Here are some reasons why one might choose gRPC over traditional HTTP/client-server communication:

  1. Efficiency and Performance:

    • Binary Protocol: gRPC uses a binary serialization format (Protocol Buffers by default), which is more compact and faster to serialize/deserialize compared to JSON used in many HTTP APIs. This results in smaller payload sizes and faster data transmission.
    • Multiplexing: gRPC multiplexes multiple requests and responses over a single connection, reducing the overhead associated with opening multiple connections for parallel requests.
  2. Strong Typing and Code Generation:

    • Protocol Buffers (protobuf): gRPC uses Protocol Buffers for defining the service interface and message formats. This provides strong typing, meaning that the structure of data is explicitly defined, and code can be generated in multiple languages based on these definitions. This reduces the chances of errors and makes the code more maintainable.
  3. Bi-directional Streaming:

    • gRPC supports bidirectional streaming, allowing both the client and server to send a stream of messages to each other. This is useful for scenarios where real-time updates or continuous data streams are needed.
  4. Language Agnostic:

    • gRPC supports multiple programming languages, making it easier for developers to work with their preferred language while still being able to communicate seamlessly between different services.
  5. Service Contract:

    • With Protocol Buffers, gRPC allows for a clear definition of the service contract, including methods, parameters, and return types. This makes it easier to understand and document the API, and also facilitates versioning.
  6. Pluggable and Extensible:

    • gRPC allows for the use of custom authentication, load balancing, and other features through the use of interceptors. This makes it highly extensible and adaptable to various requirements.
  7. Support for HTTP/2:

    • gRPC is built on top of HTTP/2, which brings benefits like header compression, multiplexing, and support for prioritization. This can lead to improved network efficiency compared to HTTP/1.1.

While gRPC has many advantages, it's important to note that the choice between gRPC and traditional HTTP/client-server communication depends on the specific requirements of the project. Factors such as simplicity, ease of debugging, existing infrastructure, and developer familiarity may also play a role in the decision-making process.

satyajitnayk commented 9 months ago

Note:

  1. streaming - continuous flow of data
  2. Asynchronous & fast
  3. Extremely scalable.
  4. Use cases: Microservices & block chain peers interactions.
satyajitnayk commented 9 months ago

1. Unary Communication:

2. Server Streaming:

3. Client Streaming:

4. Bidirectional Streaming: