Part 3 · আর্কিটেকচার 📖 ১২ মিনিট পড়া 📝 ২০টি কুইজ

N-tier Architecture

Application-কে আলাদা layer-এ ভাগ — পরিষ্কার responsibility।

📝 কুইজে যান

একটি রেস্টুরেন্টে ভাবুন: customer order দেন waiter-কে (UI), waiter rsoiyaghr-এ পাঠান (logic), রান্না হয় কাঁচামাল থেকে (data)। তিনটি স্তর — পরিষ্কার দায়িত্ব। কেউ অন্যের কাজে নাক গলায় না। এটাই N-tier Architecture

N-tier কী?

N-tier Architecture = software-কে N-সংখ্যক logical layer-এ ভাগ করা। প্রতিটি layer specific responsibility-তে কাজ করে এবং পরের layer-এর সাথে define-করা interface দিয়ে যোগাযোগ করে।

Tier vs Layer

  • Layer: Logical separation (code-এর organization)। একই machine-এ থাকতে পারে।
  • Tier: Physical separation (deployment unit)। আলাদা server-এ।

সব tier layer, কিন্তু সব layer tier নয়।

1-Tier (Single-tier)

সব কিছু এক জায়গায় — UI, logic, data এক executable-এ।

  • উদাহরণ: MS Word, Notepad — sole installation।
  • সুবিধা: সহজ, fast (no network)।
  • অসুবিধা: Multi-user difficult, scale impossible।

2-Tier (Client-Server)

Client + Server। Client UI ও কিছু logic; Server data ও back-end logic।

[Client App] ←→ [Database Server]
  • উদাহরণ: পুরাতন banking app, accounting software।
  • সুবিধা: Better than 1-tier, multi-user।
  • অসুবিধা: Business logic client ও server-এ ছড়ানো; update painful।

3-Tier — সবচেয়ে কমন

Web app-এর standard:

[Presentation Tier] ← Browser, mobile app ↓ [Application/Logic Tier] ← Business rules, API ↓ [Data Tier] ← Database, cache

Presentation Tier

UI/UX — যা user দেখে।

  • HTML/CSS/JS
  • Mobile native
  • React/Vue/Angular
  • কোনো business logic নেই

Application/Logic Tier

Business rule, validation, processing।

  • API server (Node.js, Django, Spring)
  • Authentication
  • Workflow logic
  • Data transformation

Data Tier

Persistence — data store ও retrieve।

  • RDBMS (PostgreSQL, MySQL)
  • NoSQL (MongoDB, Cassandra)
  • Cache (Redis)
  • File storage

3-tier-এর সুবিধা

  • Separation of concerns: Each layer-এর specific job।
  • Independent scaling: API server hot হলে শুধু সেটা scale।
  • Maintainability: এক layer-এর change অন্য-কে affect করে না।
  • Reusability: Same API multiple UI-তে (web, mobile)।
  • Security: DB direct exposed না — API behind।
  • Technology choice: Layer-wise different tech।

4-tier, 5-tier, N-tier

Modern web-এ আরও layer যোগ:

Common 4-tier

[Client] → [Web Tier] → [Application Tier] → [Data Tier]
  • Web tier: NGINX/Apache — static file, SSL, routing।
  • Application tier: business logic API।

Modern N-tier উদাহরণ

[CDN] → [Load Balancer] → [Web Tier] → [API Gateway] → [Microservices] → [Cache] → [DB]

Design Pattern Connection

MVC (Model-View-Controller)

  • View → Presentation tier
  • Controller → Application tier (entry)
  • Model → Data access logic

MVVM, MVP

Variants — কোনটি view ও logic আরও আলাদা করে।

বাস্তব উদাহরণ

Facebook (high-level)

  1. CDN (static)
  2. Load balancer
  3. Web tier (PHP/Hack)
  4. Service tier (microservices)
  5. Cache (Memcached, TAO)
  6. DB (MySQL, Cassandra)

Banking System

  1. Mobile/Web client
  2. API Gateway
  3. Business logic server
  4. Transaction processing
  5. Database (Oracle)

Anti-patterns

  1. Layer skip: UI সরাসরি DB call — bypassing logic tier।
  2. Logic in UI: Business rule presentation-এ — duplicated, hard to maintain।
  3. Logic in DB: অনেক stored procedure-এ business rule — testing/debug হারাম।
  4. Tight coupling: Layer-গুলো তীব্রভাবে depend — change cascading।

সাধারণ ভুল ধারণা

  1. "Tier ও layer একই": Layer logical, tier physical।
  2. "More tiers = better": না — overhead বাড়ে। যথেষ্ট দিয়ে শুরু।
  3. "Microservice replaces N-tier": Microservice-ও N-tier-এর extension।

Best Practices

  • 3-tier দিয়ে শুরু করুন — সবচেয়ে কমন।
  • Layer interface (API/contract) clearly define।
  • Layer skip করবেন না — discipline বজায় রাখুন।
  • Each tier-এ separate scaling strategy।
  • Stateless logic tier — horizontal scale-friendly।
  • Layer-এ technology change করতে ভয় পাবেন না (API contract intact থাকলে)।

📌 চ্যাপ্টার সারমর্ম

  • N-tier = software-কে N layer-এ ভাগ।
  • Layer logical, Tier physical।
  • 3-tier (Presentation, Logic, Data) সবচেয়ে কমন।
  • Separation of concerns + independent scaling।
  • Layer skip বা logic ভুল জায়গায় = anti-pattern।