Tier Architecture
This is very important topic to consider when developing anapplication. Many elements need to be considered when deciding on thearchitecture of the application, such as performance, scalability and futuredevelopment issues. When your deciding on which architecture to use, firstdecide which of the three previously mentioned elements you think is mostvaluable – as some choice you make will impact on others. For example somechoices that boost performance will impact on the scalability or futuredevelopment if your design.
Here we will generally talk about what n-Tier architectureis, and then will have a look at different n-Tier architectures you can use todevelop ASP.Net applications and issues that arise relating to performance, Scalability,and future development issues for each one.
Firstly what is n-Tier Architecture?
N-Tier architecture refersto architecture that separates Business, Presentation and data Access from one others by having them asa different applications (layers or parts) within same solution. The basic rulein his architecture is each layer can interact directly with one layer belowbut not vice versa and has specific function for it is responsible for.
Now you must be thinking shy to use n-Tier architecture?
Each layer can be locatedon physically different servers with only minor code changes, Hence they scaleout and handle more server load. Also what each layer is doing internally ishidden from other layer so they can be modified without recompiling otherlayers.
This is very powerful feature of n-Tier architecture, as additional feature orchange to an application can be done without redeploying the whole application.For example by separating data access code from business logic code, wheneverdatabase server change you need to change data access code. As business logiccode stays same it does not need or be modified or recompiled.
N-Tier architecture can have no more than 3 Tiers and theyare called Data Access Tier, Business Logic Tier and Presentation Tier. Pleasedon’t get confuse between projects and layer as data access layer can spreadacross multiple projects in any applications. Let’s have a look at what’s eachtier is responsible for.
Presentation Tier
presentation tier isresponsible for displaying the user interface and “driving” that interfaceusing business tier classes and objects. In ASP.Net it includes .aspx pages,User controls, Server Controls, HTML Pages, and sometimes security relatedclasses and objects.
Business Tier:
Business tier isresponsible for retrieving data from data access layer, running businesscalculations on the produced data and send the results to presentation layer.In ASP.Net it includes suing SqlClient or OleDb objects to retrieve, update anddelete data from database server, and also passing the data retrieved to thepresentation layer in DataReader or DataSet objects, or a custom collectionobject.
BLL and DAL
Often this tier isdivided into two sub layers: The Business Logic Layer (BLL) and the Data AccessLayer (DAL). Business Logic Layer is above data access layer means BLL uses DALclasses and objects. DAL is responsible for accessing data and forwarding it toBLL.
In ASP.Net it might be using SqlClient or OleDb to retrieve the data andsending it to BLL in the form of DataSet or DataReader. BLL is responsible forpreparing data retrieved and sends it to the presentation layer. In ASP.Net itmight be using DataSet or Data reader objects to fill up the common collectionor process it to fill up the custom collection or process it to come up withthe value, and sending it to presentation layer.
Data Tier
Data Tier is thedatabase or the source of the data itself. Often in .NET it’s SQL Server oraccess database, however it’s not limited to just two of those. It could alsobe oracle, My SQL or even XML. In this article we will focus on SQL Server asit’s been proven to be the fastest database within a .Net application.
Logical Layers VsPhysical Layers (Distributed)
Logical layer andphysical layer are the one that confuses the peoples most. Firstly logicallayers means layers are separated in terms of assembly or Set of classes, butare still hosted on teh same server. Physical Layers means those assemblies arehosted on different servers with additional code to handle the communicationbetween the layers e.g. Remoting or WebServices.
Deciding to separate the layers physically or not is important. It reallydepends on the load of your application expects to get. I think it’s worthmentioning some of the facts that might affect your decision.
Separating layer physically will slow down the applicationdue to delay in communication between servers throughout the network, if youare using physical layer approach, make sure performance gain is worth performanceloss in this.
Hopefully you have developed the application suing n-Tierapproach. In this case note that you can separate the layers in future.
Cost for maintaining physically separated server is muchgreater. First of all, you will need more servers. You will need a networkhardware connection them. At the same point deploying the application becomescomplex too! So decide these things will worth it or not.
Another fact that might affect your decision is how each ofthe tiers in the application are going to be used. You will probably want tohost a tier on a different server if more than one service is dependent on it,e.g. you might want to host business logic somewhere else if you are havingmultiple presentation layers for different clients. You might want a separateSQL server if other applications using the same data.