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-এ সব service-এর knowledge — tight coupling।
- Authentication প্রতিটি service-এ।
- Cross-cutting concerns scattered।
- Network call multiplied।
With API Gateway
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:
- প্রতিটি client-এর needs আলাদা।
- Mobile কম data; web বেশি information।
- BFF aggregates ও tailors response।
জনপ্রিয় Tools
- 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।
সাধারণ ভুল ধারণা
- "Gateway = ESB": Gateway lightweight; ESB heavyweight।
- "Business logic in gateway": Anti-pattern — service-এ থাকা উচিত।
- "Single gateway সব্যবস্থায়": BFF pattern multiple gateway suggest করে।
- "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।