Skip to main content

N Tier Architecture

Some Myths

People normally think if they have created UI (ASP.Net application project), BL (.Net Class Library Project), & DAL data access layer (.Net Class Library Project) and referencing these projects in their web project, they are following 3 tier architecture. I think creating a n tier application is more than this.

What is tier?

According to me tier means a stand-alone process which has some code to process. In the above scenario where ASP.Net Web Application is referencing BL and DAL, all the code is running in w3wp (server OS)/ aspnet_wp process which is known as worker process. So in real terms all this is single tier.

Then question arises that, is it 1 tier application? If you are not dealing with databases or any other thing which has its own process then yes it is 1-tier architecture. Database makes it 2-tier architecture. As all the databases are run under some process. sqlservr is the process for SQL databases.

Some people also say that a web application will always run under a browser and why don't treat that as a tier and say this as 3 tier architecture?

I would say a tier should contain some meat in it. Meat means, some code which processes some part of the request handling, it should minimize the effort of request processing. Now what all can be processed at browser? To process anything on browser one has to write java script or any other client script.

Browser can do validation, however every one should be agree that all the validation which we do on client should be done on server also. So browser do not minimize any processing here.

Browser can also enhance the UI which is instant action. That's a good help in enhancing the UI, now logically it is a part of UI layer which is been run on browser instead of server just to improve the user experience it is not helping in request processing.

What makes 3 tier architecture

One has to introduce one more process somewhere. We can host the Business Logic as a WCF service / Remoting. WCF service should be hosted in an application pool other than the web application pool. This is just to make sure that both the application will be run in different worker process.

In this way we would have 3 different processes 1. Web Application Process, 2. BL WCF process, and 3 would be the database process.

Why to make 3-tier

Going back to the starting why did you want your application to be 3-tier. Answer to this question contains many big words like Performance Optimization, Scalability, Robustness, Code Re-Usability, and many more.

Compare this with following question:

2 person to do your job vs 3 person to do your job, you will get all your answers. 3 men can do the task more rapidly, correct? Yes if task can be broken into sub tasks. Same applies here if you can divide your task in sub tasks then 3 tier architecture will be beneficial.

Some people take the following approach in writing the code:

Lets take an example when one is creating a inventory application, now they write a method in DAL PlaceOrder (which takes many arguments like Customer, collection of products, PersonBillingPlan etc), this method will call a SP sp_PlaceOrder and all the logic will be written in that SP. This DAL method will simply be called in BL and will return success / failure. Now even if we create WCF service and force it to run in different process, we won't achieve what we intended to while following 3-tier architecture. This is because we do not have any meat (code to execute in BL), hence all the load is on the database. Database has to perform all the operation of validating data and applying business rules. Now in a team of 2 people if one is over burdened then will my team give the right productivity as expected? I guess no... what do you say please let me know in the comments section.

One more interesting question arises here while following true 3-tier architecture

People say, if we have to write business logic in .Net code then we have to fetch some extra data from Sql to .Net and write code on them, where in SP approach everything was coded in SQL and no data was travelling from SQL to .Net and finally a flag was sent from the DB which signifies success or failure. Now to counter attack this question I would say following things:

1. Data is anyway fetched from database, select query will be hit in both the cases only thing is data will be travelled from sql to .Net. I guess this would not harm that much but depends.


2. Data caching: data caching is way to minimize the above damage. One can easily write code to use data caching at DAL and save the effort of fetching common/static data. If data will be cached then it would really enhance the performance of the application by leaps and bounds.

I hope this would help you writing 3-tier application.


Popular posts from this blog

Client Storage in SilverLight

Client Storage for Silverlight Silverlight provides two classes, one is IsolatedStorage and another is DataContractSerializer . Silverlight provides IsolatedStorage class to store data at client machine. With isolated storage, data is always isolated by user and by assembly. Credentials such as the origin or the strong name of the assembly determine assembly identity. Data can also be isolated by application domain, using similar credentials. DataContractSerializer class, which is used to serialize and deserialize instances of a type into an XML stream or document. For example, you can create a type named Person with properties that contain essential data, such as a name and address. You can then create and manipulate an instance of the Person class and write all of its property values in an XML document for later retrieval, or in an XML stream for immediate transport. Most important, the DataContractSerializer is used to serialize and deserialize data sent in Silverlight version 2 m

Create Parallel Task in State Machine Workflow in SharePoint2010

I faced a problem while creating parallel tasks in state machine workflow. My requirement is same as OUT of Box SharePoint approval workflow which allows multiple users to approve the document and when everyone approves the document, document moves to next state which is approved. All the articles pointed me that this is possible in sequential workflow. Here is the thread which explains the problem, I would no be investing much time to explain the problem http://groups.google.com/group/microsoft.public.sharepoint.portalserver.development/browse_thread/thread/e0beac08110f6135 I downloaded the code sample available at Microsoft site which is basic state machine workflow. Following is the link. http://code.msdn.microsoft.com/SharePoint-2010-Creating-39ac75ea Modifications to the code are as follows: Add a new state at level 2. In the state initialization, create two tasks with different Correlation token, task ids and task properties. Now add two event