Ask Professor Puzzler
Do you have a question you would like to ask Professor Puzzler? Click here to ask your question!
Hi, I want know about 2-tier architecture and 3-tier architecture. Please explain me with some examples. Regards, Chandra
Chandra, The easiest way to explain this is, as you suggest, by an example. So I'll give you an example.
Let's suppose I'm going to write a piece of software that students at a school can use to find out what their current grade is in all their classes. I structure the program so that a database of grades resides on the server, and the application resides on the client (the computer the student is physically interacting with).
When the student wants to know his grades, he manipulates my program (by clicking buttons, menu options, etc). The program fires off a query to the database, and the database responds with all the student's grades. Now my application uses all this data to calculate the student's grade, and displays it for him.
This is an example of a 2-tier architecture. The two tiers are:
- Data server: the database serves up data based on SQL queries submitted by the application.
- Client application: the application on the client computer consumes the data and presents it in a readable format to the student.
Now, this architecture is fine, if you've got a school with 50 students. But suppose the school has 10,000 students. Now we've got a problem. Why? Because every time a student queries the client application, the data server has to serve up large queries for the client application to manipulate. This is an enormous drain on network resources. So what do we do? We create a 3-tier architecture by inserting another program at the server level. We call this the server application. Now the client application no longer directly queries the database; it queries the server application, which in turn queries the data server. What is the advantage to this? Well, now when the student wants to know his final grade, the following happens:
- The student asks the client application.
- The client application asks the server application.
- The server application queries the data server.
- The data server serves up a recordset with all the student's grades.
- The server application does all the calculations to determine the grade.
- The server application serves up the final grade to the client application.
- The client application displays the final grade for the student.
It's a much longer process on paper, but in reality it's much faster. Why? Notice step 6. Instead of serving up an entire recordset of grades, which has to be passed over a network, the server application is serving up a single number, which is a tiny amount of network traffic in comparison. There are other advantages to the 3-tier architecture (for example, a three tier architecture allows you to do load balancing, by having multiple servers that can function as the middle tier).
Incidentally, this website is a 3-tier application. The client application is your web browser. The server application is the php code which queries the database (the third tier) for the question-and-answer you requested. I hope that helps!