Event-driven architecture
Chọn pattern trước: request/response, event processing hay workflow orchestration. Lambda cần timeout, memory, concurrency, execution role, retry và idempotency. API Gateway chỉ là front door; messaging/event services có semantics khác nhau.
Bài tập
Thiết kế ba flow: API synchronous, S3 upload asynchronous và payment workflow. Ghi duplicate event, retry/DLQ, timeout, state và observability. Một flow đạt chuẩn phải mô tả cả khi downstream lỗi.
Bài giảng chuyên sâu
Serverless cần semantics của event và retry
API synchronous cần timeout và response contract; S3 upload có thể kích hoạt Lambda asynchronous; payment workflow cần state/orchestration. Lambda có timeout, memory, concurrency, execution role và retry behavior; API Gateway chỉ là front door. SQS, SNS, EventBridge và Step Functions giải quyết queue, fan-out/event routing và workflow khác nhau.
Retry có thể tạo duplicate side effect. Handler phải idempotent bằng event id/order id hoặc conditional write; lỗi không retry được cần DLQ. Concurrency và downstream limit phải được ghép vào thiết kế, nếu không scale tự động sẽ biến thành overload.
Bài tập: vẽ ba flow sync/async/workflow, đánh dấu timeout, retry, idempotency key, DLQ, IAM role và metric. Failure drill: duplicate event, downstream timeout và poison message.