By the end of this chapter you'll be able to…

  • 1Characterise a protocol by its message set, its initiator, and the state it retains
  • 2Explain why DNS uses UDP and bulk transfer protocols use TCP
  • 3Describe the DNS hierarchy and the difference between iterative and recursive queries
  • 4Identify the common DNS record types and their purposes
  • 5Count the messages in a cold and a warm DNS resolution
  • 6Compute page load time under non-persistent, parallel, persistent and pipelined HTTP
  • 7Explain how cookies add state without making HTTP stateful, and what statelessness buys
  • 8Describe conditional GET and say what it actually saves
  • 9Explain FTP's two-connection design and why active mode fails behind NAT
  • 10Explain why email needs SMTP for transfer and POP3 or IMAP for retrieval
💡
Why this chapter matters in GATE
Every application protocol answers what messages exist, who speaks first and what state survives between messages, and DNS, HTTP, SMTP and FTP are four different answers. GATE tests DNS resolution message counts, persistent versus non-persistent HTTP round trips, the FTP two-connection design, and why email needs both a push and a pull protocol.

Before you start — revise these

🔗
TCP connection setup costing one round trip
🔗
UDP as a connectionless datagram service
🔗
NAT and why it blocks unsolicited inbound connections

Application Layer Protocols

Above the transport layer, protocols are designed rather than derived, and the design space is small enough to characterise.

The organising fact is that every application protocol answers three questions: what messages exist, who speaks first, and what state is kept between messages.

DNS, HTTP, SMTP and FTP are four different answers. HTTP keeps no state and the client always speaks first. SMTP pushes rather than pulls. FTP keeps a control connection open across many transfers. DNS caches aggressively because its data changes rarely.

The second organising fact is that a protocol's transport choice follows from its message pattern. DNS uses UDP because a query and a reply each fit in one datagram and a handshake would triple the cost. Everything that transfers bulk data uses TCP.

The third is that statelessness is a deliberate scalability decision, not an oversight. HTTP servers can be replaced, load-balanced and restarted between any two requests precisely because no request depends on the last, and cookies exist to add back exactly as much state as an application needs.

1. Architectures

The client-server model has a always-on server at a known address and clients that initiate. It is simple, and the server is a bottleneck and a single point of failure.

Peer-to-peer has no always-on infrastructure, with peers serving each other directly. It scales with participation, because each new peer brings capacity as well as demand.

A hybrid uses a server for lookup and peers for transfer, which is how most practical file-sharing systems work.

The distribution time argument makes the difference concrete. Under client-server, the time to deliver a file to clients grows linearly with , because the server's upload capacity is divided among them.

Under peer-to-peer it grows far more slowly, since every peer that finishes becomes an additional source, so aggregate capacity rises with the number of participants rather than staying fixed.

2. DNS

DNS translates names to addresses, using a distributed hierarchical database with no single server holding everything.

The hierarchy has three tiers. Root servers know the top-level domain servers. Top-level domain servers know authoritative servers for each domain. Authoritative servers hold the actual records.

A local or recursive resolver does the work on a host's behalf and is the component that caches.

RecordPurpose
AName to IPv4 address
AAAAName to IPv6 address
NSName of an authoritative server for a zone
CNAMEAlias to another name
MXMail exchanger for a domain, with a preference
PTRAddress to name, for reverse lookup
SOAZone parameters including timers

An iterative query returns a referral: the server answers with the next server to ask rather than resolving it itself.

A recursive query asks the server to obtain the final answer, which is what a host asks its local resolver and what resolvers generally refuse to do for strangers.

Queries between servers are iterative in practice, which keeps load off the root.

Caching is what makes DNS work at all. Each record carries a time to live, and a cached entry answers immediately without any network traffic, which is why the root servers handle a manageable load despite naming the whole internet.

DNS uses UDP on port 53, falling back to TCP for responses exceeding the datagram limit and for zone transfers.

3. HTTP

HTTP is a request-response protocol over TCP, on port 80 or 443 with TLS.

It is stateless: the server retains nothing between requests.

Methods include GET to retrieve, POST to submit, PUT to store, DELETE to remove, and HEAD to fetch headers alone.

Status codes fall into five classes: 1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error. The ones worth knowing are 200, 301, 304, 400, 401, 403, 404 and 500.

HTTP/1.0 used a non-persistent connection per object, so each object cost a fresh TCP handshake.

HTTP/1.1 made connections persistent by default, reusing one connection for many objects, and added pipelining, which sends requests without waiting for replies.

Head-of-line blocking limits pipelining, since responses must return in order, and that limitation is what HTTP/2's multiplexed streams were designed to remove.

Cookies add state to a stateless protocol. The server sends a Set-Cookie header, the browser returns it on subsequent requests, and the server keys its own stored state on the value.

Conditional GET avoids re-transferring unchanged content. The client sends If-Modified-Since with its cached copy's date, and the server replies 304 Not Modified with no body if nothing changed.

A web cache or proxy serves requests on behalf of many clients, reducing both response time and upstream traffic, and uses conditional GET to stay fresh.

HTTP/2 and HTTP/3

HTTP/2 keeps the same semantics and changes the encoding. Methods, status codes and headers are unchanged; what differs is that the connection carries many interleaved streams and headers are compressed.

Multiplexing removes application-level head-of-line blocking, since a slow response no longer holds up the ones behind it on the same connection.

But TCP's own head-of-line blocking remains, because a single lost segment stalls delivery of every stream sharing that connection.

HTTP/3 solves that by moving to QUIC over UDP, where each stream is independently ordered, so a loss affecting one stream leaves the others untouched. It also folds the cryptographic handshake into the transport handshake, cutting a round trip from connection setup.

4. Electronic Mail

Three components exist: user agents, mail servers, and the protocols between them.

SMTP transfers mail between servers, on port 25, and it is a push protocol: the sending server connects to the receiving one and pushes.

SMTP is a persistent, command-response protocol using 7-bit ASCII, which is why anything else must be encoded.

MIME extends it with headers declaring content type and encoding, so images and non-English text travel as base64 or quoted-printable text.

Retrieval is a separate problem, because a recipient's machine is not always on and cannot receive a push.

POP3, on port 110, downloads and typically deletes. It is simple, stateless between sessions, and awkward across multiple devices, since messages live wherever they were downloaded.

IMAP, on port 143, keeps messages on the server with folders and server-side state, so every device sees the same mailbox. It is more complex and is what almost everything uses now.

HTTP-based webmail replaces the retrieval protocol entirely while still using SMTP between servers.

5. FTP

FTP uses two TCP connections, which is its defining and most examined feature.

The control connection on port 21 stays open for the whole session, carrying commands and replies.

A separate data connection carries each file transfer and is opened and closed per transfer.

This is called out-of-band control, and it contrasts with HTTP, which sends commands and data over one connection.

In active mode the server opens the data connection back to the client from port 20, which fails whenever the client is behind NAT or a firewall, since the inbound connection has nothing to match.

In passive mode the server listens and the client connects, which works through NAT and is now the default.

FTP maintains state across commands, including the current directory and transfer mode, which is why it needs the persistent control connection at all.

6. Worked Examples

Example 1. A host with a cold cache resolves www.example.co.in using iterative queries between servers. Count the messages.

The host sends a recursive query to its local resolver. That is 1 message.

The resolver queries a root server, which does not know the answer but returns a referral to the .in top-level domain servers. That is 2 more, a query and a reply.

The resolver queries the .in server, receiving a referral to the co.in servers. 2 more.

The resolver queries the co.in server, receiving a referral to example.co.in's authoritative servers. 2 more.

The resolver queries the authoritative server, which returns the A record. 2 more.

The resolver replies to the host. 1 more.

Total is messages, of which 8 are between servers.

Now repeat with a warm cache. If the resolver has cached the .in and co.in referrals, it queries only the authoritative server, giving messages.

If the A record itself is cached and unexpired, the answer costs 1 query and 1 reply, with no network traffic beyond the resolver.

That reduction from 10 to 2 is why DNS scales. The root servers would be unable to handle the internet's query volume without it, and record time to live values are chosen precisely to balance freshness against this load.

Example 2. A web page has a base HTML file and 8 embedded objects, all on one server. The round-trip time is 100 milliseconds and transmission time is negligible. Compare non-persistent HTTP with persistent HTTP.

Non-persistent HTTP opens a fresh TCP connection per object.

Each object costs 2 round trips: one for the TCP handshake and one for the request and response.

There are 9 objects in total, the base file plus 8.

But the base file must be fetched first, since its content names the others, so the fetches are sequential in that respect.

Total is milliseconds.

With 5 parallel connections, the 8 objects need 2 batches, so the cost is 2 round trips for the base plus 2 batches at 2 round trips each, giving round trips, or 600 milliseconds.

Persistent HTTP opens one connection and reuses it.

The handshake costs 2 round trips once, one for the TCP handshake and one for the first request and response of the base file.

Each subsequent object costs 1 round trip if requests are sent one at a time.

Total is round trips, which is 1000 milliseconds.

With pipelining, all 8 requests go out together, so they cost 1 round trip in total, giving round trips, or 300 milliseconds.

The ranking is instructive. Persistent with pipelining beats parallel non-persistent, and both crush plain non-persistent, which is exactly why HTTP/1.1 made persistence the default.

Example 3. Explain how cookies add state to a stateless protocol, and state what statelessness buys.

HTTP itself retains nothing between requests. Two requests from the same browser are, to the protocol, entirely unrelated.

On the first response, the server includes a Set-Cookie header carrying an identifier it has generated.

The browser stores it and returns it in a Cookie header on every subsequent request to that domain.

The server keeps the real state in its own database, keyed by that identifier.

So the state is not in the protocol. The cookie is only a key, and the protocol remains stateless in the sense that matters.

What statelessness buys is operational freedom. Any server in a pool can handle any request, since none depends on what a particular machine remembers, so servers can be added, removed or restarted between requests with no disruption.

The moment session state lives in server memory, that freedom is lost, which is why sticky sessions are considered a design problem and why session data is pushed into a shared store or into a signed cookie.

The privacy cost is the third-party cookie, where an identifier set by an advertising domain embedded in many sites lets that domain link a user's activity across all of them.

Example 4. Why does FTP use two connections, and what breaks when the client is behind NAT?

The control connection carries commands and replies for the whole session and stays open.

A separate data connection carries each transfer and closes when it completes.

The benefit is that control remains responsive during a transfer, so an abort command can be sent and acted on while a large file is in flight, which a single connection could not do without message framing.

The cost appears with NAT. In active mode, the client tells the server which port to connect to, and the server opens the data connection inbound.

A NAT device has no table entry for that inbound connection, since the client never sent anything from that port, so the connection attempt is dropped.

A firewall rejects it for the same reason, since it looks like an unsolicited inbound connection.

Passive mode inverts the direction. The server listens on a port, tells the client which one, and the client connects outbound.

Now NAT creates the table entry naturally, because the client initiated, and the transfer works.

A second NAT problem is specific to FTP's design. The port command carries an IP address inside the payload as text, and that address is the client's private one, which the server cannot reach.

Fixing it requires NAT to inspect and rewrite the payload, which is exactly the kind of protocol-specific special handling that layering was supposed to avoid.

Example 5. Why does email need both SMTP and IMAP rather than one protocol?

SMTP is a push protocol. The sending server opens a connection to the receiving server and pushes the message.

That works between servers because both are always on, with known addresses and mail exchanger records naming them.

It cannot work for the final delivery to a person. A laptop is off, asleep, behind NAT, and on a changing address, so no sending server could ever push to it.

So the message stops at the recipient's mail server, and retrieval must be a pull.

A pull is a fundamentally different interaction, initiated by the recipient at an arbitrary later time, so it needs its own protocol.

POP3 pulls by downloading and usually deleting, treating the server as a temporary holding area.

IMAP pulls by synchronising, leaving messages and folder structure on the server so several devices see one consistent mailbox.

The general principle is worth stating. Push suits always-on infrastructure with stable addresses, and pull suits intermittently connected clients, and no single protocol serves both well.

Example 6. A proxy cache holds a copy of a page fetched at 10:00. A client requests it at 10:30. Describe the exchange and its cost.

The cache checks whether its copy is still fresh by comparing the elapsed time against the response's cache-control or expiry headers.

If the copy is fresh, the cache returns it immediately with no upstream traffic at all, and the cost is one local round trip.

If it may be stale, the cache sends a conditional GET to the origin server with an If-Modified-Since header naming 10:00.

If nothing changed, the server replies 304 Not Modified with no body. The cache serves its stored copy.

The saving is the body, not the round trip. The upstream exchange still happens, so latency improves only slightly, while bandwidth improves enormously for large objects.

If the content did change, the server replies 200 with the full body, and the cache stores and forwards it.

The general effect of caching is to reduce upstream traffic and average latency, with the hit rate determined by how much content is shared between users and how aggressively time to live values are set.

Summary

Every application protocol answers what messages exist, who speaks first, and what state survives between messages, and the transport choice follows from the message pattern.

DNS is a hierarchical distributed database over UDP port 53, with root, top-level domain and authoritative tiers. Queries between servers are iterative; a host's query to its resolver is recursive. Caching with time to live values is what makes the system scale, cutting a ten-message cold resolution to two.

Records to know are A, AAAA, NS, CNAME, MX, PTR and SOA.

HTTP is stateless over TCP. Non-persistent connections cost two round trips per object; persistent connections cost two for the first and one per object thereafter; pipelining collapses the remainder into one. Head-of-line blocking limits pipelining, which HTTP/2 addressed with multiplexed streams.

Cookies add state without making the protocol stateful, and statelessness is what lets any server in a pool handle any request.

Conditional GET returns 304 with no body, saving bandwidth rather than round trips.

SMTP pushes mail between always-on servers using 7-bit ASCII, with MIME encoding everything else. Final delivery must be a pull, since a client machine is intermittently connected, which is why POP3 or IMAP exists. POP3 downloads and deletes; IMAP synchronises server-side folders.

FTP separates a persistent control connection on port 21 from a per-transfer data connection, giving out-of-band control. Active mode fails behind NAT because the server initiates inbound; passive mode inverts the direction and works. FTP also embeds an address in its payload, forcing NAT devices into protocol-specific rewriting.

HTTP/2 keeps HTTP's semantics and changes the encoding, multiplexing streams over one connection and compressing headers, which removes application-level head-of-line blocking but not TCP's. HTTP/3 removes that too by running over QUIC, where streams are independently ordered and the cryptographic handshake is folded into the transport handshake.

Key formulas & results

Everything to memorise for the exam hall, in one card. Screenshot this for revision.

The organising principle
what messages exist, who speaks first, what state survives
Answering these three characterises any application protocol, and the transport choice follows from the message pattern.
DNS cold resolution cost
1 recursive query plus 2 messages per referral level plus 1 reply
A four-level name from a cold cache costs about 10 messages; a fully cached answer costs 2.
Non-persistent HTTP cost
2 round trips per object: one for the TCP handshake, one for request and response
Nine objects cost 18 round trips serially, or fewer with parallel connections.
Persistent HTTP cost
2 round trips for the first object, then 1 per object; with pipelining, 1 for all remaining
Nine objects cost 10 round trips without pipelining and 3 with it.
Conditional GET
If-Modified-Since produces 304 Not Modified with no body when unchanged
It saves bandwidth, not round trips, since the upstream exchange still occurs.
DNS record types
A, AAAA, NS, CNAME, MX, PTR, SOA
Address, IPv6 address, name server, alias, mail exchanger, reverse pointer, and zone parameters.
Well-known ports
DNS 53, FTP control 21 and data 20, SMTP 25, POP3 110, IMAP 143, HTTP 80, HTTPS 443
FTP is the only one in this list using two ports, which is its defining structural feature.
Push versus pull
push suits always-on infrastructure with stable addresses; pull suits intermittently connected clients
SMTP pushes between servers; POP3 or IMAP pulls to a laptop that may be off, asleep or behind NAT.
FTP mode rule
active mode has the server connect inbound and fails behind NAT; passive mode has the client connect outbound and works
NAT creates a table entry only for connections the inside host initiates.
Peer-to-peer scaling
client-server distribution time grows linearly with the number of clients; peer-to-peer grows far more slowly
Each finished peer becomes an additional source, so capacity rises with participation rather than staying fixed.
⚠️

Traps GATE sets — and how to dodge them

These are the exact option-traps and misreads that cost marks under negative marking.

WATCH OUT
Saying DNS servers query each other recursively
The host's query to its resolver is recursive; the resolver's queries to root, TLD and authoritative servers are iterative, receiving referrals. That is what keeps load off the root.
Why it happens: Recursion is what the host asks for, so it seems to describe the whole process.
WATCH OUT
Counting one round trip per object under non-persistent HTTP
Each new connection costs a TCP handshake round trip before the request, so it is two round trips per object.
Why it happens: The request and response are the visible exchange, so the handshake is forgotten.
WATCH OUT
Claiming cookies make HTTP stateful
The cookie is only a key; the state lives in the server's own store. The protocol still carries no state between requests, which is why any server in a pool can handle any request.
Why it happens: State clearly persists across requests once cookies are in use.
WATCH OUT
Saying conditional GET saves a round trip
The request still goes upstream and a 304 still comes back. What is saved is the response body, which matters enormously for large objects and not at all for small ones.
Why it happens: It is described as avoiding a transfer, which sounds like avoiding the exchange.
WATCH OUT
Describing FTP as using one connection with two ports for redundancy
There are genuinely two TCP connections: a control connection lasting the session and a data connection per transfer. That separation is what keeps control responsive during a large transfer.
Why it happens: The two port numbers are memorised without the reason for them.
WATCH OUT
Attributing FTP's NAT problem only to the port command
There are two problems. Active mode requires an inbound connection NAT cannot match, and separately the port command carries a private address. Passive mode solves the first; payload rewriting is needed for the second.
Why it happens: The embedded address is the more striking detail.
WATCH OUT
Suggesting SMTP could deliver mail directly to a laptop
SMTP pushes, and a laptop may be off, asleep or behind NAT with a changing address. Delivery stops at the recipient's server, and retrieval must be a client-initiated pull.
Why it happens: SMTP is described as the mail transfer protocol, so it seems to cover the whole path.
WATCH OUT
Assuming HTTP/2 eliminated head-of-line blocking entirely
It removes application-level blocking but not TCP's, since one lost segment still stalls every stream on that connection. HTTP/3 over QUIC removes the remainder by ordering streams independently.
Why it happens: Multiplexing is presented precisely as the fix for it.

Exam-pattern practice

PYQ-style questions with full solutions. Work through them as a readiness check — mark yourself honestly and get your gap report at the end.

Readiness check

Are you exam-ready for Application Layer Protocols: DNS, SMTP, HTTP, FTP & Email?

10 problems from this chapter. Try each one, reveal the worked solution, mark yourself honestly — get your gap report at the end.

10 questions~7 min

5-minute revision

The whole chapter, distilled. Read this the night before the exam.

  • Characterise a protocol by its messages, its initiator and its retained state
  • Transport choice follows the message pattern: DNS uses UDP, bulk transfer uses TCP
  • DNS hierarchy: root, top-level domain, authoritative, plus a caching local resolver
  • Host to resolver is recursive; resolver to servers is iterative
  • Records: A, AAAA, NS, CNAME, MX, PTR, SOA
  • Caching cuts a ten-message cold resolution to two
  • HTTP is stateless over TCP, port 80 or 443
  • Non-persistent costs 2 round trips per object; persistent costs 2 then 1 each; pipelining collapses the rest to 1
  • Head-of-line blocking limits pipelining; HTTP/2 multiplexes; HTTP/3 over QUIC removes TCP's version
  • Cookies are keys, not state; statelessness lets any server handle any request
  • Conditional GET saves the body, not the round trip
  • SMTP pushes between servers on port 25 using 7-bit ASCII; MIME encodes everything else
  • Final delivery must be a pull: POP3 downloads and deletes, IMAP synchronises server-side folders
  • FTP has a persistent control connection on 21 and a per-transfer data connection, which is out-of-band control
  • Active mode fails behind NAT; passive mode inverts the direction and works
  • FTP's port command embeds a private address, forcing NAT payload rewriting
  • Peer-to-peer distribution time grows far more slowly than client-server because finished peers become sources

GATE question blueprint

How this topic is asked, tier by tier — so you can prep to the pattern.

Typical weightage: 5

Question styleMarks eachTypical countWhat it tests
HTTP21
DNS11
Email protocols11
FTP11

Exam-hall strategy

Battle-tested tips from mentors and toppers for this topic under the sectional clock.

  1. For DNS message counting, draw the chain of servers and count two messages per referral, then add one query and one reply for the host, and state your caching assumption explicitly since the answer depends on it. For HTTP timing, decide first whether connections are persistent and whether requests are pipelined, then count round trips rather than working in milliseconds until the end. Remember that the base HTML must be fetched before the embedded objects are known. When a question asks why a design choice was made, name the failure it prevents: NAT for FTP passive mode, intermittent connectivity for IMAP, and server-pool flexibility for statelessness.

Beyond the exam

Where this skill shows up in the job you're competing for — and in life.

DNS caching behaviour determines how long a service migra…

DNS caching behaviour determines how long a service migration takes to complete, which is why operators lower time to live values days in advance of a cutover

Content delivery networks are built on DNS returning diff…

Content delivery networks are built on DNS returning different answers by client location, turning name resolution into a load-balancing mechanism

The shift to HTTP/2 and HTTP/3 was driven by exactly the …

The shift to HTTP/2 and HTTP/3 was driven by exactly the round-trip arithmetic in this chapter, since page load time is dominated by round trips rather than by bandwidth

Third-party cookies are being phased out by browsers beca…

Third-party cookies are being phased out by browsers because the same mechanism that provides sessions also enables cross-site tracking

SPF

SPF, DKIM and DMARC exist because SMTP was designed with no authentication at all, so any server could claim to send as any domain

Where else this topic is tested

Prepare once, score in every exam that asks it.

GATE CS
GATE DA
UGC NET Computer Science
ISRO Scientist SC
BARC Computer Science

Questions aspirants ask

Pulled from the Q&A community and mentor sessions.

Because the common case is still a small query and a small reply, and paying a TCP handshake for every name lookup would add a round trip to the start of every connection. The extension mechanism raised the practical UDP response limit, and TCP remains available as a fallback, so the cheap path stays cheap.

Almost never in practice. Responses must return in request order, so one slow response blocks everything behind it, and buggy intermediaries handled pipelined requests badly enough that browsers disabled it. HTTP/2's multiplexing achieves the intended benefit without the ordering constraint, which is why pipelining is now a historical answer rather than a deployed one.

Because it predates NAT by two decades and was already universal when the problems appeared, and passive mode addressed the worst of them. It is now largely displaced by HTTP for downloads and SFTP for authenticated transfer, both of which use a single connection and avoid the whole class of problem.

By trading freshness against load and latency. A long value means fewer queries and faster lookups but a slow propagation when the address changes, which is why operators shorten it deliberately in the days before a planned migration and lengthen it again afterwards.

It means the protocol carries no state between requests, not that the application cannot store anything. The application keeps whatever it needs in a database keyed by a cookie value. The distinction matters operationally: state in a shared store lets any server handle any request, while state in one server's memory does not.

Because SMTP itself was specified for 7-bit ASCII and the installed base of servers assumes it. MIME also does more than encoding: its content type headers tell the recipient how to interpret each part, which is what makes attachments and multipart messages possible at all.
Header Logo