The architecture of Database can be 2-tier or 3 tier architecture based on how users are connected to the database to get their request done. They can either directly connect to the database or their request is received by the intermediary layer, which synthesizes the request and then it sends to the database. The architecture of Database is described in details below:
Table of Contents
2-tier Architecture of Database
In 2-tier architecture, the application program directly interacts with the database. There will not be any user interface or the user involved with database interaction. Imagine a front end application of School, where we need to display the reports of all the students who are opted for different subjects. In this case, the application will directly interact with the database and retrieve all the required data. Here no inputs from the user are required. This involves the 2-tier architecture of the database.
Let us consider another example of the two-tier architecture of database. Consider a railway ticket reservation system. How does this work? Imagine a person is reserving the ticket from Delhi to Goa on a particular day. At the same time, another person in some other place of Delhi is also reserving the ticket to Goa on the same day for the same train. Now there is a requirement for two tickets, but for different persons. What will the reservation system do? It takes the request from both of them and queues the requests entered by each of them. Here the request entered to the application layer and request is sent to the database layer. Once the request is processed in the database, the result is sent back to the application layer for the user.
Advantages of 2-tier Architecture
- Easy to understand as it directly communicates with the database.
- Requested data can be retrieved very quickly when there are fewer users.
- Easy to modify – any changes required, directly requests can be sent to the database
- Easy to maintain – When there are multiple requests, it will be handled in a queue and there will not be any chaos.
Disadvantages of 2-tier Architecture:
- It would be time-consuming when there is a huge number of users. All the requests will be queued and handed one after another. Hence it will not respond to multiple users at the same time.
- This architecture would little cost-effective.
3-tier Architecture of Database
The 3-tier architecture is the most widely used database architecture. It can be viewed below.
- The presentation layer / User layer is the layer where the user uses the database. He does not have any knowledge about the underlying database. He simply interacts with the database as though he has all data in front of him. You can imagine this layer as a registration form where you will be inputting your details. Did you ever guess, after pressing the ‘submit’ button where the data go? No right? You just know that your details are saved. This is the presentation layer where all the details from the user are taken, sent to the next layer for processing.
- The application layer is the underlying program that is responsible for saving the details that you have entered and retrieving your details to show up on the page. This layer has all the business logic like validation, calculations, and manipulations of data, and then sends the requests to the database to get the actual data. If this layer sees that the request is invalid, it sends back the message to the presentation layer. It will not hit the database layer at all.
- The data layer or Database layer is the layer where the actual database resides. In this layer, all the tables, their mappings, and the actual data present. When you save you details from the front end, it will be inserted into the respective tables in the database layer, by using the programs in the application layer. When you want to view your details in the web browser, a request is sent to the database layer by the application layer. The database layer fires queries and gets the data. These data are then transferred to the browser (presentation layer) by the programs in the application layer.
Advantages of 3-tier architecture:
- Easy to maintain and modify. Any changes requested will not affect any other data in the database. The application layer will do all the validations.
- Improved security. Since there is no direct access to the database, data security is increased. There is no fear of mishandling the data. The application layer filters out all the malicious actions.
- Good performance. Since this architecture cache, the data once retrieved, there is no need to hit the database for each request. This reduces the time consumed for multiple requests and hence enables the system to respond at the same time.
Disadvantages of 3-tier Architecture
Disadvantages of 3-tier architecture are that it is a little more complex and little more effort is required in terms of hitting the database.
In this tutorial, we read about the architecture of database. We will cover more topics on database in the next articles.