HTTP Connection Reuse
We recommend creating a persistent connection to Prime endpoint. The persistent connection will have these benefits:
- Reduces the latency at client end. A new HTTPS connection for every request will result in higher latency due to “connection creation time” + SSL handshake negotiation (which results in transfer of SSL certificate of 6 KB).
- It reduces the load at Prime end because the same connection can be reused to serve multiple requests. This requires creation of less HTTP connections.
- More advantages here - https:/ en.wikipedia.org/wiki/HTTP_persistent_connection#Advantages
How do you enable persistent connection?
- Every HTTP client library will have the support for persistent connections. With HTTP/1.0 protocol, the “Connection: keep-alive” header needs to be sent but with HTTP/2.0 protocol, the default is persistent connection. Example of Apache HTTP client with default persistent connections - https://www.baeldung.com/httpclient-connection-management
- We recommend keeping the connection “idle timeout” as 180 seconds. It means that after 180 seconds of inactivity on the connection, the client will close the connection. The above link has the section that specifies the setting of the default idle connection timeout. One more reference is this documentation of Apache HttpClient - https://hc.apache.org/httpcomponents-client-4.5.x/current/tutorial/pdf/httpclient-tutorial.pdf (Search for “Connection keep alive strategy”).
- You should make sure that there is a retry (as specified in the Retry section). It can happen (in an edge case) that client thinks that connection is open but server (Prime host) has closed the connection. In that case, a new request will immediately error out with “connection reset” error. However, the retry will take care of this issue.