Skip to content

Chương 38: Cloud Tasks — Thực Thi Công Việc Bất Đồng Bộ ​

Tại Sao Quan Trọng ​

Cloud Tasks là managed task queue service của Google Cloud dành cho công việc bất đồng bộ quy mô lớn. Không giống Pub/Sub (invocation ngầm), Cloud Tasks sử dụng explicit invocation model — bạn kiểm soát chính xác khi nào, ở đâu, thế nào mỗi task được thực thi.

Ở quy mô production, hiểu rõ mô hình bên trong (dispatch rate, retry backoff, deduplication window) là điều kiện bắt buộc để tránh:

  • Thundering herd — khi retry logic kích hoạt quá nhiều request cùng lúc
  • Duplicate execution — xử lý cùng task hai lần, gây dữ liệu không nhất quán
  • Silent failures — tasks vĩnh viễn thất bại nhưng không được alerting

Bạn cần hiểu:

  1. Task queue model — task là entity rõ ràng, không phải event implicit
  2. Rate limiting mechanics — 500 QPS/queue default nhưng cách nó được dispatch
  3. Retry exponential backoff — hành vi khi handler fail
  4. Deduplication window — 24 giờ sau deletion, lệnh tái tạo task sẽ thất bại
  5. At-least-once semantics — handler phải idempotent
  6. Khi nào chọn Cloud Tasks vs Pub/Sub — explicit vs implicit invocation

Điều Kiện Tiên Quyết ​

  • Distributed systems fundamentals (eventual consistency, retry patterns)
  • HTTP/REST API concepts
  • Async work patterns
  • Chapter 35: Cloud Pub/Sub (để hiểu phân biệt)

Mức Độ Sâu ​

4/5 — Kiến thức cốt lõi cho production systems. Bạn sẽ hiểu cơ chế dispatch, failure modes, scale bottlenecks.


Các Chủ Đề Chính ​

1. Mô Hình Bên Trong Cloud Tasks ​

Kiến thức cốt lõi: Task queue model vs event model; task anatomy; queue structure; explicit execution control

2. Rate Limiting & Dispatch Configuration ​

Kiến thức cốt lõi: Dispatch rate (QPS), max burst, max concurrent dispatch; tại sao config sai dẫn thundering herd; scaling qua multi-queue

3. Retry Exponential Backoff ​

Kiến thức cốt lõi: Retry semantics; exponential backoff formula; max attempts; backoff configurable parameters; cách tránh cascade failure

4. Task Deduplication & Idempotency ​

Kiến thức cốt lõi: ID-based dedup; 24-hour window after deletion; why idempotent handlers mandatory; dedup window SLA

5. HTTP Targets & Authentication ​

Kiến thức cốt lõi: HTTP target endpoints; authentication (OIDC tokens, service accounts); header injection; target validation; handler requirements

6. Cloud Tasks vs Pub/Sub Decision Matrix ​

Kiến thức cốt lõi: Khi nào chọn explicit (Tasks) vs implicit (Pub/Sub); multiple subscribers; delivery control; scaling semantics

7. Failure Handling & Observability ​

Kiến thức cốt lõi: Failed tasks behavior; retry exhaustion; logging/alerting; dead letter patterns; operational instrumentation

8. Operational Patterns — Pause, Resume, Purge ​

Kiến thức cốt lõi: Queue lifecycle (create, pause, resume, delete); graceful shutdown; task purging; operational concerns at scale

9. GKE Integration & Service-to-Service Tasks ​

Kiến thức cốt lõi: HTTP targets pointing to GKE services; service account authentication; workload identity integration; intra-cluster task dispatch


Mục Tiêu Sau Khi Hoàn Thành Chapter Này ​

✅ Bạn hiểu task queue model khác hoàn toàn so với event streaming
✅ Bạn biết cách configure rate limiting để tránh thundering herd
✅ Bạn nắm được retry exponential backoff làm gì, tại sao, và khi nào nó thất bại
✅ Bạn biết idempotency requirement vì sao bắt buộc (at-least-once)
✅ Bạn có thể quyết định Cloud Tasks vs Pub/Sub dựa trên model (explicit vs implicit)
✅ Bạn hiểu GKE service-to-service patterns sử dụng Cloud Tasks
✅ Bạn có thể troubleshoot failure modes (stalled tasks, dedup conflicts, auth failures)


Nếu bạn chưa quen:

  1. Start với 01.internal-model.md — hiểu task queue model
  2. Skip 06.vs-pubsub.md nếu chưa quen Pub/Sub
  3. Focus 02.rate-limiting.md + 03.retry-backoff.md

Nếu bạn là staff/principal level:

  1. 01.internal-model.md — mental model chính xác
  2. 06.vs-pubsub.md — decision matrix cho architecture
  3. 07.failure-handling.md — production observability
  4. 09.gke-integration.md — multi-service patterns

References ​