3-Tier Architecture
Tags: architecture, linux, beginners, devops
Published: 2022-11-09 15:22:32

Three-tier architecture is a well-established software application architecture that organizes applications into three logical and physical computing tier, the presentation tier, or user interface; the application tier, where data is processed, and the data tier, where the data associated with the application is stored and managed.

It is more complex than the 2-tier client-server computing model, because it is more difficult to build a 3-tier application compared to a 2-tier application. The physical separation of application servers containing business logic functions and database servers containing databases may be something that affects performance.

The diagram for a three-tier architecture,



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hf5lsy0swd48tf6gm76m.png)


**Presentation  Layer** 

The request from the external loadbalancer will refer to either of the web servers because it is the topmost layer, which the user can access directly. The request is forwarded to the second live server if one web server is offline.  It is responsible to communicate with the application server to provide output to the user end.-


**Application Layer**

It regulates the fundamental operations of the application by carrying out careful processing. The database layer and web layer are connected via the application layer. The application, which is used to exchange processed data, will be implemented in this layer. This layer is where all logical operations will take place.


**Database Layer**

An Oracle, MongoDB, MySQL, SQL, PostgreSQL, MariaDB, etc., can be used as the database layer. The database server will house all of the data. This increases security because only the application layer will have direct interface with the database layer. The database layer can leverage Innodb clusters to increase availability.

**Innodb Cluster**

The innodb cluster is used to increase the database's availability. It consists of numerous database servers with identical data in each database. The innodb cluster will respond appropriately to the request forwarded to it. Requests are sent to the other two active databases if one database fails. Only the application server will have the direct communication with the cluster that improves the security, no external request can directly access the db cluster.

## Work Flow

1. The request from the user passes through the firewall to the external loadbalancer.

2. The external load balancer will send request to anyone of the healthy webserver.The load balancer will route requests to the other web server if one web server is down or has too many requests.Httpd, nginx can  be be used as an web server to server the incoming requests.

3. Webserver pass the request to the internal loadbalancer(Haproxy) that will handles the incoming requests.

4. From the internal loadbalancer the request will be send to the application server. As we discussed earlier the internal loadbalancer have some logic to send traffic to the suitable application server(depends on the loadbalancer configuration). Also we can restrict sending request to app server using reverse proxy.

5. The Application loadbalancer will be interconnected with the innobd cluster to store and retrieve data from the database. Application server will only have direct communication with the database.

 
**Advantages:**

1) As a result of the application servers' ability to be 
  installed on numerous machines, increased scalability is the 
  primary three-tier benefit.


2) Balancing of load is much easier with division of core 
   business from the server of the database.

3) Improve security and data integrity. Business logic is more  
   secure because it is stored on a secure central server

4) High scalability due to the tiers are based on the 
   deployment of layers, scaling out an application is 
   reasonably straightforward.

**Disadvantages:**

1) A separate proxy server may be required.

2) Network traffic will be increased if a separate proxy 
   server is used.

3) The physical separation of application servers containing   
   business logic functions and database servers containing 
   databases may be something that affects performance.

4) Increased complexity