Stage 1 · Foundations · Easy · 12 min

HTTP, TCP, UDP and connections

How data moves between a browser and a server. Compare TCP with UDP, and see what HTTP/1.1 keep-alive, HTTP/2 and HTTP/3 over QUIC each change.

What each interview level is expected to know

Learn first: The client–server model

After this lesson you can:

  • Explain what TCP and UDP each guarantee, and when each is the better choice.
  • Count the round trips that the TCP and TLS handshakes add before the first byte.
  • Say what keep-alive, HTTP/2 and HTTP/3 each fix, including head-of-line blocking.

Start here

See it in 60 seconds

Why reusing a connection is faster

Every new connection costs a handshake round trip before any data moves, so reusing one connection makes a page of many requests much faster.

Scene 1 of 6 · Ask to connect

Before any data moves, the browser opens a TCP connection by sending SYN: "can we talk?"

BrowserBrowserWeb serverWeb server
  • Browser — healthy
  • Web server — healthy
Waiting so far
not shown yet
Total, new connection each time
not shown yet
Total, one reused connection
not shown yet
  1. Ask to connect. Before any data moves, the browser opens a TCP connection by sending SYN: "can we talk?"
  2. Agree, then confirm. The server replies SYN-ACK, "yes, let's", and the browser confirms with ACK: one round trip, about 50 ms.
  3. Now the request. Only now does GET / travel to the server, and the page comes back: a second round trip.
  4. A new connection each time. If each of 3 requests opens its own connection, the handshakes double the trips: 6 round trips, 300 ms.
  5. Keep it open. Keep-alive leaves the connection open after the answer, so the next request skips the handshake.
  6. Reuse saves trips. On one reused connection, the same 3 requests take 4 round trips: 200 ms, not 300 ms.
  7. Now you try. A page needs several requests, sent one after another. How many? For example: 10 requests: new connections take 20 round trips (1,000 ms); one reused connection takes 11 (550 ms). Reuse pays the handshake once instead of 10 times, which saves 450 ms on this page.

Scene 1 of 6: Ask to connect. Before any data moves, the browser opens a TCP connection by sending SYN: "can we talk?"

Key points

  1. TCP opens a connection with a handshake, which costs one round trip before any data moves.
  2. With HTTPS, setting up the secret key usually adds one or two more round trips to each new connection.
  3. Keep-alive reuses one connection for many requests, so only the first request pays for the handshake.
  4. HTTP/2 goes further: many requests share one connection at the same time, not one after another.

Go deeper in the Request flow lab →

In plain words

A protocol is an agreed set of rules for how two computers talk. When you open a web page, three of them work in layers. carries the bytes and resends any that get lost, so they arrive in order with no gaps. encrypts them. gives them meaning: a request such as GET /users/42, and a response with a . is a lighter choice than TCP. It sends each once and does not wait to hear that it arrived. A packet may be lost, arrive out of order or arrive twice, so an app that needs more must add it itself.

Opening https://shop.example.com runs those layers in order. First the browser and the server set up a TCP connection with a short . Then TLS checks the site's certificate and agrees on keys to encrypt with. Only then does the browser send its HTTP request, such as GET /cart. Video calls and games often pick UDP instead, because a late packet is no use, and waiting for a resend only adds delay.

The problem it solves

A network can lose packets or deliver them out of order. A web page or a payment needs every byte, so it accepts a short wait while lost data is resent. A video call cannot wait: a packet that arrives late is useless. So there are two kinds of transport, and each app picks the one that fits.

Why it matters

Every request in a design crosses the network on one of these protocols. Your choice decides how long a connection takes to open, what happens to lost data, and whether one slow request holds up others.

A worked example

Suppose one round trip takes 50 ms, and a page needs 6 images. Over a single HTTP/1.1 connection, only one request travels at a time, so fetching the 6 images in turn takes about 6 × 50 = 300 ms. HTTP/2 can multiplex all 6 requests over that same one connection at once, so the wait is close to 50 ms instead.

Think of it like…

Think of a form at a service counter. You fill in what you want and hand it over. You get back a slip with a code that says what happened.

Where this analogy stops working

A fixed form and a fixed list of reply codes is the useful part. But a clerk remembers you while you stand there. HTTP does not: each request is handled alone. The server knows you only if the request carries a or a token.

Try it

See it working

Guided walkthroughOpen the full lab →

Lab · Foundations

Request flow

Follow one request for a product page, part by part: DNS, a CDN edge near the user, and on a miss the origin far away. Pick which copies exist, then step forward and back and watch the time add up.

Try it

Where the address is known

The resolver answers from its copy: about 20 ms.

The CDN edge
The cache at the origin

With these settings: Answered by the database after 248 ms. The trip to the origin and back took 200 of those ms, so a CDN copy would have saved the most.

Browser, in PuneBrowserin Punewaiting for addressDNS resolver, name to address, NOWDNS resolvername to addressNOWCDN edge, in MumbaiCDN edgein MumbaiLoad balancer, origin, VirginiaLoad balancerorigin, VirginiaAPI gateway, checks each callAPI gatewaychecks each callProduct service, builds the answerProduct servicebuilds the answerCache, RedisCacheRedisDatabase, PostgreSQLDatabasePostgreSQL
  • Browser — in Pune — healthy — waiting for address
  • DNS resolver — name to address — healthy — NOW
  • CDN edge — in Mumbai — healthy
  • Load balancer — origin, Virginia — healthy
  • API gateway — checks each call — healthy
  • Product service — builds the answer — healthy
  • Cache — Redis — healthy
  • Database — PostgreSQL — healthy
  • Request
  • Answer
  • Miss: sent on
  • Read
  • Nothing found
  • Save a copy
Step 1 of 15

Step 1 of 15 · DNS resolver

Done: The browser asks DNS for the address

What happens
The browser has a name, shop.example.com, but the network needs an IP address.
Why
Nothing can be sent until the browser knows where to send it.
What changes
The resolver has a saved answer, so it can reply at once.
Next
DNS answers after 20 ms

Event log

14 more to go. Press a line to go back to that step.

Time so far
0ms
Lines crossed
1
Parts that did work
2
Answered by
not yet

Step 1 of 15: DNS resolver. The browser asks DNS for the address. The browser has a name, shop.example.com, but the network needs an IP address.

What this model simplifies
  • Every time here is an example value, not a measurement. The edge is 2 ms away and the origin 100 ms away each way. The cache takes 1 ms and the database 15 ms.
  • The connections are already open, so there is no TCP or TLS handshake to wait for. The HTTP lesson shows what those cost.
  • Each part does one thing at a time, and nothing fails. A real edge may also check with the origin before it serves an old copy.

Also try: WebSockets & heartbeats

Mechanics

How it works

Before a browser can send a request over , it sets up a connection in two steps. The pictures follow one request, GET /users/42, from a browser to a shop's server.

  1. TCP 3-way handshake

    TCP is the protocol that delivers bytes in order and resends any that are lost. Before sending data, the two sides swap three short messages: SYN, SYN-ACK and ACK. That costs one round trip before the first request can go.

  2. TLS handshake

    TLS is the layer that turns HTTP into HTTPS. Client and server agree on a secret key without ever sending it. The server proves who it is with a certificate. After that, someone in between cannot read or change the contents. They can still see which server you talk to and how much data moves.

  3. HTTP request and response

    Pick a case to follow below

    With this case: User 42 exists, so the server answered 200 OK with the user as JSON in the body.

    Browser, the clientBrowserthe clientShop server, speaks HTTPS, NOWShop serverspeaks HTTPSread /users/42NOWDatabase, holds the usersDatabaseholds the users
    • Browser — the client — healthy
    • Shop server — speaks HTTPS — healthy — NOW — read /users/42
    • Database — holds the users — healthy
    • Request
    • Response
    Step 1 of 3

    Step 1 of 3 · Shop server

    Done: The browser sends GET /users/42

    What happens
    The request has a method, GET, a path and headers, such as which formats the browser accepts.
    Why
    GET means "read this". It does not change anything on the server.
    What changes
    The server reads the path and works out what is asked for.
    Next
    The server reads user:42
    Method and path
    GET /users/42
    Status code
    –
    not sent yet

    Step 1 of 3: Shop server. The browser sends GET /users/42. The request has a method, GET, a path and headers, such as which formats the browser accepts.

    The client sends a method, a path and headers: for example GET /users/42. GET reads data and POST creates it. The server answers with a status code, headers and a body. Codes from 200 to 299 mean success, 400 to 499 mean a client mistake, and 500 to 599 mean a server fault.

    Switch between the three cases. User 42 exists, so the answer is 200 OK with the user in the body. User 999 does not exist, so the answer is 404 Not Found.

    When the database is down, the server answers 503 Service Unavailable. The difference matters to the client. Sending the same 4xx request again usually gets the same answer. The exception is 429 Too Many Requests, which means wait and try again. A 5xx request may also work after a wait.

  4. Keep the connection open

    Pick a case to follow below

    With this case: A new connection took 3 round trips, about 150 ms: one for TCP, one for TLS, one for the request.

    Browser, the clientBrowserthe clientShop server, speaks HTTPS, NOWShop serverspeaks HTTPSgot SYNNOWDatabase, holds the usersDatabaseholds the users
    • Browser — the client — healthy
    • Shop server — speaks HTTPS — healthy — NOW — got SYN
    • Database — holds the users — healthy
    • Handshake
    • Request
    • Response
    Step 1 of 6

    Step 1 of 6 · Shop server

    Done: TCP handshake: the browser says hello

    What happens
    There is no connection yet. The browser sends SYN to ask for one.
    Why
    TCP sets up a connection before any data, so it can deliver bytes in order.
    What changes
    The server sets a little memory aside for this connection.
    Next
    The server answers SYN-ACK
    Time so far
    25ms
    Round trips
    0
    50 ms each

    Step 1 of 6: Shop server. TCP handshake: the browser says hello. There is no connection yet. The browser sends SYN to ask for one.

    What these pictures simplify. These pictures use one round example time: 50 ms there and back between the browser and the server. Real times depend on the distance. Newer HTTP/3 runs on QUIC, which joins the two handshakes into one round trip.

    Opening a connection is slow, so the client keeps it open and reuses it. This is called . HTTP/2 goes further and sends many requests at once over one connection.

    In the picture, one round trip takes 50 ms, a round example time. On a new connection, the request waits for TCP, then for TLS 1.3, one round trip each. The answer arrives after about 150 ms.

    On a kept-open connection, the same request takes about 50 ms. The further the server is, the more each round trip costs. That is one reason sites use a close to their users.

Use it when

  • TCP: web pages, payments, file transfers and chat, where every byte must arrive and order matters.
  • UDP: video calls, voice calls and online games, where a late packet is worse than a lost one. lookups use it too, to skip the handshake.

Skip it when

  • TCP for a fast online game: one lost packet holds back everything behind it while it is resent.
  • Plain UDP for data that must all arrive, unless your app adds its own resending and ordering.

Check yourself

What does a 503 status code tell the client?

Also

More in 60 seconds

What HTTPS hides

HTTPS checks that a site is real, agrees on a secret key, and scrambles every request, so people on the same network see only noise.

Scene 1 of 5 · Plain HTTP is readable

With plain HTTP, anyone on the café Wi-Fi can read the request, word for word.

Your laptopYour laptopCafé Wi-FiCafé Wi-FiBank server, bank.exampleBank serverbank.exampleSomeone on the Wi-FiSomeone on the Wi-FiGET /balance?account=1234
  • Your laptop — healthy
  • Café Wi-Fi — healthy
  • Bank server — bank.example — healthy
  • Someone on the Wi-Fi — healthy — GET /balance?account=1234
  1. Plain HTTP is readable. With plain HTTP, anyone on the café Wi-Fi can read the request, word for word.
  2. Check the certificate. With HTTPS, the server sends a certificate, signed by a trusted authority, which the laptop checks.
  3. Agree on a secret key. In the HTTPS handshake, both sides agree on a secret key, without ever sending the key itself.
  4. Scrambled on the way. Every request is then scrambled with that key, so the person on the Wi-Fi sees only noise.
  5. What still shows. They can still see which site you visit, when, and roughly how much data moves, but not what.
  6. Now you try. Pick plain HTTP or HTTPS, and see what someone on the same Wi-Fi reads. For example: Over HTTPS, they see the site name, bank.example, then scrambled noise. Your laptop and the bank hold the key, so nobody reads the request, but your IP address still shows.

Scene 1 of 5: Plain HTTP is readable. With plain HTTP, anyone on the café Wi-Fi can read the request, word for word.

Key points

  1. Plain HTTP travels as readable text, so anyone on the same network can read it.
  2. A trusted authority signs the server's certificate, and the laptop checks it before trusting the site.
  3. Both sides agree on a secret key without ever sending the key itself.
  4. HTTPS hides what you send, but not which site you visit, roughly how much, or when.

Judgement

Trade-offs and how it fails

What you give up

Performance
UDP sends data at once, with no handshake. TCP needs one round trip to connect, and TLS usually adds one or two more before the first request.
Reliability
TCP delivers bytes in order and resends lost ones. UDP makes no promise: packets can be lost, repeated or arrive out of order.

Failure modes

  • Head-of-line blocking: TCP delivers bytes in order, so one lost packet holds back all the data behind it until it is resent.
  • A lost reply: the server does the work, but its response never arrives. The client cannot tell this from a failed request, so sending a POST again can do the work twice.
  • A new connection for every request: a client that does not reuse connections pays the TCP and TLS handshakes each time. Every request is then slower.

In the real world

  • Video-call apps usually send audio and video over UDP, because a late packet is useless, and fall back to TCP when UDP is blocked.
  • Chrome and other major browsers support HTTP/3, which runs on QUIC over UDP and sets up a connection in fewer round trips. Source: Can I use: HTTP/3 (checked 14 October 2026)

Trade-offs to be ready to discuss: Tcp vs udp

Check yourself

A video call loses one packet. Why do most call apps send sound and video over UDP rather than TCP?

Interview

What interviewers look for

  • Know how HTTP/2 and HTTP/3 differ. HTTP/2 sends many requests over one TCP connection. HTTP/3 uses , a newer transport built on UDP, so a lost packet delays only its own request.

Say it out loud: Why does HTTP/3 run on QUIC over UDP instead of TCP?

A page makes 30 small requests to the same server. Why is one HTTP/2 connection faster than a new connection for each request?

Expected depth by interview level

Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.

JuniorExpected
HTTP methods and status codes; TCP vs UDP at a high level.
MidCore
WebSockets vs long polling vs server-sent events for real-time features.
SeniorExpected
Connections at scale: keep-alive, HTTP/2, many idle sockets.
StaffUseful
Protocol choices across a platform.

Practice

Apply it

Three harder questions

The first two use the idea on a new case. The last asks you to judge a design.

Apply it

A round trip to a server takes 100 ms. TCP needs one round trip to connect, and TLS 1.3 one more. On a new connection, about how long until the response to GET /users/42 arrives?

Apply it

A client sends POST /orders with a required field missing. Which kind of status code should the server send back?

Judge a design

A payment client sends POST /payments. No reply comes within 5 seconds, so it sends the same POST again. What is the risk, and what fixes it?

Next: the API styles built on these protocols: REST, WebSockets, Server-Sent Events, gRPC and GraphQL.

Go deeper

Sources and further reading

First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.