phatboislym

web stack (2)

Jan 8th, 2023
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.79 KB | Writing | 0 0
  1. What Happens When You Type https://www.google.com in Your Browser?
  2. Have you ever stopped to think about what happens behind the scenes when you type a URL into your browser and press Enter? While it may seem like magic, there is actually a series of events that occurs to allow you to interact with the website.
  3.  
  4. In this post, we'll take a closer look at what happens when you type https://www.google.com into your browser and press Enter. We'll cover the following topics:
  5.  
  6. DNS request
  7. TCP/IP connection
  8. Firewall
  9. HTTPS/SSL
  10. Load-balancer
  11. Web server
  12. Application server
  13. Database
  14. 1. DNS Request
  15. The first step in this process is the DNS (Domain Name System) request. When you type in a URL like https://www.google.com, your computer needs to know the IP address of the server where the website is hosted. It does this by making a DNS request to a DNS server.
  16.  
  17. DNS lookup
  18.  
  19. The DNS server looks up the IP address associated with the domain name and sends it back to your computer. This process is called a DNS lookup.
  20.  
  21. As an example, let's say you type in https://www.example.com into your browser. Your computer will send a DNS request to a DNS server asking for the IP address of www.example.com. The DNS server will respond with the IP address, and your computer will use that address to establish a connection to the server.
  22.  
  23. 2. TCP/IP Connection
  24. Next, your computer establishes a TCP (Transmission Control Protocol) connection with the server. TCP is a set of rules that govern how data is transferred over the internet. It ensures that data is transferred reliably and in the correct order.
  25.  
  26. Here's how it works:
  27.  
  28. Your computer sends a SYN (Synchronize) packet to the server, requesting a connection.
  29. The server responds with a SYN-ACK (Synchronize-Acknowledgment) packet, acknowledging the request.
  30. Your computer sends an ACK (Acknowledgment) packet, completing the three-way handshake and establishing the connection.
  31. TCP connection
  32.  
  33. 3. Firewall
  34. If the server has a firewall set up, the connection request will need to be approved by the firewall before it can be established. The firewall checks the request against a set of rules to determine whether it should be allowed through or blocked. This helps to secure the server and prevent malicious traffic from reaching it.
  35.  
  36. For example, the firewall may have rules that block all incoming traffic from certain countries or IP addresses. If the request originates from one of these blocked sources, it will be denied and the connection will not be established.
  37.  
  38. 4. HTTPS/SSL
  39. Once the connection is established, the browser sends an HTTPS (Hypertext Transfer Protocol Secure) request to the server. HTTPS is a secure version of the HTTP protocol that is used to transfer data on the web. It encrypts the data being transferred to prevent it from being intercepted by third parties.
  40.  
  41. ![HTTPS](https://i.imgur.com/4xCfL3F.png)
  42.  
  43. But how does HTTPS work, exactly? When you connect to a website using HTTPS, the following steps occur:
  44.  
  45. The browser sends a request for a secure connection to the server.
  46. The server sends a copy of its SSL (Secure Sockets Layer) certificate to the browser.
  47. The browser checks the certificate to verify the identity of the server. If the certificate is valid, the browser sends a message to the server to begin the SSL handshake.
  48. The server sends a message back to the browser to confirm the handshake.
  49. The browser and server use the SSL handshake to generate a unique, shared secret key that will be used to encrypt all communication between them.
  50. The browser sends the HTTPS request to the server, encrypted with the shared secret key.
  51. The server decrypts the request and processes it, then sends the response back to the browser, encrypted with the shared secret key.
  52. The browser decrypts the response and displays the webpage to the user.
  53. 5. Load-balancer
  54. If the server has a load-balancer set up, the HTTPS request will be routed through it. A load-balancer is a device that distributes incoming requests across a group of servers to balance the load and ensure that the system remains stable and efficient. This is especially important for websites that receive a large volume of traffic.
  55.  
  56. For example, let's say that a popular website receives 1000 requests per second. If all of these requests were sent to a single server, it could quickly become overloaded and unable to handle the traffic. By using a load-balancer, the requests can be distributed across multiple servers, allowing the website to scale and handle more traffic.
  57.  
  58. Load-balancer
  59.  
  60. 6. Web server
  61. The request is then forwarded to the web server, which processes the request and sends back the appropriate response. The web server retrieves the requested webpage and any associated resources (such as images, videos, or other files) and sends them back to the browser.
  62.  
  63. In the case of a static website (a website that consists of fixed HTML pages), the web server simply retrieves the requested HTML file and sends it back to the browser to be rendered.
  64.  
  65. 7. Application server
  66. If the webpage requires dynamic content (content that is generated in real-time), the request may be forwarded to an application server. The application server processes the request and generates the dynamic content, which is then sent back to the web server to be included in the final webpage.
  67.  
  68. For example, if you fill out a form on a webpage and submit it, the request may be sent to an application server to process the form data and generate a response (such as a confirmation page).
  69.  
  70. 8. Database
  71. If the webpage requires access to data stored in a database, the application server may need to request this data from the database server. The database server retrieves the requested data and sends it back to the application server, which includes it in the final webpage.
  72.  
  73. Finally, the fully-assembled webpage is sent back to the browser, which renders it for the user to interact with. And that's what happens when you type https://www.google.com into your browser and press Enter!
  74.  
  75. I hope this post has helped you understand the various steps that occur when you access a website. While there are many technical details involved in this process, it's amazing to think that all of this happens in just a matter of seconds.
  76.  
  77. In my personal experience, I've had to troubleshoot DNS issues on several occasions. One time, I spent hours trying to figure out why a certain website wasn't loading, only to realize that the DNS records had not been properly configured. It was a frustrating but valuable learning experience, and it reminded me of the importance of double-checking all the details.
  78.  
  79. If you'd like to learn more about how the web works, check out these resources:
  80.  
  81. [How the Web Works] from Mozilla Developer Network
  82. [How Does the Internet Work?] from HowStuffWorks
  83. [How Web Servers Work] from HowStuffWorks
  84. Thanks for reading!
  85.  
Advertisement
Add Comment
Please, Sign In to add comment