简体   繁体   中英

Why does nestjs framework use a transport layer different than HTTP in a microservices approach?

If you look a the OSI model, HTTP is part of Layer 7 (Application). TCP is Layer 4 (Transport).

When looking at Layer 4 there is no determining characteristic that makes it HTTP, AMPQ, gRPC, or RTSP. Layer 4 is explicitly how data is transmitted and received with the remote device.


Now, this is where networking and the software development worlds collide. Networking people will use "transport" meaning Layer 4, while Programming people use "transport" meaning the way a packet of data is transmitted to another component.

The meaning of "transport" (or "transporter" as used in the docs) is used as an abstraction from how messages are shared in this architecture.

Looking at the documentation if you are looking for something like AMPQ for your microservice you can use NATS or REDIS (both implementations are built by them).

https://docs.nestjs.com/microservices/basics#getting-started

OSI 层

The main reason is it is slow. The problem with HTTP approach is that, with HTTP, JSON can generate an unwanted processing time to send and translate the information.

This is an expensive process and imagine serialization for a big data.

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 is very slow. There are some optimization techniques and those are complex and does not add significant performance benefits

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