What is the Difference between layers and tiers

What is the Difference between layers and tiers?

In this article, I will discuss one of the most frequently asked interview questions i.e. what is the difference between layers and tiers?

This question can also be asked in many different ways like

What are 3-layer and 3-tier architecture? Or

What do you mean by n-layer and n-tier architecture?

Layers:

The Layers refer to the logical separation of the application code. Logical layers help us to organize our code in a better way. For example, an application can have the following layers.

  1. Presentation Layer or UI Layer
  2. Business Layer or Business Logic Layer
  3. Data Access Layer or Data Layer

The above three layers reside in their own projects, maybe in 3 different projects or even more. When we compile the projects we get the respective layer DLL. So we have 3 DLL’s now.

Depending on how we deploy our application, we may have 1 to 3 tiers. As we have 3 DLL’s, if we deploy all the DLL’s on the same machine, then we have only 1 physical tier but 3 logical layers.

If we choose to deploy each DLL on a separate machine, then we have 3 tiers and 3 layers.

So, in short, we can define the Layers are the logical separation and the Tiers are the physical separation of an application. We can also say that tiers are the physical deployment of layers.

Tiers:
  1. The Presentation Tier which is also known as the UI Tier (Hosts the Presentation Layer or UI Layer). This can be considered as a web server in case of an ASP.NET web application. 
  2. The Application Tier which is also called as Business Tier (Hosts Business Layer or Business Logic Layer) of the application. 
  3. The Data Access Tier also is known as Data Tier (Hosts Data Access Layer or Data Layer).
  4. The Database Tier – It may be SQL Server or Oracle or any other database which has tables, stored procedures, and other database objects.
The following diagram represents the architecture of a typical n layer and n-tier

What is the Difference between layers and tiers

In general, the following are the responsibilities of each layer or tier:

The Presentation Layer or Tier is usually responsible for interacting with the user.

The Business Layer or Tier is responsible for implementing the business logic of the application.

The Data Access Layer or Tier is responsible for encapsulating the code that accesses the persistent data stores such as a relational database.

Once we understand the difference between n-tier and n-layer architecture, let’s discuss the advantages and disadvantages of using layered architecture.

Following are the advantages of a layered architecture:

Layered architecture increases flexibility, maintainability, and scalability. In Layered architecture, we separate the user interface (i.e. presentation layer) from the business logic and the business logic from the data access logic layer. Separation of concerns among these logical layers and components is easily achieved with the help of layered architecture.

Multiple applications can reuse the components. The Layered architecture allows us to reuse the same components in multiple applications. For example, if we want a windows user interface rather than a web browser interface, this can be done very easily just by replacing the UI component. All the other components like business logic, data access logic and the database remains the same.

The layered architecture enables teams to work on different parts of the application parallel with minimal dependencies on other teams. For example, some developer may work on the presentation layer while some other developer may work on the business logic layer at the same time some developer might work on the data access layer as well.

Different components of the application can be independently deployed, maintained, and updated, on different time schedules.

The Layered architecture also makes it possible to configure different levels of security to different components deployed on different machines. So Layered architecture, enables us to secure portions of the application behind the firewall and make other components accessible from the Internet.

Layered architecture also helps us to test the components independently of each other.

Following are the disadvantages of a layered architecture:     

There might be a negative impact on the performance as we have the extra overhead of passing through layers instead of calling a component directly. 

Development of user-intensive applications can sometimes take longer if the layering prevents the use of user interface components that directly interact with the database.

The use of layers helps to control and encapsulate the complexity of large applications but adds complexity to simple applications.

SUMMARY

In this article, I try to explain the Difference between layers and tiers. I hope this article will help you with your need. I would like to have your feedback. Please post your feedback, question, or comments about this article.

Leave a Comment

Your email address will not be published. Required fields are marked *