Part 2 of 5 · 1 min read
2-tier architecture
A client talking directly to a database, and why that gets hard to maintain.
Think of a single clerk who both talks to customers and personally fetches every file from the archive. The clerk's desk and the archive are the only two things in the picture.
In plain words: a 2-tier architecture has a client and a database, with no separate layer in between. The client program connects straight to the database and sends SQL to it directly. Business rules, such as "an order needs a valid customer," live inside the client program itself, or inside the database as triggers and constraints.
A worked example. An early desktop bookstore application, installed on each employee's computer, connects straight to the shared database server over the network. Every computer running the application needs its own database credentials and its own copy of the business logic, such as the code that checks a discount is valid before applying it.
The key lines. A 2-tier client, shown as pseudocode rather than a full program, since the point is the direct connection, not any one language:
connection = connect_to_database(host, user, password)
rows = connection.execute("SELECT * FROM orders WHERE customer_id = 107")
2-tier architecture
A 2-tier architecture is a system made of exactly two layers: a client that holds the user interface and often the business logic, and a database that the client connects to directly.
Example: a desktop application that opens its own direct database connection, with no server in between, is 2-tier.