Database System Architecture — 3-Tier & ANSI/SPARC
Database আর্কিটেকচার — 3-tier ও ANSI/SPARC
1. Why Architecture Matters
When a Pathao rider in Sylhet opens the app to accept a ride, his phone makes a network call to a server in a Singapore data center. That server hits a PostgreSQL database that may itself be replicated across three machines. From the rider's point of view it is a single tap. From the system's point of view it is a finely-layered architecture in which each layer hides complexity from the next.
This module gives you the vocabulary to think about that layered structure — the same vocabulary that every backend interview in Bangladesh uses. We will cover two complementary views: the tiered deployment architecture (1-tier, 2-tier, 3-tier) and the deeper ANSI/SPARC three-schema model from 1975 that explains why a DBMS even has these layers.
2. 1-Tier vs 2-Tier vs 3-Tier — Where Does the Database Sit?
"Tier" means a physical or logical layer of the system. The big question is: how many machines (or processes) does a request travel through before it reaches the database?
| Tier | Where it shines | Where it fails | বাংলায় |
|---|---|---|---|
| 1-Tier | Personal apps, prototypes, embedded SQLite (any phone app's local cache). | Multi-user, networked usage. | একজন ব্যবহারকারীর জন্য — যেমন SQLite যা প্রায় প্রতিটি Android অ্যাপে আছে। |
| 2-Tier | LAN-bound enterprise apps (1990s ERP, Tally, old POS). | Internet scale; client must hold credentials. | LAN-এ কাজ করে এমন GUI অ্যাপ; Internet-এ অসুরক্ষিত। |
| 3-Tier | Every modern web/mobile app — Pathao, Daraz, bKash, Facebook. | Slightly more latency; more moving parts. | আজকের প্রতিটি ওয়েব/মোবাইল অ্যাপ — Pathao, Daraz, bKash। |
3. The ANSI/SPARC Three-Schema Model (1975)
Tiered architecture talks about where code runs. ANSI/SPARC talks about how the data description is layered. It says every database has exactly three views, and the DBMS's job is to translate between them.
Three layers, each more abstract than the one below it:
- External (View) schema — what each user role sees. A bank cashier sees one set of columns; the auditor sees another; the customer sees only their own balance. Many external schemas can sit on top of one conceptual schema.
- Conceptual (Logical) schema — the single, complete description of the business: which tables exist, which columns, which constraints, which foreign keys. There is exactly one of these.
- Internal (Physical) schema — how the data is actually laid out on disk: B+tree indexes, page sizes, file paths, compression, WAL.
Let us see this in code. Below we create a single conceptual schema (an account table), then
build two external schemas (views) on top — one for cashiers, one for auditors. Each user sees a different
slice of the same underlying data. Internal storage stays hidden.
-- External schema 1: what the cashier sees
SELECT * FROM cashier_view;
-- External schema 2: what the auditor sees
SELECT * FROM auditor_view;
4. The Whole Point — Data Independence
ANSI/SPARC's three layers are not just an academic chart. They exist to make change possible. The promise is called data independence, and it comes in two flavours:
| Type | What can change | Without breaking | বাংলায় |
|---|---|---|---|
| Physical data independence | Add an index, switch from a heap to a clustered file, move to SSD. | Existing application code. | Internal-এ পরিবর্তন করলেও application-কে পুনরায় লিখতে হয় না। |
| Logical data independence | Add a new column, split a table into two, drop a column. | Existing user views. | Conceptual schema বদলালেও পুরোনো view-এর users কিছু টের পান না। |
In 2023, when bKash added a new "merchant_category" column to its transaction table, the cashier app kept running unchanged — its view did not include the new column. That is logical data independence in real life. A flat-file system would have required every consumer program to be re-deployed.
২০২৩ সালে bKash যখন transaction টেবিলে নতুন column যোগ করেছে, cashier app-এর কোড কিছুই পাল্টায়নি — কারণ তাদের view-এ ওই column ছিল না। এটিই বাস্তবে logical data independence।
5. Schema vs Instance — Two Words, Two Meanings
Beginners often confuse these two terms because in everyday Bangla and English they sound similar. Precision here will save you in interviews and in production debugging.
📐 Schema (the design)
The structure of the database — table names, column names, types, keys, constraints. It changes rarely (months/years).
- Lives in the data dictionary.
- Defined by
CREATE TABLE,ALTER TABLE. - Same for every backup of the database.
🧾 Instance (the data)
The actual rows stored at this moment. It changes continuously (every INSERT, every UPDATE).
- Different at 10:00 AM and 10:01 AM.
- Defined by
INSERT,UPDATE,DELETE. - Each backup captures one instance.
-- Schema lives in sqlite_master (every DBMS has a similar dictionary)
SELECT name, sql
FROM sqlite_master
WHERE type = 'table';
-- Instance is the actual rows right now
SELECT * FROM student;
6. Inside a DBMS — Storage, Query, Transaction Managers
When you run a single line — SELECT * FROM student WHERE roll=101 — what really happens?
Inside any production DBMS, your query is handed off through several specialised modules. Knowing them
by name is the difference between writing SQL and understanding SQL.
- Query processor — parses your SQL, validates names, rewrites the query, and the optimizer picks the cheapest execution plan (which index, which join order).
- Execution engine — actually runs the plan, calling the storage manager to fetch rows.
- Transaction manager — ensures ACID: groups multiple statements into atomic units, takes locks, writes the redo log so a crash cannot lose committed work.
- Storage manager — owns the disk: pages, the buffer pool (RAM cache of recent pages), B+tree indexes, and the journal/WAL file.
7. Client–Server in a Modern Web App
In a typical Bangladesh fintech stack — say a Daraz checkout — here is the path of a single click:
- The browser sends an HTTPS request to
api.daraz.com.bd. - An NGINX load balancer routes it to one of dozens of Node.js / Spring Boot app servers.
- The app server runs business rules, then opens a connection from a pooled set to PostgreSQL.
- PostgreSQL's query processor compiles the SQL and the storage manager fetches rows from a B+tree.
- Results stream back through the same chain, transformed into JSON for the browser.
Every layer hides what the layer above does not need to know. The browser does not know about indexes; the app server does not know about disk pages; the DBMS does not know which rider clicked which button. That is the entire art of architecture.
প্রতিটি স্তর তার উপরের স্তরের কাছ থেকে complexity লুকিয়ে রাখে — এই lukanonই আসলে architecture।
8. Glossary (শব্দকোষ)
| Term | Meaning | বাংলায় |
|---|---|---|
| Tier | A physical/logical layer in deployment. | Deployment-এর একটি স্তর। |
| External schema (View) | What one user role sees. | একজন user যা দেখে। |
| Conceptual schema | The single global table-and-constraint design. | পুরো database-এর design। |
| Internal schema | Physical storage structures. | Disk-এ data কীভাবে রাখা। |
| Physical data independence | Internal changes do not break apps. | Internal পরিবর্তনে app ভাঙে না। |
| Logical data independence | Conceptual changes do not break views. | Conceptual পরিবর্তনে view ভাঙে না। |
| Schema | The design — rarely changes. | Design — কালেভদ্রে পাল্টায়। |
| Instance | The actual rows now — changes constantly. | এই মুহূর্তের rows — সারাক্ষণ পাল্টায়। |
| Buffer pool | RAM cache of recently-used pages. | সম্প্রতি ব্যবহৃত page-এর RAM cache। |
| WAL | Write-ahead log — durability guarantee. | Write-ahead log — durability-র ভিত্তি। |
9. Practice Problems
Try, then click Show Answer. Several answers contain runnable SQL.
-
Classify each app: (a) MS Access on a personal laptop, (b) Tally ERP over a LAN, (c) Daraz mobile app — which tier?প্রতিটি অ্যাপকে tier দিন: (ক) ব্যক্তিগত MS Access, (খ) LAN-এ Tally ERP, (গ) Daraz মোবাইল অ্যাপ।
✨ Show Answer
Answer: (a) 1-tier, (b) 2-tier, (c) 3-tier.
(ক) 1-tier, (খ) 2-tier, (গ) 3-tier।
-
Create a base table and two views — one for a Pathao rider (sees pickup/dropoff only) and one for the analytics team (sees fare too).একটি base টেবিল ও দুটি view বানান — একটি Pathao রাইডারের জন্য (শুধু pickup/dropoff), আরেকটি analytics-এর জন্য (fare সহ)।
✨ Show Answer
ans2.sqlCREATE VIEW rider_view AS SELECT rid, pickup, dropoff, status FROM ride; CREATE VIEW analytics_view AS SELECT rid, pickup, dropoff, fare, status FROM ride; SELECT * FROM rider_view; SELECT * FROM analytics_view; -
Explain the difference between physical and logical data independence in your own words.নিজের ভাষায় physical ও logical data independence-এর পার্থক্য লিখুন।
✨ Show Answer
Answer: Physical = changing how data is stored (indexes, files) without breaking applications. Logical = changing what tables/columns exist (conceptual schema) without breaking existing user views.
Physical = ভেতরের সংরক্ষণ পাল্টালেও application ঠিক থাকে। Logical = conceptual schema পাল্টালেও পুরোনো view ভাঙে না।
-
Demonstrate logical data independence: add a new column to a table and prove an old view still works.Logical data independence প্রমাণ করুন — table-এ নতুন column যোগ করেও পুরোনো view যেন ঠিক চলে।
✨ Show Answer
ans4.sql-- Schema change: add a column the old app does not know about ALTER TABLE customer ADD COLUMN phone TEXT; UPDATE customer SET phone = '01711-000001' WHERE cid = 1; -- Old app's view is unaffected SELECT * FROM old_app_view; -
Why does a 2-tier client–server design struggle on the public Internet?2-tier client–server পাবলিক Internet-এ কেন ভেঙে পড়ে?
✨ Show Answer
Answer: The client must hold DB credentials (security risk), business logic ends up duplicated across clients, you cannot easily change the schema without redeploying every client, and DB connections are expensive to keep open per user. A 3-tier app server centralises all of this.
প্রতিটি client-এ DB credential থাকতে হয় (নিরাপত্তা ঝুঁকি), business logic বহু client-এ ছড়ানো, schema বদলালে সব client পুনরায় deploy করতে হয়, প্রতি user-এর DB connection ব্যয়বহুল। 3-tier app server এই সব কেন্দ্রীভূত করে।
-
List the rows of a tiny table, then show its schema definition. Confirm both come from the same DB.একটি ছোট টেবিলের rows ও তার schema একই DB থেকে দেখান।
✨ Show Answer
ans6.sql-- Instance (rows) SELECT * FROM book; -- Schema (definition stored by the DBMS) SELECT sql FROM sqlite_master WHERE name = 'book'; -
Match each component to its job: query optimizer, buffer pool, transaction manager, parser.প্রতিটি component-এর কাজ মেলান।
✨ Show Answer
Answer:
- Parser — turns SQL text into a syntax tree.
- Query optimizer — picks the cheapest plan (which index, which join order).
- Buffer pool — keeps recently-used disk pages in RAM.
- Transaction manager — locks, commits, rolls back to enforce ACID.
Parser → SQL text-কে গাছে পরিণত করে। Optimizer → সবচেয়ে কম খরচের plan বেছে নেয়। Buffer pool → page গুলোকে RAM-এ রাখে। Transaction manager → lock, commit, rollback সামলায়।
-
Explain why a 3-tier architecture is friendlier to scaling than 2-tier.3-tier আর্কিটেকচার scale-এ যাওয়া কেন সহজ — ব্যাখ্যা করুন।
✨ Show Answer
Answer: The middle tier (app server) is stateless, so you can run many copies behind a load balancer. The DB tier can be scaled separately by replication or sharding. Clients are thin — phones and browsers — and can be updated without touching the database. This separation of concerns is what lets bKash handle 10k+ requests per second.
মাঝের app server stateless — load balancer-এর পেছনে অনেক কপি চালানো যায়। DB স্তর আলাদাভাবে replication/sharding-এ scale করা যায়। Client পাতলা — DB ছোঁয়া ছাড়াই আপডেট সম্ভব। এ কারণেই bKash সেকেন্ডে ১০ হাজার+ request সামলাতে পারে।
Summary — Module 03
A modern web app is a 3-tier system: client, app server, DBMS. Inside the DBMS, ANSI/SPARC's three-schema model separates each user's view from the global conceptual schema and from the physical storage details, giving us logical and physical data independence. Schema is the design and changes rarely; instance is the rows and changes constantly. The DBMS itself is built from a query processor, an execution engine, a transaction manager, and a storage manager that together translate one SQL line into actual disk I/O.