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

API Gateway

Microservice-এর সামনে — single front door।

📝 কুইজে যান

আপনার একটি app-এর backend-এ ৫০টি microservice। Mobile app যদি প্রতিটির সাথে আলাদাভাবে যোগাযোগ করে — auth, retry, error handling সব duplicate। সমাধান: একটি API Gateway সামনে; সব request সেখানে আসে; gateway সঠিক service-এ forward করে।

API Gateway কী?

API Gateway = একটি reverse proxy যা client request নেয়, multiple backend service-এ route করে, এবং response client-এ ফেরত দেয়। Microservice আর্কিটেকচার-এ standard pattern।

Without API Gateway

[Client] ↓ ↓ ↓ ↓ ↓ (50 connections) [Service 1] [Service 2] [Service 3] ... [Service 50]

সমস্যা:

  • Client-এ সব service-এর knowledge — tight coupling।
  • Authentication প্রতিটি service-এ।
  • Cross-cutting concerns scattered।
  • Network call multiplied।

With API Gateway

[Client] ↓ [API Gateway] ↓ ↓ ↓ ↓ ↓ [Service 1] [Service 2] ... [Service 50]

API Gateway-র দায়িত্ব

১. Routing

URL/header দেখে সঠিক service-এ forward।

  • /api/users/* → User Service
  • /api/orders/* → Order Service

২. Authentication & Authorization

JWT verify, OAuth — gateway-তে centralized।

৩. Rate Limiting

Per-user, per-IP throttle। DDoS protection।

৪. Caching

Frequent response cache।

৫. Request/Response Transformation

Old client compatibility, format conversion।

৬. Aggregation

Multiple service-এর response merge করে এক response (BFF pattern)।

৭. Logging & Monitoring

Centralized request log, metrics।

৮. SSL Termination

HTTPS terminate; backend plain HTTP।

৯. Circuit Breaker

Failed service কে route না করা।

১০. Versioning

v1, v2 API support।

BFF Pattern (Backend For Frontend)

Different client-এর জন্য আলাদা gateway:

[Mobile App] → [Mobile BFF] ─┐ [Web App] → [Web BFF] ─┼→ [Microservices] [Smart TV] → [TV BFF] ─┘
  • প্রতিটি client-এর needs আলাদা।
  • Mobile কম data; web বেশি information।
  • BFF aggregates ও tailors response।
  • Kong: Open-source, plugin-rich।
  • AWS API Gateway: Managed, serverless integration।
  • Azure API Management: Enterprise।
  • Google Cloud Apigee: Full lifecycle management।
  • Tyk: Open-source, lightweight।
  • Express Gateway: Node.js based।
  • Spring Cloud Gateway: Java/Spring।
  • Envoy/Istio: Service mesh-এও।

API Gateway vs Load Balancer vs Reverse Proxy

Load Balancer

  • L4/L7 traffic distribute
  • Identical instance-এ
  • Simple routing
  • No business logic

Reverse Proxy

  • Request forwarding
  • Caching, SSL
  • Single backend often
  • NGINX classic

API Gateway

  • Microservice routing
  • Auth, rate limit, transform
  • API-aware
  • Aggregation

API Gateway = reverse proxy + extra API management features।

সুবিধা

  • Client simplification — single endpoint।
  • Cross-cutting concerns centralized।
  • Backend service refactor flexibility।
  • Centralized security।
  • Monitoring single point।
  • Aggregation reduces client roundtrip।

Challenges

  • Single Point of Failure: Down = সব down। HA cluster দরকার।
  • Performance bottleneck: All traffic through gateway।
  • Latency: Extra hop।
  • Complexity: Configuration management।
  • Coupling risk: Gateway-এ business logic বেশি = anti-pattern।

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

  • Netflix Zuul: Pioneer API gateway।
  • Amazon: Custom gateway + AWS API Gateway public।
  • Uber: Internal gateway + edge proxy।
  • WeChat: Massive gateway handles billion+ daily।

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

  1. "Gateway = ESB": Gateway lightweight; ESB heavyweight।
  2. "Business logic in gateway": Anti-pattern — service-এ থাকা উচিত।
  3. "Single gateway সব্যবস্থায়": BFF pattern multiple gateway suggest করে।
  4. "Mandatory": Single-service-এ overkill।

Best Practices

  • Gateway lightweight রাখুন — only routing, auth, cross-cutting।
  • Business logic backend service-এ।
  • HA cluster — multiple gateway instance।
  • Caching aggressive।
  • Per-route rate limit configure।
  • BFF pattern multiple client থাকলে।
  • Monitor latency — gateway slow হলে সবাই slow।

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

  • API Gateway = microservice-এর single front door।
  • Routing, auth, rate limit, aggregation, monitoring।
  • BFF pattern multiple client-এর জন্য।
  • Kong, AWS API Gateway, Tyk — top tools।
  • HA + lightweight = success।