Understanding 3-Tier Architecture
Modern web applications are often designed using a layered structure to separate responsibilities and improve maintainability. One of the most common patterns is the 3-tier architecture. This approach divides an application into three distinct layers: the presentation tier, the application tier (aka. logic tier), and the data tier. Each tier handles a specific aspect of the application, allowing developers to isolate and manage concerns more effectively.
As you build websites using Express, EJS, and PostgreSQL this semester, you are effectively implementing a 3-tier architecture. Understanding the roles of these layers — and how they relate to both the request-response lifecycle and other architectural models — will help you design and reason about your application more clearly.
The Three Tiers of Web Applications
Presentation Tier (Client-Facing Interface)
The presentation tier is what users see and interact with. In a web application, this usually means HTML, CSS, and JavaScript rendered in the browser. In our setup, EJS templates are used to generate this content on the server side, so even though the output appears client-side, it is generated by the server before being sent to the user.
This layer is responsible for presenting data to the user and capturing input. It does not make decisions or manage data directly — it relies on the application tier for that.
Application Tier (Business Logic and Routing)
This is the core of your application, where logic lives. In your Express-based web application, the application tier receives HTTP requests, routes them to the appropriate handlers, processes user input, interacts with the database, and determines which views (EJS templates) to render. It acts as the intermediary between the user interface and the data.
By separating this logic from both the user interface and the database, the application tier ensures that your app is easier to maintain and scale.
Data Tier (Persistent Storage)
The data tier is where information is stored, retrieved, and managed. PostgreSQL serves this role in our projects. It holds all persistent data such as users, posts, comments, and more. The application tier sends queries to the database and uses the results to construct dynamic responses.
Although it is common to depict the database as a separate server, it can also reside on the same server as the application logic. What matters is that its responsibility is distinct — it handles long-term data storage and retrieval, not user interaction or logic.
How This Relates to the Request-Response Lifecycle
You are already familiar with the request-response lifecycle. Now let's see how the three-tier architecture maps onto this process that happens with every user interaction:
-
Browser Request (Presentation Tier)
When a user clicks a link or submits a form in their browser, an HTTP request is sent to your server.
-
Express Server Processing (Application Tier)
Your Express.js application receives and processes this request, applying business rules and logic.
-
Database Interaction (Data Tier)
If needed, your Express application queries the PostgreSQL database to retrieve or modify data.
-
View Generation (Application → Presentation)
Express then uses EJS templates to transform the data into HTML.
-
Browser Display (Presentation Tier)
Finally, the server sends the HTML response to the browser, which renders it for the user to see.
Each tier plays a distinct role in this lifecycle, making it easier to understand how data flows through your application. By recognizing exactly where in this flow specific functionality belongs, you can maintain cleaner code organization and make your application easier to debug and extend.
Comparing to Other Architectures
While 3-tier architecture is common, it is not the only approach. Some applications use a 2-tier architecture where the client communicates directly with the database, usually in desktop applications or intranet tools. Others use n-tier architectures, where additional layers like caching, authentication, or API gateways are added for performance or complexity management.
Understanding 3-tier architecture not only helps you grasp the foundational structure of modern web applications but also equips you to recognize and adapt to variations like 2-tier or n-tier models. This knowledge prepares you for designing more advanced systems future courses or your career.
Why This Model Matters
The 3-tier model promotes separation of concerns, making your code easier to organize and test. If something breaks, it is easier to locate the problem within the correct tier. It also enables scalability — each tier can be scaled independently as your application grows.
As you develop your project with Express, EJS, and PostgreSQL, consider how each part of your code fits into this model. Recognizing which tier each responsibility belongs to will improve your architecture and design decisions going forward.
Additional Reading
Consider exploring videos or using AI to learn more about this topic. For further reading, check out these articles: