- Microservice Patterns and Best Practices
- Vinicius Feitosa Pacheco
- 394字
- 2021-06-30 19:02:55
Tools for synchronous communication
The most common form of direct communication between microservices is using the HTTP protocol with Rest and passing JavaScript Object Notation, the famous JSON. Communication works great for APIs, providing endpoints for external consumption. However, communication using HTTP with JSON has a high cost in relation to performance.
First, this is because in the case of communication between microservices, it would be more appropriate to optimize than the HTTP protocol creating some sort of pipeline or keeping the connection alive. The problem is the control of the connection timeout, which shouldn't be very strict, and in addition could start to close doors, threads, or processes with a simple silent error. The second problem with this approach is the serialization time of JSON sent. Normally this is not an inexpensive process. Finally, we have the packet size sent to the HTTP protocol. In addition to JSON, there are a number of HTTP headers that should be interpreted further which may be discarded. Look closer; there's no need to elaborate on protocols between microservices, the only concern should be to maintain a single layer for sending and receiving messages. Therefore, the HTTP protocol with JSON to communicate between microservices can be a serious slow point within the project and, despite the practicality of implementation of the protocol, the optimization is complex to understand yet not very significant.
Many would propose the implementation of communication sockets or WebSockets but, in the end, the customization process of these communication layers is very similar to the classic HTTP.
Synchronous communication layers between microservices must complete three basic tasks:
- Report practice and direct the desired messages
- Send simple, lightweight packages and fast serialization
- Be practical to maintain the signature of communication endpoints
A proposal that meets the aforementioned requirements communicates using binary or small-size packages.
Something important to point out when it comes to working with this type of protocol is that, usually, they are incompatible with each other. This means that the option chosen as the tool for serialization and submission of these small-sized packages should be compatible with the stack of all microservices.
Some of the most popular options on the market are:
- MessagePack (http://msgpack.org/)
- gRPC (https://grpc.io/)
- Apache Avro (https://avro.apache.org/)
- Apache Thrift (https://thrift.apache.org/)
Let us understand how each of these options works to see what best fits on our news portal.
- Truffle Quick Start Guide
- Web Application Development with R Using Shiny
- 物聯網信息安全
- 互聯網基礎資源技術與應用發展態勢(2021—2023)
- 射頻通信系統
- 網絡環境中基于用戶視角的信息質量評價研究
- 網絡安全應急響應技術實戰指南
- React Cookbook
- AIoT應用開發與實踐
- LwIP應用開發實戰指南:基于STM32
- 物聯網與智慧農業
- Hands-On Reactive Programming in Spring 5
- Architecting Data:Intensive Applications
- 走近2050:注意力、互聯網與人工智能
- 智慧的物聯網:感知中國和世界的技術