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?"
- 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
- Ask to connect. Before any data moves, the browser opens a TCP connection by sending SYN: "can we talk?"
- Agree, then confirm. The server replies SYN-ACK, "yes, let's", and the browser confirms with ACK: one round trip, about 50 ms.
- Now the request. Only now does GET / travel to the server, and the page comes back: a second round trip.
- A new connection each time. If each of 3 requests opens its own connection, the handshakes double the trips: 6 round trips, 300 ms.
- Keep it open. Keep-alive leaves the connection open after the answer, so the next request skips the handshake.
- Reuse saves trips. On one reused connection, the same 3 requests take 4 round trips: 200 ms, not 300 ms.
- 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
- TCP opens a connection with a handshake, which costs one round trip before any data moves.
- With HTTPS, setting up the secret key usually adds one or two more round trips to each new connection.
- Keep-alive reuses one connection for many requests, so only the first request pays for the handshake.
- HTTP/2 goes further: many requests share one connection at the same time, not one after another.
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. (The rules most internet traffic uses to deliver data in order, sending again any piece that gets lost.) carries the bytes and resends any that get lost, so they arrive in order with no gaps. (Transport Layer Security: the encryption behind the S in HTTPS. It hides the data on its way and lets the browser check it reached the real server.) encrypts them. (The rules an app or browser uses to ask a server for something and get an answer, such as GET /profile/42 and then 200 OK.) gives them meaning: a request such as GET /users/42, and a response with a (A three-digit number in every HTTP answer that says how the request went: 200 means OK, 404 means not found, 500 means a server error.). (A simple way to send data over the internet with no delivery check. UDP itself does not resend a lost piece, so it is quick. DNS and video calls use it.) is a lighter choice than TCP. It sends each (A small piece of data sent across a network. A big message is cut into many packets.) 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 (The first short messages two machines swap to set up a connection, before any real data moves.). 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 (A small value that a site asks the browser to keep, and to send back with every request to that site.) or a token.
Try it
See it working
Also try: WebSockets & heartbeats
Mechanics
How it works
Before a browser can send a request over (HTTP with every message scrambled by a secret key, after the server proves who it is with a certificate a trusted authority signed.), it sets up a connection in two steps. The pictures follow one request, GET /users/42, from a browser to a shop's server.
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.
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.
HTTP request and response
Pick a case to follow belowWith this case: User 42 exists, so the server answered 200 OK with the user as JSON in the body.
Browser, the client Browser the client Shop server, speaks HTTPS, NOW Shop server speaks HTTPS read /users/42 NOW Database, holds the users Database holds 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 3Step 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 pathGET /users/42Status code–not sent yetStep 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.
Keep the connection open
Pick a case to follow belowWith this case: A new connection took 3 round trips, about 150 ms: one for TCP, one for TLS, one for the request.
Browser, the client Browser the client Shop server, speaks HTTPS, NOW Shop server speaks HTTPS got SYN NOW Database, holds the users Database holds 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 6Step 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 far25msRound trips050 ms eachStep 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 (Leaving a connection open after a request, so the next request can use it without a new handshake.). 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 (A content delivery network: many servers around the world that keep copies of files close to the people who ask for them.) 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. (The Domain Name System: the way the internet turns a name, such as example.com, into the address of a server.) 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
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 laptop — healthy
- Café Wi-Fi — healthy
- Bank server — bank.example — healthy
- Someone on the Wi-Fi — healthy — GET /balance?account=1234
- Plain HTTP is readable. With plain HTTP, anyone on the café Wi-Fi can read the request, word for word.
- Check the certificate. With HTTPS, the server sends a certificate, signed by a trusted authority, which the laptop checks.
- Agree on a secret key. In the HTTPS handshake, both sides agree on a secret key, without ever sending the key itself.
- Scrambled on the way. Every request is then scrambled with that key, so the person on the Wi-Fi sees only noise.
- What still shows. They can still see which site you visit, when, and roughly how much data moves, but not what.
- 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
- Plain HTTP travels as readable text, so anyone on the same network can read it.
- A trusted authority signs the server's certificate, and the laptop checks it before trusting the site.
- Both sides agree on a secret key without ever sending the key itself.
- 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
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 way to carry web traffic, built on UDP. It adds its own delivery checks and encryption. HTTP/3 runs on it, and it connects in fewer round trips than TCP with TLS.), 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?
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
Apply it
Judge a design
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.
- StandardRFC 9110: HTTP SemanticsIETFThe exact meaning of methods, status codes and headers, including which methods are safe to retry.
- StandardRFC 9293: Transmission Control Protocol (TCP)IETFThe current TCP standard: the handshake, ordered delivery and resending lost data.
- StandardRFC 9000: QUICIETFThe transport under HTTP/3, built on UDP, which avoids one lost packet stalling every stream.