Nâng CaoAWS & Cloud iconAWS & Cloud

Serverless architecture patterns là gì? Giải thích các pattern phổ biến: API + Lambda, event-driven, saga pattern.

Serverless architecture tận dụng managed services loại bỏ server management: Lambda (compute), API Gateway (HTTP routing), DynamoDB (database), S3 (storage), SQS/SNS/EventBridge (messaging), Cognito (auth), Step Functions (orchestration).

Pattern 1 — REST API: API Gateway → Lambda → DynamoDB; ưu điểm: không manage server, auto-scale, pay-per-request; nhược: cold start, 29s timeout API Gateway, stateless.

Pattern 2 — Event-driven microservices: services communicate qua EventBridge/SQS/SNS thay vì direct HTTP call; mỗi service là Lambda subscribe event, emit event sau khi xử lý; loosely coupled, independently deployable và scalable; phức tạp debugging (distributed transaction tracking cần X-Ray + correlation IDs).

Pattern 3 — Saga pattern cho distributed transactions: mỗi service local transaction + compensating transaction; Choreography-based saga: mỗi step publish event, next step subscribe và trigger — decentralized nhưng khó monitor; Orchestration-based saga: Step Functions orchestrate toàn bộ flow, mỗi bước có compensating step nếu fail — centralized, dễ debug hơn, preferred trên AWS.

Pattern 4 — BFF (Backend for Frontend): Lambda functions riêng tối ưu cho từng client type (mobile, web, third-party API).

Pattern 5 — CQRS + Event Sourcing: DynamoDB Stream trigger Lambda cập nhật read model.

Anti-patterns serverless: long-running computation (>15 phút), large file processing inline (dùng S3 trigger + async), database connection pooling (dùng RDS Proxy).

Xem toàn bộ AWS & Cloud cùng filter theo level & chủ đề con.

Mở danh sách AWS & Cloud