SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

How to avoid TLS handshake latency on Profiles API?

Question

How to avoid TLS handshake latency on Profiles API?

 

Product

Twilio Segment

 

Environment

Segment Console

 

Answer

Segment's Profiles API has a connection idle timeout of 60 seconds and utilizes TLS 1.2. If a connection is dropped due to inactivity, a full TLS handshake is required to re-establish it. This handshake can add 400ms+ of latency to the first request sent after a connection has timed out.

 

To avoid this overhead, we recommend one of the following optimization strategies:

 

Option 1: Adjust Client-Side Keep-Alive Timeout (~30s-40s)

If your application’s keep-alive timeout is higher than Segment's (60s), our load balancer will terminate the connection first. This often results in your client attempting to use a "dead" connection, leading to a retry or a forced handshake.

  • Action: Set your client-side keep-alive timeout to a value lower than ours (we recommend starting around 30s-40s).

  • Result: This allows your server to gracefully close and recycle the connection on its own terms, preventing unexpected termination by the Segment load balancer.

 

Option 2: Implement a "Heartbeat" or Proactive Polling (every 20s-30s)

For use cases requiring the absolute lowest possible latency for every request, you can prevent the connection from ever idling out.

  • Action: Send a "dummy" or lightweight request (a heartbeat) every 20–30 seconds.

  • Result: This keeps the TCP/TLS connection "warm" and active, ensuring the pipe stays open so that production requests never encounter the 400ms handshake penalty.

 

Have more questions? Submit a request
Powered by Zendesk