Application Layer Fundamentals

Application Layer Overview

The application layer is the highest layer of the OSI reference model. It provides network services directly to users and is the interface through which users interact with the network.


1. The Core Role of the Application Layer

1.1 Serving Users Directly: The “Front Desk” of the Network

User services

The application layer faces the user directly and provides the various networked application services. It works like the waiter in a restaurant: the customer does not need to know how the kitchen operates.

The Role of the Application Layer

The restaurant analogy:

LayerRestaurant analogyNetwork layerFunction
Application layerThe waiterApplication layerServes the customer or user directly
Transport layerThe kitchen runnerTransport layerCarries the dishes or the data
Network layerThe purchasing departmentNetwork layerTransports the ingredients or routes the packets
Link layerThe supplierLink layerProvides the ingredients or the transmission medium
Physical layerThe delivery vehiclePhysical layerPhysical transport or signal transmission

Users only ever deal with the application layer:

  • Users: browse pages, send mail, download files
  • Application layer: provides the interface and the function for those services
  • Lower layers: support it behind the scenes, and the user never has to care

The Types of Service the Application Layer Provides

1. File services

Like borrowing and returning books at a library:

  • 📁 File transfer: uploading and downloading files (FTP)
  • 📂 File sharing: sharing files among many people (cloud drives)
  • 📄 File synchronisation: keeping files in step across devices (Dropbox)

2. Communication services

Like the post office and the telephone:

  • 📧 Electronic mail: sending and receiving mail (SMTP, POP3)
  • 💬 Instant messaging: real-time chat (WeChat, QQ)
  • 📞 Video conferencing: remote meetings (Zoom, Tencent Meeting)

3. Information lookup

Like a library catalogue:

  • 🌐 Web browsing: visiting sites (HTTP)
  • 🔍 Search engines: searching for information (Baidu, Google)
  • 📊 Database queries: looking up data (SQL)

4. Remote services

Like a remote control:

  • 🖥️ Remote login: accessing a computer remotely (SSH)
  • 🎮 Remote control: operating a device remotely (RDP)
  • 🔧 Remote management: administering servers remotely

2. The Two Models of Networked Applications

2.1 The Client/Server Model (C/S)

The client/server model

The C/S model (Client/Server) is a centralised model for networked applications in which the client actively requests a service and the server passively provides it. It works like a restaurant: the customer (the client) orders, the cook (the server) prepares the food.

How the C/S Model Works

The restaurant ordering analogy:

The customer (the client): reads the menu (learns what is on offer) → orders (issues the request) → waits (waits for the response) → eats (uses the service).

The cook (the server): takes the order (receives the request) → cooks (processes the request) → serves the dish (returns the result) → waits for the next order (waits for a new request).

The C/S model in the network:

The client (the active side): a browser visiting a site, a mail client sending and receiving mail, a file client uploading and downloading — it initiates requests.

The server (the passive side): a web server serving pages, a mail server processing mail, a file server storing files — it responds to requests.

Characteristics of the C/S Model

1. A clear structure

Like a restaurant with clearly divided roles:

RoleResponsibilityNetwork role
The customerOrders and eatsThe client: requests the service
The waiterTakes the order and serves itThe application layer: processes the request
The cookCooks the foodThe server: provides the service

2. Centralised management

Like a restaurant managed under one roof:

  • The server manages all the resources centrally (files, data, services)
  • The client does not have to manage resources
  • The server controls access rights (who may access what)

3. Easy maintenance

Like a restaurant that is simple to maintain:

  • Only the server has to be maintained (upgraded, repaired, optimised)
  • The client needs no maintenance (the user simply uses it)
  • Problems are easy to locate (they are on the server)

4. Good security

Like a restaurant with controlled access:

  • The server controls access rights
  • A single security policy applies
  • Monitoring and auditing are straightforward

Typical Applications of the C/S Model

The Advantages and Disadvantages of the C/S Model

Advantages:

✅ Centralised management: resources are stored centrally and are easy to manage ✅ A clear structure: the responsibilities of the client and the server are explicit ✅ Easy maintenance: only the server side has to be maintained ✅ Good security: the server controls access in one place ✅ Predictable performance: the server’s performance determines the quality of service

Disadvantages:

❌ Limited scalability: the server’s performance caps the performance of the whole system ❌ A single point of failure: if the server fails, every client is affected ❌ Higher cost: powerful server hardware is required ❌ Dependence on the server: the client depends entirely on the server


2.2 The Peer-to-Peer Model (P2P)

The P2P model

The P2P model (Peer-to-Peer) is a distributed model for networked applications in which every node is both a client and a server, and the nodes talk to each other directly. It works like a circle of friends: everyone is a sharer (a server) and a viewer (a client) at the same time.

How the P2P Model Works

The circle of friends analogy:

Each person (each node): publishes content (serving as a server), reads content (acting as a client), and forwards content (being both server and client). There is no central platform; the nodes share directly with one another.

P2P in the network: node A serves file 1 (acting as a server) and downloads file 2 (acting as a client); node B serves file 2 and downloads file 1. The nodes talk to each other directly, with no central server involved.

Characteristics of the P2P Model

1. Peers are equal

Like friends in a circle, who are all on equal terms:

  • Every node has the same standing
  • Every node is both a client and a server
  • There is no master/slave relationship

2. Distribution

Like content that is spread across everyone in the circle:

  • Resources are spread across all the nodes
  • There is no central server
  • Every node contributes part of the resources

3. Strong scalability

Like a circle that livens up as more people join:

  • More nodes means more resources
  • More nodes means faster downloads
  • Performance is not limited by any single node

4. Good fault tolerance

Like a circle where the others are still visible when one person is away:

  • The failure of a single node does not affect the whole
  • Resources have multiple copies
  • The system switches to other nodes automatically

Typical Applications of the P2P Model

The Advantages and Disadvantages of the P2P Model

Advantages:

✅ Strong scalability: the more nodes there are, the more capable the service is ✅ Good fault tolerance: the failure of a single node does not affect the whole ✅ Low cost: no expensive central server is needed ✅ Abundant resources: the resources contributed by the nodes pool together ✅ Fast downloads: several nodes are downloaded from in parallel

Disadvantages:

❌ Complex management: with no centre, management is difficult ❌ A security challenge: the nodes are autonomous, so a single security policy is hard to enforce ❌ Copyright problems: file sharing may infringe copyright ❌ Uncertain reliability: it depends on the quality of each node ❌ Hard to control: there is no central server in control


2.3 C/S Compared with P2P

FeatureThe C/S modelThe P2P modelAnalogy
StructureCentralisedDistributedThe restaurant against the circle of friends
Central nodeThere is a serverThere is no centreThe cook against everyone
Where resources liveOn the serverSpread across the nodesThe kitchen against each person’s own home
ScalabilityLimited by the serverGrows with the number of nodesLimited by the kitchen, versus the better it gets the more people join
ReliabilityDepends on the serverFault tolerantThe cook falling ill affects the restaurant, versus one person being absent not affecting the circle
Management difficultyEasy to manageHard to manageRunning a kitchen against a circle that needs no management
SecurityEasy to controlHard to controlKitchen hygiene under control against hygiene that differs from home to home
CostHigh (a server)Low (no centre)The cost of building a kitchen against not building one
Typical useConventional servicesPeer sharingOrdering a dish against sharing

How to choose:

When to use the C/S model: when resources need centralised management, a uniform security policy, and a reliable quality of service, and when the resources and the user base are relatively stable.

When to use the P2P model: when resources are spread across many nodes, when scalability and fault tolerance matter, and when the user base is large and dynamic and the budget limited.


3. Application Layer Protocols: The “Rules” of Communication

3.1 What an Application Layer Protocol Is

Application layer protocol

An application layer protocol defines the rules and the formats of communication at the application layer, like the menu and the service procedure of a restaurant.

The Role of a Protocol

The restaurant specification analogy:

Restaurant specificationApplication layer protocolFunction
The format of the menuThe data formatDefines how the data is organised
The ordering procedureThe request formatDefines how a request is issued
The serving procedureThe response formatDefines how a response is returned
The service procedureThe communication procedureDefines the steps of the exchange

What a protocol contains:

  1. Data format: how the data is organised (JSON, XML, HTML)
  2. Request format: how a request is issued (GET, POST)
  3. Response format: how a response is returned (status codes, data)
  4. Error handling: what happens when something goes wrong (error codes, retries)
  5. State management: how session state is managed (cookies, sessions)

3.2 Common Application Layer Protocols

File Transfer Protocols

FTP (File Transfer Protocol)

Like sending and receiving parcels by courier:

FunctionAnalogyWhat the protocol does
Upload a filePosting a parcelThe client uploads to the server
Download a fileCollecting a parcelThe client downloads from the server
Manage filesTidying the parcelsCreating, deleting, and moving files
Access controlChecking identityVerifying the user’s permissions

Characteristics:

  • Ports: 20 (data), 21 (control)
  • Supports anonymous access and authenticated access
  • Supports listing, uploading, downloading, and deleting files

HTTP (Hypertext Transfer Protocol)

Like borrowing a book from a library:

FunctionAnalogyWhat the protocol does
GETBorrowing a bookRetrieves the content of a page
POSTReturning a book with a filled-in formSubmits data to the server
PUTUpdating the record of a bookUpdates the resource
DELETECancelling the loanDeletes the resource

Characteristics:

  • Ports: 80 (HTTP), 443 (HTTPS)
  • A stateless protocol (every request is independent)
  • Supports several request methods

Mail Protocols

SMTP (Simple Mail Transfer Protocol)

Like posting a letter at the post office:

Sender
Sender's Post Office
Recipient's Post Office
Recipient

What SMTP is responsible for:

  1. Sender → the sender’s post office (the mail is submitted)
  2. The sender’s post office → the recipient’s post office (the mail is carried)

Characteristics:

  • Port: 25
  • Responsible for sending mail
  • Push model (the mail is pushed out)

POP3 (Post Office Protocol)

Like going to the post office to collect your letters:

Recipient
Collecting Mail at the Post Office
Home

What POP3 is responsible for: the recipient collects the mail at the post office and keeps it locally after downloading it.

Characteristics:

  • Port: 110
  • Responsible for receiving mail
  • Pull model (the mail is fetched actively)
  • Delete after download (optional)

IMAP (Internet Message Access Protocol)

Like reading your letters at the post office:

Recipient
Reading Mail at the Post Office
Leaves It There
Reads It Repeatedly

What IMAP is responsible for: the recipient reads the mail at the post office without downloading it; the mail stays on the server.

Characteristics:

  • Port: 143
  • Responsible for receiving mail
  • The mail stays on the server
  • Supports access from several devices

Name Resolution Protocols

DNS (Domain Name System)

Like a telephone directory:

Scenario: you want to call Zhang San but you do not have the number.

The lookup process:

  1. You check the address book (the local DNS cache)
  2. You do not find it, so you ask directory enquiries (the DNS server)
  3. The directory gives you the number: 13800138000
  4. You make the call (visit the site)

DNS resolution:

  1. Query the IP address of www.baidu.com
  2. DNS returns: 202.108.22.5
  3. Visit the site using the IP address

Characteristics:

  • Port: 53
  • UDP (fast lookups)
  • A distributed database (servers at several levels)
  • Caching (fewer queries)

Remote Service Protocols

SSH (Secure Shell)

Like a remote control:

Scenario: you are at home and you want to control the office computer remotely.

The SSH connection:

  1. Your computer (the client)
  2. Connect over SSH to the office computer (the server)
  3. Work as if you were sitting in front of it
  4. The traffic is encrypted, so it cannot be eavesdropped

Characteristics:

  • Port: 22
  • Encrypted communication (secure)
  • Supports remote login
  • Supports file transfer (SCP)

Telnet

Like a remote control, in the insecure version:

Telnet is similar to SSH but without encryption: it provides remote login over plaintext, which is insecure, and it is rarely used today.

Characteristics:

  • Port: 23
  • No encryption (insecure)
  • A historical protocol
  • Superseded by SSH

3.3 The Relationship Between Protocols and Ports


4. Worked Examples

Example 1: The Full Process of Visiting a Website

Let us look at the full process of visiting a website from the point of view of the application layer:

What the user does:

  1. Opens the browser
  2. Types the address www.baidu.com
  3. Presses Enter

Application layer (the HTTP protocol):

  1. The browser builds the HTTP request: GET / HTTP/1.1, Host: www.baidu.com, User-Agent: Chrome
  2. DNS resolution: the browser looks up www.baidu.com → 202.108.22.5

Transport layer (TCP):

  1. The TCP connection is established (the three-way handshake): browser port 54321 → server port 80

Network layer (IP):

  1. IP routing: client IP → server IP (202.108.22.5)

The server:

  1. Receives the HTTP request
  2. Processes the request (querying the database, generating the page)
  3. Builds the HTTP response: HTTP/1.1 200 OK, Content-Type: text/html, body <html>...</html>

The data returns:

  1. HTTP response → TCP transport → IP routing → back to the client

The browser:

  1. Parses the HTML
  2. Renders the page
  3. Displays it to the user

Example 2: The Process of Sending Mail

What the user does:

  1. Opens the mail client (Outlook)
  2. Writes the message: recipient friend@example.com
  3. Clicks send

Application layer (the SMTP protocol):

  1. The mail client builds the SMTP commands: MAIL FROM: you@example.com, RCPT TO: friend@example.com, DATA: <the body of the message>

Transport layer (TCP):

  1. Connects to the SMTP server (port 25)

Network layer (IP):

  1. Routes to the mail server

The mail server:

  1. Receives the message
  2. Looks up the location of the recipient’s mailbox
  3. Forwards the message to the recipient’s mail server

The recipient’s mail server:

  1. Receives the message
  2. Stores it in the recipient’s mailbox

The recipient reads the mail:

  1. Opens the mail client
  2. Connects to the POP3 server (port 110)
  3. Downloads the mail
  4. Displays the content

Example 3: A P2P File Download

What the user does:

  1. Opens the BitTorrent client
  2. Adds the torrent file
  3. Starts the download

The P2P process:

  1. The torrent file is parsed and the file information is obtained: the name movie.mp4, the size 1GB, divided into 1000 pieces, and the list of peers A, B, C, D…
  2. Several peers are connected to: peer A has pieces 1-100, peer B has pieces 101-200, peer C has pieces 201-300, peer D has pieces 301-400
  3. Parallel download: the pieces are downloaded from peers A/B/C/D at the same time, which is fast
  4. Uploading at the same time: once you have downloaded pieces 1-100, other peers need them and you upload them — you are both a client and a server
  5. The download finishes: all the pieces are downloaded, combined into the complete file, and you go on uploading to the other peers

Exercises

Exercise 1

How do the C/S model and the P2P model differ, and what scenarios suit each of them?

client/server modelp2p modelnetwork applications

Approach

Compare the two models along the axes that decide which one to use: structure, where resources live, the roles of the nodes, scalability, and reliability. Then map each to its scenarios.

Steps

  1. Compare the structural characteristics.
  2. Compare where resources are stored.
  3. Compare the roles of the nodes.
  4. Compare scalability.
  5. Compare reliability.
  6. List the scenarios for C/S and then for P2P.

Answer

The main differences are:

  1. Structure:

    • C/S: centralised, with a central server
    • P2P: distributed, with no central node
  2. Where resources are stored:

    • C/S: the resources are concentrated on the server
    • P2P: the resources are spread across the nodes
  3. The roles of the nodes:

    • C/S: the roles of client and server are distinct
    • P2P: every node is both a client and a server
  4. Scalability:

    • C/S: limited by the performance of the server
    • P2P: grows as the number of nodes grows
  5. Reliability:

    • C/S: depends on the server, so a single point of failure has a large effect
    • P2P: fault tolerant, so the failure of one node has a small effect

Where C/S suits:

  • Web browsing: the pages are concentrated on the server
  • Mail services: the mail is concentrated on the mail server
  • File services: the files are concentrated on the file server
  • Database services: the data is concentrated on the database server

Characteristic: the resources are centralised and need unified management, with a stable user base.

Where P2P suits:

  • File sharing: the files are spread across many nodes
  • Instant messaging: the nodes talk directly to one another
  • Blockchain: decentralised applications
  • Distributed computing: the work is spread across many nodes

Characteristic: the resources are dispersed and high scalability is needed, with a dynamic user base.

Exercise 2

What is the role of an application layer protocol? Give some common examples.

application layer protocolsprotocol designport numbers

Approach

State the role as the definition of the rules of communication, list the five things a protocol has to specify, and then give a concrete protocol from each family with its port.

Steps

  1. State the role of an application layer protocol.
  2. List the five things a protocol specifies.
  3. Give the file transfer protocols.
  4. Give the mail protocols.
  5. Give the name resolution protocol.
  6. Give the remote service protocols.

Answer

The role of an application layer protocol:

An application layer protocol defines the rules and the formats of communication at the application layer, like the service specification of a restaurant:

  1. Data format: defines how the data is organised
  2. Request format: defines how a request is issued
  3. Response format: defines how a response is returned
  4. Error handling: defines what happens when something goes wrong
  5. State management: defines how the session is managed

Common protocol examples:

File transfer protocols:

  • FTP: file upload and download (ports 21/20)
  • HTTP: web browsing (port 80)
  • HTTPS: secure web browsing (port 443)

Mail protocols:

  • SMTP: sending mail (port 25)
  • POP3: receiving mail (port 110)
  • IMAP: mail access (port 143)

Name resolution:

  • DNS: name resolution (port 53, UDP)

Remote services:

  • SSH: secure remote login (port 22)
  • Telnet: remote login (port 23)

What every protocol has in common:

  • It uses a specific port
  • It defines a data format
  • It defines a communication procedure
  • It defines error handling

Exercise 3

What is the role of the DNS protocol? Describe the DNS resolution process.

dnsname resolutiondomain name system

Approach

State the role of DNS, then walk down the hierarchy from the client to the root, the top-level, and the authoritative servers, and finally describe the return path.

Steps

  1. State the role of the DNS protocol.
  2. Describe the local cache lookup.
  3. Describe the local DNS server lookup.
  4. Describe the root server lookup.
  5. Describe the top-level domain server lookup.
  6. Describe the authoritative server lookup.
  7. Describe the return of the result.

Answer

The role of the DNS protocol:

DNS (the Domain Name System) resolves domain names into IP addresses, in the same way a telephone directory turns a name into a number.

The DNS resolution process:

Scenario: the user visits www.baidu.com

  1. The local cache lookup:

    • The browser checks the local cache
    • If there is a cached entry, it is used directly
    • If not, the lookup continues
  2. The local DNS server lookup:

    • The browser queries the local DNS server
    • The local DNS server checks its cache
    • If there is a cached entry, the IP address is returned
    • If not, the lookup continues
  3. The root DNS server lookup:

    • The local DNS server queries a root server
    • The root server returns the addresses of the top-level domain servers
  4. The top-level domain server lookup:

    • The local DNS server queries a top-level domain server
    • It returns the address of the authoritative server
  5. The authoritative server lookup:

    • The local DNS server queries the authoritative server
    • The authoritative server returns the IP address: 202.108.22.5
  6. The result is returned:

    • The local DNS server returns the IP address to the browser
    • The browser caches the result
    • The site is visited using the IP address

The analogy:

Like looking up a telephone number:

  • First check the address book (the local cache)
  • If it is not there, ask directory enquiries (the DNS server)
  • The directory looks up the number and returns it
  • Dial the number (visit the site)

Exercise 4

How do HTTP and FTP differ, and what scenarios suit each of them?

httpftpapplication layer protocols

Approach

Compare them on the dimensions that matter in practice — purpose, ports, connection model, data types, how they are driven, and security — and then map each to its scenarios.

Steps

  1. Compare the purpose.
  2. Compare the ports.
  3. Compare the connection model.
  4. Compare the data types.
  5. Compare the way operations are expressed.
  6. Compare security.
  7. State the selection rule.

Answer

The main differences are:

  1. Purpose:

    • HTTP: web browsing, retrieving the content of pages
    • FTP: file transfer, uploading and downloading files
  2. Ports:

    • HTTP: port 80 (443 for HTTPS)
    • FTP: port 21 (control), 20 (data)
  3. Connection model:

    • HTTP: short-lived connections, closed once the request and response are done
    • FTP: persistent connections, with the session state maintained
  4. Data types:

    • HTTP: mainly carries web content such as HTML and images
    • FTP: carries files of any type
  5. How operations are expressed:

    • HTTP: request methods such as GET and POST
    • FTP: commands such as upload, download, delete, and list
  6. Security:

    • HTTP: plaintext (encrypted by HTTPS)
    • FTP: plaintext (encrypted by SFTP)

Where HTTP suits:

  • Web browsing: visiting sites
  • API calls: calling web services
  • Form submission: submitting data
  • Content retrieval: fetching pages, images, and so on

Where FTP suits:

  • Large file transfers: uploading and downloading big files
  • File management: creating, deleting, and moving files
  • Site maintenance: uploading the files of a site to a server
  • Backup and restore: backing files up to a remote server

How to decide:

  • If you need to browse pages → use HTTP
  • If you need to transfer files → use FTP
  • If you need to manage files → use FTP
  • If you need to retrieve content quickly → use HTTP

Found an issue with this content?

Tell us what could be improved.