Applied Theory: How Facebook Works

After having studied my articles on Relational Databases and How the Internet Works, here are the basics of how Facebook works. I will only concentrate on the users and their friends (as Facebook is a HUGE undertaking).
Tables
Below are the tables for the users and friends features. Notice how Jen & Jake are friends and Rob & Davy are friends.

Users

id username password
1 jacob beasley
2 jennifer hamilton
3 rob mohr
4 davy stiles
5 charles beasley
Friends

id userid friendid
1 1 2
2 2 1
3 3 4
4 4 3
Login Process:

  1. You go to Facebook.com. Facebook.com shows you a login form. You type in your username/password and click login.
  2. Your browser sends a request to Facebook containing your login information
  3. The web server receives the requests, recognizes that it is for a PHP file, and it starts up the PHP interpreter.
  4. The PHP Interpreter reads the Facebook programmer’s code. The code realizes that you are trying to login and queries up the MySQL database to see if the email/password is valid. The “query” is sent using SQL (structured query language).
  5. The mysql database searches the table and finds the user. It then sends this back to the php script
  6. The php script continues running where it left off. It recognizes that the data was valid. It tells the browser to save a cookie with the user’s information and outputs the rest of the page.

Viewing another page:

  1. You click on your inbox.
  2. Your browser requests the inbox page. It sends the cookie that was set in the login process over to the web server.
  3. The web server recognizes it is requesting a PHP file and runs the code through the PHP interpreter.
  4. The php code sends a request to the mysql server to see if the information stored in the cookie is valid.
  5. The mysql server sends back a response.
  6. The php code sees that the cookie does checkout. It then queries the mysql table for a list of messages
  7. the mysql servers sends back a response with the messages
  8. the php code then outputs the rest of the page with the messages
  9. The web server sends what the php code outputs to the browser
  10. The browser, finally, displays the page to you, the user.
  • Share/Bookmark



No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *