N-Tier

Multitier

Definition
A tiered architecture cleanly separates its main concerns. Each tier only communicates with the tier before and the tier after it.

Each tier may live on a separate server, or two or more tiers may be combined on the same server. It's the separation of concerns that matters.

N-tier architecture diagram

I will explain the 4-tier architecture here. There may be less or more.

The presentation tier deals with the interaction with the user. It shows the user interface and allows the user to interact with it via controls.

The controller tier or application tier contains all the code required to run an application, but distinct from the domain model.

The domain logic tier contains the code that expresses the requirements of the domain, or business. This information is typically extracted from domain experts.

The data access tier stores and retrieves data from the database. It contains CRUD functions (Create Read Update Delete), as well as complicated queries joining multiple tables.

How does it work?

Communication between the different tiers often takes place via a network.

Examples

  • Web-applications

When should you use it?

Every large scale application needs to separate these concerns. A specialized team may work on a single tier. Even on small applications this pattern helps to reduce cognitive load (makes it easier to understand).

Advantages of a separate the presentation tier

  • It is possible to have a frontend team just work on the visual design, without having to code
  • It is possible to add another view (presentation) in the same application
  • It is possible to replace the presentation
  • It is possible to test the application without access to the presentation

Advantages of a separate domain logic tier

  • Isolating the domain rules to review them with the domain experts
  • Preventing code-duplication, which makes maintenance easier
  • Unit tests that are don't need a database are faster and easier to create

Advantages of a separate data access tier

  • A separate data access tier can focus on speed

Links