OVERVIEW:
Understanding what happens behind the scenes when a URL is hit involves multiple steps and
components in web development. Here's a detailed breakdown of the process:
1. DNS Lookup
When a user enters a URL into the browser, the first step is to translate the human-readable
address (e.g., www.example.com) into an IP address that computers use to identify each other
on the network.
● Browser Cache: The browser first checks its cache to see if it has recently resolved the
URL.
● Operating System Cache: If not found in the browser cache, it checks the OS's cache.
● Router Cache: If still not found, it checks the cache on the router.
● ISP DNS Cache: Next, it queries the DNS server provided by the Internet Service
Provider (ISP).
● Recursive Search: If the ISP's DNS server doesn't have the information, it performs a
recursive search starting from the root DNS servers, moving to top-level domain (TLD)
servers (like .com or .net), and finally to the authoritative DNS server for the domain.
2. TCP/IP Connection
Once the IP address is obtained, the browser initiates a TCP connection to the server.
● Three-Way Handshake:
1. SYN: The browser sends a SYN (synchronize) packet to the server.
2. SYN-ACK: The server responds with a SYN-ACK (synchronize-acknowledge)
packet.
3. ACK: The browser sends an ACK (acknowledge) packet back to the server.
3. SSL/TLS Handshake (if HTTPS)
If the URL uses HTTPS, an additional step is required to establish a secure connection.
● Certificate Exchange: The server sends its SSL certificate to the browser.
● Certificate Validation: The browser validates the certificate against trusted certificate
authorities.
● Key Exchange: Both browser and server agree on encryption keys to use for the
session.
4. HTTP Request
With a connection established, the browser sends an HTTP request to the server.
● HTTP Method: Common methods include GET, POST, PUT, DELETE, etc.
● Headers: Include additional information such as cookies, user-agent, accepted
response formats, etc.
● Body: Present in methods like POST, PUT, containing data to be sent to the server.
5. Server-Side Processing
The server receives the request and processes it. This step involves several sub-steps
depending on the server configuration and application logic.
● Load Balancer (if any): Distributes the incoming request to one of the several servers.
● Web Server: Servers like Apache, Nginx, or IIS handle the incoming request and pass it
to the application server.
● Application Server: Processes the request using server-side scripts written in
languages like PHP, Python, Ruby, Java, etc.
○ Routing: Determines which controller and action to invoke based on the URL
and method.
○ Controller: Executes the business logic, often interacting with a database.
○ Model: Represents the data structure and handles database operations.
○ View: Templates that generate the HTML to be returned to the client.
6. Database Interaction
If the application needs to retrieve or store data, it interacts with the database.
● Query Execution: SQL or NoSQL queries are executed to fetch or update data.
● Data Transformation: Data may be transformed or processed before being sent back to
the controller.
7. Generating the Response
The server constructs an HTTP response.
● Status Code: Indicates the result of the request (e.g., 200 OK, 404 Not Found, 500
Internal Server Error).
● Headers: Include metadata like content type, length, caching policies, etc.
● Body: Contains the requested resource (e.g., HTML, JSON, XML).
8. Sending the Response
The server sends the HTTP response back to the browser over the established TCP
connection.
9. Rendering the Page
The browser receives the response and begins rendering the page.
● HTML Parsing: The browser parses the HTML content.
● Resource Loading: Additional resources (CSS, JavaScript, images) are fetched. Each
resource request goes through a similar process as the initial URL request.
● DOM Construction: The browser constructs the Document Object Model (DOM) from
the HTML.
● CSSOM Construction: The CSS Object Model (CSSOM) is constructed from CSS files.
● Render Tree: The DOM and CSSOM are combined to form the render tree.
● Layout: The browser calculates the layout of each element.
● Painting: The browser paints the pixels to the screen.
10. JavaScript Execution
If the page includes JavaScript, the browser's JavaScript engine executes it.
● Event Listeners: Attached to elements, awaiting user interactions.
● Dynamic Updates: Can modify the DOM or CSSOM, leading to re-rendering.
11. User Interaction
Finally, the user interacts with the rendered page, and this interaction can trigger further HTTP
requests or DOM updates.
This entire process involves numerous technologies and protocols working together seamlessly
to deliver a smooth web experience.
DETAIL:
1. DNS Lookup
When a user enters a URL, the DNS (Domain Name System) translates
the domain name into an IP address.
DNS Resolution Steps:
1. Browser Cache:The browser first checks its cache for a recent DNS
record to avoid redundant lookups.
2. OS Cache: If the browser cache doesn’t have the record, the OS
cache (managed by the DNS client service) is checked.
3. Router Cache: Next, the query is sent to the router, which might
have cached the DNS record.
4. ISP DNS Server: If not found locally, the router forwards the
request to the DNS server of the ISP.
5. Recursive Resolution: If the ISP DNS server doesn’t have the
record, it performs a recursive query:
○ Root DNS Servers: Start from the root (.) servers.
○ TLD DNS Servers: The root servers direct the query to the
top-level domain (TLD) servers (e.g., .com, .net).
○ Authoritative DNS Servers: TLD servers direct the query to
authoritative DNS servers for the specific domain.
DNS Record Types:
● Maps a domain to an IPv4 address.
A Record:
● AAAA Record: Maps a domain to an IPv6 address.
● CNAME Record: Alias of one domain to another.
● MX Record: Mail exchange servers for a domain.
● TXT Record: Arbitrary text data associated with a domain.
2. TCP/IP Connection
Once the IP address is obtained, a TCP connection is established
between the client and the server.
TCP Handshake:
1. The client sends a SYN (synchronize) packet to the server
SYN:
to initiate a connection.
2. SYN-ACK: The server responds with a SYN-ACK
(synchronize-acknowledge) packet.
3. ACK: The client sends an ACK (acknowledge) packet back to the
server.
Ports:
● Well-known Ports: Ports 0-1023 (e.g., HTTP uses port 80, HTTPS
uses port 443).
● Registered Ports: Ports 1024-49151.
● Dynamic/Private Ports: Ports 49152-65535.
3. SSL/TLS Handshake (if HTTPS)
For secure connections, SSL/TLS is used to encrypt the data between
the client and server.
SSL/TLS Handshake Steps:
1. The client sends a ClientHello message with supported
ClientHello:
SSL/TLS versions, cipher suites, and a random number.
2. ServerHello: The server responds with a ServerHello message
with the chosen SSL/TLS version, cipher suite, and a random
number.
3. Certificate: The server sends its SSL certificate to the client for
verification.
4. Key Exchange: Depending on the cipher suite, the client and
server exchange keys (e.g., using RSA or Diffie-Hellman).
5. Finished: Both client and server send a Finished message,
encrypted with the negotiated keys.
Encryption:
● Uses the same key for encryption and
Symmetric Encryption:
decryption (e.g., AES).
● Asymmetric Encryption: Uses a public-private key pair (e.g.,
RSA).
● Hashing: Ensures data integrity (e.g., SHA-256).
4. HTTP Request
The browser sends an HTTP request to the server.
HTTP Request Components:
● Contains the HTTP method, URL, and HTTP version
Request Line:
(e.g., GET /index.html HTTP/1.1).
● Headers: Key-value pairs providing additional information (e.g.,
User-Agent, Accept, Cookie).
● Body: Present in methods like POST, PUT, containing the data to
be sent to the server.
HTTP Methods:
● GET:Requests data from the server.
● POST: Submits data to be processed to the server.
● PUT: Updates a current resource.
● DELETE: Deletes a specified resource.
● HEAD: Same as GET but only requests the headers.
5. Server-Side Processing
The server processes the incoming request.
Components:
● Distributes incoming requests across multiple
Load Balancer:
servers to ensure reliability and efficiency.
● Web Server: Handles HTTP requests and responses (e.g.,
Apache, Nginx).
● Application Server: Runs the business logic (e.g., Tomcat,
Node.js).
Processing:
1. Determines which controller and action to invoke based
Routing:
on the URL and method.
2. Controller: Executes the business logic.
3. Model: Represents the data structure and handles database
interactions.
4. View: Templates that generate the HTML or other content to be
returned to the client.
6. Database Interaction
If the application needs to retrieve or store data, it interacts with a
database.
Database Types:
● Relational Databases (SQL): Use tables with rows and columns (e.g.,
MySQL, PostgreSQL).
● NoSQL Databases: Non-tabular databases that store data
differently (e.g., MongoDB, Cassandra).
Query Execution:
● Written in Structured Query Language to interact with
SQL Queries:
relational databases.
● NoSQL Queries: Depending on the database, queries can vary
(e.g., MongoDB uses BSON).
7. Generating the Response
The server constructs an HTTP response.
HTTP Response Components:
● Contains the HTTP version, status code, and status
Status Line:
message (e.g., HTTP/1.1 200 OK).
● Headers: Key-value pairs providing additional information (e.g.,
Content-Type, Content-Length).
● Body: The requested resource (e.g., HTML, JSON).
Status Codes:
● 2xx (Success): The request was successful (e.g., 200 OK, 201
Created).
● 3xx (Redirection): Further action needs to be taken (e.g., 301
Moved Permanently, 302 Found).
● 4xx (Client Error): There was an error with the request (e.g., 400
Bad Request, 404 Not Found).
● 5xx (Server Error): The server encountered an error (e.g., 500
Internal Server Error, 503 Service Unavailable).
8. Sending the Response
The server sends the HTTP response back to the client over the
established TCP connection.
9. Rendering the Page
The browser receives the response and begins rendering the page.
Steps:
1. The browser parses the HTML content and
HTML Parsing:
constructs the DOM (Document Object Model).
2. Resource Loading: The browser identifies additional resources
(CSS, JavaScript, images) and fetches them.
3. CSSOM Construction: The browser parses CSS and constructs
the CSSOM (CSS Object Model).
4. Render Tree: Combines the DOM and CSSOM to form the render
tree.
5. Layout: Calculates the layout of each element (size and
position).
6. Painting: Renders the pixels to the screen.
10. JavaScript Execution
If the page includes JavaScript, the browser's JavaScript engine
executes it.
JavaScript Engine:
● Parsing: Converts JavaScript code into an abstract syntax tree
(AST).
● Compilation: Converts AST to machine code.
● Execution: Runs the machine code.
Features:
● Event Listeners: Attached to elements, awaiting user interactions.
● DOM Manipulation: Allows dynamic updates to the page content.
● AJAX Requests: Fetches data asynchronously without reloading
the page.
11. User Interaction
Finally, the user interacts with the rendered page.
● Event Handling: JavaScript responds to events like clicks, form
submissions, etc.
● Dynamic Content: Updates the DOM or makes additional HTTP
requests (e.g., AJAX).
This comprehensive process involves numerous technologies and
protocols, ensuring a smooth web experience for the user.