# is gRPC Better than REST

## 4 types of gRPC

* Unary
* Client Streaming
* Server Streaming
* BiDirectional Streaming

![](https://4184784299-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdF90Xe9F63MiAMEQ6k%2F-MdH37yQ5Ejr56BWJp_u%2F-MdH3tKppsZ_g4R-P9BT%2FScreenshot%20from%202021-06-28%2017-03-52.png?alt=media\&token=7ec2ef3a-df3f-431f-8cb5-17c8e91ba337)

## gRPC vs REST

| Feature         | GRPC                        | REST                          |
| --------------- | --------------------------- | ----------------------------- |
| Protocol        | HTTP/2 (fast)               | HTTP/1.1 (slow)               |
| Payload         | Protobuf ( binary, small )  | JSON (text , large)           |
| API Contract    | Strict, required (.proto)   | Loose, optional (OpenAPI)     |
| Code Generation | Built-in (protoc)           | Third-party tools (Swagger)   |
| Security        | TLS/SSL                     | TLS/SSL                       |
| Streaming       | Bidirectional Streaming     | Client -> server request only |
| Browser Support | Limited ( require gRPC-web) | Yes                           |

## Where gRPC is well Suited to

* Microservices
  * Low latency and high throughput communication
  * Strong API contract
* Polygot environments
  * code generation yang memsupport banyaka bahasa pemrograman
* Point-to-Point realtime communication
  * Support yang sangat baik untuk BiDirectional Streaming
* Network constrained environments
  * format message yang ringan
