简体   繁体   中英

How is gRPC used to enhance Microservice interaction in PHP?

I'm studying gRPC and noticed they assist in building quality microservice interactions.

Currently I use RESTful requests to interact between services with typical tools like Guzzle etc.

How does gRPC improve the way Microservices would interact with each-other?

gRPC offers several benefits over REST (and also some tradeoffs).

The three primary benefits are:

  1. Protocol Buffers are efficient. Because both sides already have the protobuf definitions, only the data needs to be transferred, not the structure. In contrast, for some JSON payloads, the names of the fields can make the payload significantly larger than just the data. Also, protobuf has a very compact representation "on the wire". Finally, you don't have the overhead of the HTTP headers for every request. (Again, for some smaller requests, the headers could be significantly larger than the request body itself.)

  2. gRPC can be bidirectional. gRPC services can have "streams" of data which can go both directions. HTTP must always have a request and response matched together.

  3. gRPC tries to make you think about version compatibility. Protocol Buffers are specifically designed to help you make sure you maintain backwards compatibility as your data structures change. If done properly, this can make future upgrades easier to implement.


With all those upsides, why not use gRPC for everything?

In my view, the main downside of gRPC is that it requires more tooling. Just about any programming language can handle HTTP and there are many debugging tools, but for gRPC you have to compile your .proto files for each language and share them. There also aren't as many testing tools.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM