Database System Architecture — 3-Tier & ANSI/SPARC

Database আর্কিটেকচার — 3-tier ও ANSI/SPARC

Read: ~30 min Beginner 8 practice problems Architecture

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.

যখন সিলেটের একজন Pathao রাইডার ride accept করেন, তার ফোন থেকে রিকোয়েস্ট যায় Singapore-এর সার্ভারে, সেখান থেকে database-এ। ব্যবহারকারীর কাছে সব এক tap, কিন্তু পেছনে অনেক layer। এই module-এ আমরা শিখব dবেoplyment-এর tier (1/2/3) এবং ANSI/SPARC-এর তিনটি schema — যা এই layer-গুলোর ভিত্তি।

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?

1-Tier (একটিই মেশিন) UI · App · DB all in one e.g. MS Access single .mdb / .sqlite For one user, one PC. 2-Tier (Client–Server) Client app (thick GUI) DB Server (SQL only) SQL-talking GUI app (legacy banking, ERP) 3-Tier (আজকের ওয়েব অ্যাপ) Browser / Mobile app App Server (API, business) DB Server (PostgreSQL/MySQL) Pathao, bKash, Daraz — all live here. Figure 3.1 — Tier-এর সংখ্যা যত বেশি, scale-এ যাওয়া তত সহজ।
TierWhere it shinesWhere it failsবাংলায়
1-TierPersonal apps, prototypes, embedded SQLite (any phone app's local cache).Multi-user, networked usage.একজন ব্যবহারকারীর জন্য — যেমন SQLite যা প্রায় প্রতিটি Android অ্যাপে আছে।
2-TierLAN-bound enterprise apps (1990s ERP, Tally, old POS).Internet scale; client must hold credentials.LAN-এ কাজ করে এমন GUI অ্যাপ; Internet-এ অসুরক্ষিত।
3-TierEvery modern web/mobile app — Pathao, Daraz, bKash, Facebook.Slightly more latency; more moving parts.আজকের প্রতিটি ওয়েব/মোবাইল অ্যাপ — Pathao, Daraz, bKash।
1-tier: সব এক মেশিনে। 2-tier: client সরাসরি DB-তে কথা বলে — ছোট LAN-এ। 3-tier: মাঝে একটি app server, যা business logic, security, scaling সব সামলায় — আজকের সব serious system এই pattern-এ।

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.

External Schema (View 1) Cashier sees: name, balance External Schema (View 2) Auditor sees: txn log + dates External Schema (View 3) Manager sees: summary totals ↕ logical-to-external mapping Conceptual Schema (one global model) customer, account, transaction, branch — tables, columns, FK rules ↕ conceptual-to-internal mapping Internal Schema (physical storage) B+tree indexes · pages on SSD · WAL files · compression Figure 3.2 — ANSI/SPARC তিন স্তর: External (যে যা দেখে), Conceptual (পুরো model), Internal (physical সংরক্ষণ)।

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.
ANSI/SPARC বলে — প্রতিটি ডাটাবেসের তিনটি স্তর আছে। (১) External: প্রতিটি ব্যবহারকারী যা দেখে (cashier আলাদা, auditor আলাদা)। (২) Conceptual: পুরো ব্যবসার একটিমাত্র মডেল — কোন টেবিল, কোন column, কোন constraint। (৩) Internal: ডিস্কে আসলে কীভাবে রাখা — B+tree, page, 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.

three_schemas.sql
-- 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:

TypeWhat can changeWithout breakingবাংলায়
Physical data independenceAdd an index, switch from a heap to a clustered file, move to SSD.Existing application code.Internal-এ পরিবর্তন করলেও application-কে পুনরায় লিখতে হয় না।
Logical data independenceAdd a new column, split a table into two, drop a column.Existing user views.Conceptual schema বদলালেও পুরোনো view-এর users কিছু টের পান না।
Why this matters in production
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।
Physical: ভেতরে কীভাবে রাখা — index, page, file format — পাল্টালেও application হাত দিতে হয় না। Logical: conceptual schema-তে নতুন column যোগ করলেও পুরোনো user view ভাঙে না।

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 মানে database-এর "ডিজাইন" — কোন টেবিল, কোন column, কোন type। এটি কালেভদ্রে পাল্টায়। Instance মানে এই মুহূর্তে যে rows আসলে আছে — যা প্রতি সেকেন্ডে পাল্টাচ্ছে।
schema_vs_instance.sql
-- 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.

Client / API sends SQL string Query Processor parser · planner · optimizer Execution Engine runs the chosen plan Transaction Manager ACID · locks · log Storage Manager buffer pool · pages · indexes Disk: data files · WAL / journal B+tree pages, redo log, sorted runs Figure 3.3 — একটি SQL query DBMS-এর ভিতরে কোন কোন module-এর মধ্য দিয়ে যায়।
  • 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.
একটি SQL query DBMS-এ ঢুকে আগে parser-এ যায়, তারপর optimizer সবচেয়ে কম খরচের plan বেছে নেয়, execution engine তা চালায়, transaction manager লক ও log সামলায়, এবং storage manager disk থেকে page এনে দেয়। এই পাঁচ module-ই মিলে আপনার এক লাইন SQL-কে answer-এ পরিণত করে।

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:

  1. The browser sends an HTTPS request to api.daraz.com.bd.
  2. An NGINX load balancer routes it to one of dozens of Node.js / Spring Boot app servers.
  3. The app server runs business rules, then opens a connection from a pooled set to PostgreSQL.
  4. PostgreSQL's query processor compiles the SQL and the storage manager fetches rows from a B+tree.
  5. Results stream back through the same chain, transformed into JSON for the browser.
Key takeaway
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।
Daraz-এর একটি click পেছনে চলে: browser → NGINX → app server → PostgreSQL → B+tree page → আবার back। প্রতিটি স্তর শুধু পরের স্তরকে চেনে।

8. Glossary (শব্দকোষ)

TermMeaningবাংলায়
TierA physical/logical layer in deployment.Deployment-এর একটি স্তর।
External schema (View)What one user role sees.একজন user যা দেখে।
Conceptual schemaThe single global table-and-constraint design.পুরো database-এর design।
Internal schemaPhysical storage structures.Disk-এ data কীভাবে রাখা।
Physical data independenceInternal changes do not break apps.Internal পরিবর্তনে app ভাঙে না।
Logical data independenceConceptual changes do not break views.Conceptual পরিবর্তনে view ভাঙে না।
SchemaThe design — rarely changes.Design — কালেভদ্রে পাল্টায়।
InstanceThe actual rows now — changes constantly.এই মুহূর্তের rows — সারাক্ষণ পাল্টায়।
Buffer poolRAM cache of recently-used pages.সম্প্রতি ব্যবহৃত page-এর RAM cache।
WALWrite-ahead log — durability guarantee.Write-ahead log — durability-র ভিত্তি।

9. Practice Problems

Try, then click Show Answer. Several answers contain runnable SQL.

আগে চেষ্টা করুন, তারপর Show Answer দেখুন।
  1. 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।

  2. 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.sql
    CREATE 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;
  3. 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 ভাঙে না।

  4. 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;
  5. 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 এই সব কেন্দ্রীভূত করে।

  6. 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';
  7. 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 সামলায়।

  8. 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.

আজকের web app হলো 3-tier — client, app server, DBMS। DBMS-এর ভেতরে ANSI/SPARC তিনটি schema আলাদা রাখে: external (যে যা দেখে), conceptual (পুরো design), internal (physical storage)। এই স্তরগুলো dেয় logical ও physical data independence। Schema আর instance — design আর rows — দুটোকে গুলিয়ে ফেলবেন না। আর DBMS-এর ভেতরে query processor, execution engine, transaction manager ও storage manager — চারটি বিভাগ মিলে আপনার SQL-কে disk I/O-তে অনুবাদ করে।

Next Module → Data Models — Hierarchical, Network, Relational, Object ও NoSQL — কোনটি কখন কাজে লাগে।