CSE Roadmap

Common tier · about 2 hours · 5 parts

Part 3 of 5 · 1 min read

3-tier architecture

Adding an application-layer server between the client and the database.

Think of the same clerk's desk, but now a second worker sits between the clerk and the archive. That second worker takes every request, applies the shop's own rules, and only then talks to the archive.

In plain words: a 3-tier architecture adds a middle layer, the application server, between the client and the database. The client talks only to the application server, usually over an API. The application server holds the business logic and is the only thing that connects to the database. The database itself stays the third tier, unchanged in role from the 2-tier picture.

A worked example. A modern bookstore website has a browser (the client tier), a web server running the bookstore's own code (the application tier), and the database (the data tier). The browser never sees a database connection string. It only calls the application server's API, such as POST /orders, and the application server is the one place that checks a discount before writing the order.

The key lines.

# client tier
response = http_post("/orders", {"customer_id": 107, "book_id": 42})

# application tier (runs on the server, not the client)
def post_orders(customer_id, book_id):
    if not discount_is_valid(customer_id):
        return error("invalid discount")
    db.execute("INSERT INTO orders (customer_id, book_id) VALUES (%s, %s)", customer_id, book_id)

3-tier architecture, application server

A 3-tier architecture is a system made of three layers: a client, an application server holding the business logic, and a database. An application server is the middle tier. It is the only layer that connects directly to the database.

Example: the bookstore website's web server, which checks discounts and then writes to the database on the browser's behalf, is the application server in a 3-tier system.