Way2Java

Tutorial 2 tier 3 tier Architecture

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.

  1. A GUI should be presented (displayed) to the employee to enter the customer ID (this I call as presentation code).
  2. 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.
  3. 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.

  1. 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.
  2. 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.

Now let us go in a technical way of explanation of Tutorial 2 tier 3 tier.

Tutorial 2 tier 3 tier

1. Presentation Layer

2. Application Layer

The server does a lot of work at the background to deliver the information requested by the client.

For example, if you would like to withdraw some amount from the ATM, the application layer requires to check whether the balance is available or not, should check if overdraft exists the withdrawal is within limits only, access database and hand over cash taking care of all the transaction mechanism and logging etc required.

This layer sometimes also referred as Services layer, Business logic layer, Server, Middle tier etc.

3. Database Layer

1 – Tier Architecture

a) Advantages

b) Disadvantages

2 – Tier Architecture

a) Advantages

b) Disadvantages

Note: Sometimes, the business logic can be on the client also.

3 – Tier Architecture

3-tier architecture comes with a client tier, a middle tier and a database tier. The client tier is for communication between the user and the system. The middle tier communicates with the other two tiers and the database tier manages the whole data.

In 3-tier, the client (generally a browser in Web communication) is known as thin client as client does not do anything other than taking data from client and forwarding to the middle tier and printing the response to client.

For more security of database, a persistence manager can be placed on database server. Persistence manager controls the flow of data between application server and database. That is, application server cannot communicate directly with the database (now you may call it as 4-tier architecture).

a) Advantages

b) Disadvantages

The client/server architecture (of 2 and 3 tiers) permits to distribute the workload and may use the following other technologies.

For n-tier development, the architect thinks of the following.

  1. The application requires how many tiers.
  2. What is the task to be performed by each tier? Answer to this gives the number of tiers exactly required.
  3. Requires thin client (dumb terminal) or thick client. In thick client, some part of the workload (say, some logic) of middle tier is executed by the client.
  4. The server is accessible to Web or not.
  5. The size of connection pool on the database server.
  6. The type of DBMS should be installed like Oracle, DB2, MySQL etc by considering the number users with scalability, performance while retrieving big data and budget.
  7. Also should be thought of languages like Java, PHP, PERL etc., platforms and other supporting software, the informative system should make use of.

For more clarity and differences read Difference between 2-tier and 3-tier Architecture.