Tutorial 2 tier 3 tier: Regarding, 2-tier and 3-tier, many Web sites explain but looks me difficult to a very fresher to understand. Here, I give my own style of explanation. If you would like to change the content or style (way2java aim is to simplify the complexity) for better explanation., please pass your comments at the end of this posting in Comment box.
The purpose of this notes is to introduce you to n-tier architecture, knowing the issues involved, advantages and disadvantages. This notes does not make you an expert in tiered architecture as it does not give complete information of n-tier (ofcourse, no single Web site gives you).
In 1-tier, 2-tier, 3-tier and n-tier, what a tier means? Before answering, what 2-tier and 3-tier means in trains? Tier in trains corresponds to sleeping berth. But in computer terminology, tier corresponds to layers of different systems involved in communication. I take an example to explain on Tutorial 2 tier 3 tier.
Suppose I own a super market in Hyderabad, one and only one. I give credit to my regular customers and I maintain their accounts also in software on my computer. Now what my software do basically, say when a customer comes with his shopping card issued by me? The software should cater the following requirements.
- A GUI should be presented (displayed) to the employee to enter the customer ID (this I call as presentation code).
- Some program with sufficient logic (I call it as business logic application) to read the ID and display the customer details like what overdraft is allowed, how much he used till now and his regularity of payment.
- Database should be maintained with regular updates of credits and debits etc. (I call database).
Because I own only one super market, all the above three requirements are loaded on a single system (computer). I am happy with the software.
This single system with all the 3 requirements is called as 1-tier. In 1-tier, the client is known as thick client or fat client as everything should be processed by the client itself.
Now I open two more branches in different parts of Hyderabad. I cannot be at all the three places. So, I must have a central place, ofcourse with a system, to sit and monitor all the three branches. Just for differentiation, I call the system in my central (head) office as server and the three branch systems as clients.
Now out of the above three requirements, what should be placed on the client systems and server system? I think it is better to place first requirement of GUI on client systems and the the other two, business logic application and database, on the server. You accept GUI required for every client system to enter customer ID. What about business logic and database? You may argue these two also can be loaded with clients itself avoiding server necessity. Of course, you are right. If they are maintained on the server, the following advantages may be thought of.
- Maintenance of code becomes easy. For example, I would like to introduce discousts for a forth coming festival, the discount logic should be added on all the client systems. It may be possible for two or three brachnes. But some super markets exist in India with more than 1000 branches also. Now is it possible to change all the 1000 clients? So the better idea is to place the business application on server side. Yes or no.
- If the database is put on the server, I can know stock position in each branch and send the required stock without an indent from the client and also a customer can go to any branch with his ID card and draw the goods.
Now you accept that the better position of the three requirements is GUI on client system and the the other two on the server. This type of arrangement is known as 2-tier architecture. In 2-tier, the first tier is generally multiple systems (where one system corresponds one client, here branch) and second tier, the server will be only one always. This is good.
In 2-tier scenario, the client is able to access the database on the server directly. Note that the database is very important than anything, say hardware systems, employees, buildings and stock. This database should be protected from all the clients’ direct access. I place the database on a separate system and I will not allow the client to access; only I permit the server to access. Client is permitted to access server only. Is it better you feel or not?
Now, finally three systems are involved – client system, server system and database system. Client is given only GUI and nothing more, server is loaded with business logic and database system with the database loaded. This type of arrangement is known as 3-tier architecture, the most proven as the best.
Some times, you may add between client and server, load balancing servers as in call centers, security systems etc and this is known as n-tier architecture.