What really is an N-tier application?

10

I've always heard a lot about N-tier applications, but thinking about it lately I've been a bit confused by what this really means. Searching on google found the wikipedia article on the subject and saw that this has to do with a physical separation.

So in this way, is an N-tier application an application that is divided into N parts, each of which runs in a different environment? So a web application with database access would be considered 3-tier because it is divided into client, server and database, and does each one work in one place?

But in this case if the database server is on the same computer as the web server, would it be 2-tier? Or what counts is that they are separate processes?

    
asked by anonymous 27.07.2014 / 02:15

3 answers

11

Update:

Tier is usually referenced by the physical layer , while layer is usually referenced by the logical layer. This is an older concept, today basically, most servers run in the cloud, where this "physical separation" does not make much sense. I will treat Tier and Layer as the same meaning of the word (layer / level)

Tier / Layer is layer that represents a logical sequence, period. You can create an application of 1..N layers, in the way that you think is the correct one. This does not necessarily mean that it is something physical or in separate environments. it is only the abstract separation of its application itself. For example nowadays it is well known applications in 3 layers ... ( not to confuse with MVC ).

Just to illustrate:

Layer 1: Layer of presentation, where everything is related to view, can be Java Swing screens, .Net forms, or web pages.

Layer 2: Logical layer. All the rules specific to your application, is the central part of your app. Where in fact you are designing your ideas.

Layer 3: Access to the bank. Good here, you ... access the bank =). And there may also be some logic related to the transaction, etc.

Nothing prevents you from creating an app with 1,2,3,4 or 5+ layers, for example the 3 cited cents, plus another Rest integration, another specific validation and so on. It all depends on the project requirement. In general 3 is enough or even too much.

Why to use layers?

In practice it is to separate the concepts. Usually communication is done through interfaces , which makes it much easier to add or replace one of them. Another situation is when working as a team. Where you have the faces of the frontend developing the graphical interface, others in the "core", etc. Where each team does not change the code of the other team, all working on the same project. And at the same time they know what to pass and what to receive from the top / bottom layer because they use the interfaces contracts. All this in the world of OOP, other paradoxes I'm not sure for sure how it should work.

Emphasizing that "layer" is the abstract separation of the logic of your project. But when it comes to large architectures, we can also have N layers, at the application level, where each layer can correspond to an application running on one server, which communicates with another running on another server, a good example of this are commercial applications, where things start to get pretty big.

In general more layers do not mean to be better, the more layers, the more decoupling you have, which is good but often unnecessary, but generates more complexity and maintenance work.

Note that the layer has the stack scheme, where to get the last one you must go through all the intermediates, eg

Layer 1 < - > layer 2 < - > layer 3

    
28.07.2014 / 06:18
7

An N-Tier application, is an application program in n layers is an application developed in order to have several logical layers. Each layer is self-contained enough so that the application can be split into multiple computers in a distributed network.

The most common form of architecture is the three-tier (3-Tier) application commonly used in web applications, where the layers are:

  • User Interface (Presentation Layer);
  • business logic (Business Layer); and
  • database (Data Layer).

Each layer of this architecture is usually maintained on a specific server to become more scalable and independent of the others. For the same purpose, middleware technologies such as CORBA, Web Services or RMI are used.

This architecture has the following characteristics:

  • Low availability costs;
  • Low costs of database change;
  • Low costs in changing business logic;
  • Efficient storage and reuse of resources.

It is debatable that counts as "layers", but in my opinion it needs to at least cross the border process. Or else it is called layers. But, this does not need to be on physically different machines. Although I do not recommend, you can host layers and logical database in the same box.

Oneimplicationisthatpresentationlayerandlogicallayer(sometimescalledBusinessLogicLayer)needtocrossborders"by the wire" sometimes by unreliable, slow, and / or insecure network. This is very different from the simple desktop application where data resides on the same machine as files or Web applications where you can access the database directly.

For n-tier programming, you need to pack the data into some sort of transportable form called a "data set", and carry them along the wire. The DataSet class of .Net or Web Services like SOAP are few of such attempts to "pass" objects along the wire.

    
28.07.2014 / 13:37
2

N-Tier application is an application whose architecture separates physically concepts. "N-Tier" does not refer to logical or conceptual separation only.

  

But in this case if the database server is in the same   computer than the web server, there would be 2-tier? Or what counts is that   are separate processes?

In this case it is still 3 tiers because the concepts of web server and database server are physically separated and this system has been devised to be deployed using different servers.

N-Tier architecture has become trivial and very common, so this term is almost out of use. Examples of non-N-Tier software:

  • Applications developed in Clipper.
  • Applications developed in MS Access (almost always a single layer / tier).
  • Applications developed in any language that does not use a SGBD nor consume another remote service to search or persist your data example a Java application that saves your data in XML or any other file managed by it and not by other software).

A much more common term nowadays is Multi-Layer , and this one is about the logical or conceptual separation of a system, not necessarily implying physical separation.

Update: I added some reference below.

  

It's important to understand the distinction between "layers" and "tiers". "Layers"   describes the logical grouping of functionality and components in a   application; while "tiers" describes the physical distribution of   functionality and components on servers, computers, networks or   remote locations. Although both layers and tiers use the same   set of names (presentation, business, services, and data),   remember that only "tiers" imply physical separation. It's common   allocate more than one layer on the same physical machine (same tier).   You can think of the term "tier" as referring to   physical distribution as "2 tiers", "3 tiers" and "n tiers".

Source: Microsoft Application Architecture Guide - Layered Application - Notes .

Of course, Microsoft has not invented this, but is only taking advantage of long-defined concepts.

    
09.09.2014 / 23:43