Saturday, January 4, 2014

2. Difference between 2-Tier and 3-Tier Architecture?

All projects are broadly divided into two types of applications 2 tier and 3 tier architecture. Basically high level we can say that 2-tier architecture is Client server application and 3-tier architecture is Web based application. Below I am concentrating on the difference between Two-Tier and Three-Tier Architecture, what all advantages, disadvantages and practical examples.

Two-Tier Architecture:

The two-tier is based on Client Server architecture. The two-tier architecture is like client server application. The direct communication takes place between client and server. There is no intermediate between client and server. Because of the tight coupling, a 2 tier application will  always run faster.


This figure shows the architecture of two-tier; there is a direct communication between client and server, there is no intermediate between them.

Let’s take a look of real life example of Railway Reservation  in two-tier architecture:

Let’s consider that a person is making Railway Reservation for Mumbai to Delhi by Mumbai Express at Counter No. 1 and at the same time the other person is also looking to book the same birth for the same train from Counter No. 2.
Now, in this case, If staff from both the counters are trying to book the same birth, there might be a good chance of confusion and chaos, only one of them would be able to get the reservation done (whoever clicks the booking option first).

But reservations could be done from anywhere in India, then how will it be handled?

So here comes the role of three tier architecture for handling the multiple requests at a time. if there is a difference of micro seconds for making the reservation then only the very first request is proceed further and the other requests are added into the queue. 

For the first request, the Staff enters the data to Client Application and the reservation request is sent to the database. The database sends back the information/data to the client.

In this application, the Staff user is an end user who is using Railway reservation application software. He gives the inputs to the application software and it sends requests to server;  both Database and Server are incorporated with each other, so this technology is called as “Client-Server Technology“.

The Two-tier architecture is divided into two parts:

1) Client Application (Client Tier)
2) Database (Data Tier)

On client application side, the code is written for saving the data in the SQL server database. Client sends the request to server and it processes the request & sends back with data. The main problem of two tier architecture is the server cannot respond multiple requests at the same time, as a result it will cause a data integrity issue.

Advantages:

1.   Easy to maintain and modification is bit easy
2.   Communication is faster.

Disadvantages:

1.   In two tier architecture application performance will be degrade upon increasing the users.
2.   Cost-ineffective

Three-Tier Architecture:

Three-tier architecture typically comprise of a presentation tier, a business or data access tier, and a data tier. Three layers in the three tier architecture are as follows:

1) Client layer
2) Business layer
3) Data layer

1) Client layer:
It is also called as Presentation layer which contains UI part of our application. This layer is used for the design purpose where data is presented to the user or input is taken from the user. For example designing registration form which contains text box, label, button etc.


2) Business layer:
In this layer all business logic written like validation of data, calculations, data insertion etc. This acts as a interface between Client layer and Data Access Layer. This layer is also called the intermediary layer helps to make communication faster between client and data layer.

3) Data layer:
Data Access Layer contains methods to connect with database and to perform insert, update, delete, get data from database based on our input data.

Advantages

1.   High performance, lightweight persistent objects
2.   Scalability – Each tier can scale horizontally
3.   Performance – Because the Presentation tier can cache requests, network utilization is minimized, and the load is reduced on the Application and Data tiers.
4.   High degree of flexibility in deployment platform and configuration
5.   Better Re-use
6.   Improve Data Integrity
7.   Improved Security – Client is not direct access to database.
8.   Easy to maintain and modification is bit easy, won’t affect other modules
9.   In three tier architecture application performance is good.

Disadvantages
1.   Increase Complexity/Effort

This is the common Question asked in the Interview. Hope this post helped you understanding Two-Tier and Three-Tier Architecture with example.

Thanks and Happy Testing!!!

2 comments:

  1. Hi, plz add more details about three-tier architecture

    ReplyDelete
  2. Hi Sheenu, Please find the detailed explanation of 3-tier architecture below:

    This involves one more layer called the business logic tier, service tier or middle tier (layer). In the client-server solution the client was handling the business logic and that makes the client “thick”. A thick client means that it requires heavy traffic with the server, thus making it difficult to use over slower network connections like Internet and Wireless (LTE, 3G, or Wi-Fi).

    By introducing the middle layer, the client is only handling presentation logic. This means that only little communication is needed between the client and the middle tier making the client “thin” or “thinner”. An example of a thin client is an Internet browser that allows you to see and provide information fast and almost with no delay.

    As more users access the system a three-tier solution is more scalable than the other solutions because you can add as many middle tiers (running on each own server) as needed to ensure good performance (N-tier or multiple-tier).

    Security is also the best in the three-tier architecture because the middle layer protects the database tier.

    ReplyDelete