Search code examples
node.jshttpsslmicroserviceshttp2

HTTP2: Should inner service apis use http2


I'm using a Microservice architecture, where one service calls multiple services at a time with servers on nodejs

I was planning to use HTTP2 for API calls from one service to another, as it makes use of just one TCP connection with header compression.

However, HTTP2 needs TLS support, which implies a TLS handshake for every API call made by service to others, adding overhead roundtrips.

Although TLS1.3 takes only one round trip, still it adds up some extra overhead time.

My question is, Is it a good idea to use HTTP2 in the first place for API calls from one service to another, or it's better to continue with HTTP1.1


Solution

  • HTTP2 most likely won't be more performant than ordinary HTTP1.1. It's only faster when you compare them in the context of HTTPS and parallel requests. HTTP2 allows to re-use the same TLS handshake, as well as use the same connection for multiple parallel requests (multiplex).

    This is the reason you wouldn't set up HTTP2 between nginx and your app server - as you usually don't need TLS between them. So unless a) you need a secure connection between your services and b) you're planning to issue parallel requests - it doesn't seem to make sense to use HTTP2 for service-to-service communication.

    PS: also read the answer by @sbordet - there seem to be use cases when HTTP2 can be beneficial even without TLS.