Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
02

Frontend System Design · Lesson 2 of 86 · 3 min

TCP and TLS Handshakes: Connection Setup Costs

This is about the round-trip latency you pay before your app's first byte of data can even be sent.

How a TCP connection is established

Before your browser can send an HTTP request, it needs a reliable connection to the server. TCP, the Transmission Control Protocol, provides this reliability. It uses a three-step process called the 3-way handshake.

  1. SYN: The client sends a "synchronize" packet to the server to initiate a connection.
  2. SYN-ACK: The server acknowledges the client's packet and sends its own synchronize packet back.
  3. ACK: The client acknowledges the server's packet. The connection is now open.

This exchange ensures both client and server are ready to communicate. The key cost is that it takes one full round-trip time (RTT) before any application data (like your GET request) can be sent.

In an interview, framing this as a "one round-trip tax" for reliability shows you understand the performance implications. It's the first component of Time To First Byte (TTFB).

How a secure connection is established

After the TCP connection is open, you need to secure it for HTTPS. This is done with a TLS (Transport Layer Security) handshake. Its job is to authenticate the server, agree on encryption algorithms, and generate a shared secret key.

A full TLS 1.2 handshake is a chatty process. The client says hello and lists the encryption methods (cipher suites) it supports. The server picks one, sends back its public certificate to prove its identity, and then they exchange key information to create a shared secret.

This negotiation adds two more round trips on top of the initial TCP handshake. Your first request to a new https:// domain now costs 1 RTT (TCP) + 2 RTTs (TLS 1.2) before the HTTP request is even sent.

The trap: Forgetting that TLS adds its own latency. Candidates often describe the TCP handshake cost but miss the much larger cost of the initial TLS negotiation. This total setup time can easily be hundreds of milliseconds on a mobile network.

How TLS 1.3 speeds things up

TLS 1.3, now widely adopted, is a major improvement. It streamlines the handshake process, reducing the cost from two round trips down to one. The client sends its parameters and immediately guesses which key agreement protocol the server will use, saving a full RTT.

Now, the total cost for a new connection is 1 RTT (TCP) + 1 RTT (TLS 1.3). This is a significant reduction in initial connection latency.

TLS 1.3 also supports a "zero round trip" (0-RTT) mode for resuming previous sessions. If you've connected to a server recently, the client can send encrypted application data in its very first message. This is powerful but has security trade-offs, as these 0-RTT requests are vulnerable to replay attacks.

How this appears in your code and tools

You don't write code to perform these handshakes. The browser or Node.js runtime handles them automatically whenever you initiate a secure network request.

When you call fetch, the time spent on these handshakes happens before your request for /items is ever sent over the wire. This is the "Initial connection" or "SSL" phase you see in your browser's network timing tab.

async function getItems() {
  try {
    // Before this HTTP GET request is sent, the browser performs:
    // 1. TCP 3-way handshake (1 RTT)
    // 2. TLS handshake (1-2 RTTs)
    const response = await fetch('https://api.example.com/items');

    if (!response.ok) {
      throw new Error(`HTTP error! Status: ${response.status}`);
    }
    const data = await response.json();
    console.log('Data received:', data);
    return data;
  } catch (error) {
    console.error('Failed to fetch data:', error);
  }
}

getItems();

The latency is most noticeable on the very first request to a domain. Subsequent requests can often reuse the existing warm connection, avoiding the handshake penalty entirely.

Try it

Open your browser's DevTools to the Network tab. Check "Disable cache" and load a website you haven't visited recently, like https://www.fastly.com. Click the first HTML document request and view the "Timing" tab. See the time spent on "Initial connection" and "TLS setup." That's the cost, right there.

Next: We'll look at how browsers manage these connections to avoid paying this setup cost over and over in the "Browser Network Stack and Connection Pooling" lesson.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)

Next

Browser Network Stack and Connection Pooling