Skip to content

Instantly share code, notes, and snippets.

@jwashke
Created March 22, 2016 17:29
Show Gist options
  • Save jwashke/91caa8fe558e54c598d5 to your computer and use it in GitHub Desktop.
Save jwashke/91caa8fe558e54c598d5 to your computer and use it in GitHub Desktop.

How the Web Works

What happens when you enter a url into the address bar of a web browser and hit enter

  • This is a common interview question

Hypertext Transfer Protocol (HTTP)

Stores no state, simple text documents transferred back and forth.

HTTP Verbs
  • GET - Retrieve information identified by the Request-URI
    • GET /users => All users
  • POST - Create a new resource identified by the Request-URI
    • POST /users => Create a new user
  • PUT - Update a specific resource identified by the Request-URI
    • PUT /users/1 => update existing user with id of 1
  • DELETE - Delete the resource identified by the Request-URI
    • DELETE /users/1 => delete existing user with id of 1

All of the verb decisions are decided within your application. You can go against protocol in your application. ex:

get '/users' do
	create_user
end

You shouldn't do this and should stick to following the protocol.

Domain Name System (DNS)

  • Massive database mapping domain names to IP addresses.
  • Translates domain names to the numerical IP addresses.
DNS lookup
  • First place it looks is in the cache of the local machine.
  • If it doesn't find it there, it looks in the cache of the local network.
  • Next if will check the ISP to if it has it cached.
  • Finally it checks the DNS space
    • In DNS it first checks Resolving Name Server
    • Root Server
      • .com
      • .net
      • TLD servers
    • Top Level Domain Servers Every step of the journey what is found is cached.

Internet Protocol address (IP address)

  • IPv4 uses 32-bit addresses or 2**32 (4,294,967,296)
  • Human readable: 172.16.254.1
    • Translates to: 10101100.00010000.11111110.00000001
  • Reserved address (127.0.0.1)
  • IPv6 uses 128-bit addresses or 2**128
    • (340.282.366.920.938.463.463.374.607.431.768.211.456)

Visit the Server

Ports

The server is listening for traffic on a specific port.

  • Port 80 is commonly used for http
  • Port 22 is commonly used for ssh
    • To protect server against ssh attacks you can close port 22 and use ssh on a secondary port.
  • Port 443 is commonly used for https Programs like Nginx and Apache watch the port waiting for the traffic to come in.

Nginx and Apache are referred to as web servers or HTTP servers.

Puma and Unicorn are referred to as application servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment