Skip to content

Chương 37: Eventarc — Event Routing & CloudEvents

Eventarc là managed event routing service của Google Cloud — lớp kết nối giữa các event source (Audit Logs, Cloud Storage, Pub/Sub) và event consumer (Cloud Run, GKE, Workflows). Hiểu Eventarc không phải là học cấu hình trigger. Điều quan trọng hơn là hiểu tại sao nó được thiết kế như vậy: event routing được xây trên Pub/Sub, tại sao cần CloudEvents standard, và tại sao Eventarc Advanced xuất hiện để giải quyết những gì Eventarc Standard không làm được.

Tại sao chương này quan trọng

Eventarc không chỉ là "gắn event vào Cloud Run". Nó là lớp abstraction giải quyết ba vấn đề thực tế:

  1. Heterogeneous event sources — hơn 130 GCP services phát ra sự kiện theo format khác nhau. Eventarc chuẩn hóa tất cả về CloudEvents trước khi deliver.
  2. Delivery reliability — kéo cơ sở hạ tầng Pub/Sub vào layer routing, không phải tự build.
  3. IAM integration — trigger service account kiểm soát danh tính khi gọi destination, không để source service gọi trực tiếp.

Sai lầm phổ biến nhất là coi Eventarc như một event bus tổng quát. Trong Standard mode, nó là trigger-based router, không phải bus. Eventarc Advanced mới là bus thực sự — và sự khác biệt này có hệ quả quan trọng cho architecture.

Cấu trúc chương

chapter-37-eventarc/
├── index.md                                 # File này
├── 01.eventarc-architecture-trigger-model.md # Trigger model, event sources, transport layer, destinations, IAM
├── 02.cloudevents-format-delivery.md         # CloudEvents spec, HTTP binary mode, delivery guarantees, retry, dead letter
└── 03.eventarc-advanced.md                  # Advanced: buses, enrollments, pipelines, CEL transformation

Danh sách subtopics

1. Kiến Trúc Eventarc & Trigger Model

Xây dựng mental model đúng về cách Eventarc hoạt động bên trong. Điểm mấu chốt: Eventarc Standard không xây transport layer từ đầu — nó dùng Pub/Sub làm universal transport. Mọi event, dù từ Audit Logs hay Cloud Storage, đều đi qua Pub/Sub subscription được quản lý bởi Eventarc trước khi đến destination.

Nội dung chính:

  • Trigger là gì về mặt kỹ thuật: declaration + routing metadata trong control plane
  • Hai đường ingest event: Audit Log path và Direct (Pub/Sub, Cloud Storage) path
  • Tại sao Pub/Sub là universal transport: reliability, retention, retry semantics
  • Filtering mechanics: serviceName/methodName cho Audit Logs, event type cho Direct events
  • Destinations: Cloud Run, GKE (gke-forwarder pod model), Workflows, Cloud Functions
  • IAM: trigger service account, Eventarc service agent, quyền tối thiểu per-destination

2. CloudEvents Format & Delivery Guarantees

CloudEvents là open standard mà Eventarc dùng để normalize tất cả events trước khi deliver. File này giải thích cấu trúc CloudEvents (context attributes + data), HTTP binary mode, và tại sao at-least-once delivery là hệ quả tất yếu của việc dùng Pub/Sub transport. Cũng cover retry, dead letter qua Pub/Sub subscription settings.

Nội dung chính:

  • CloudEvents spec: required attributes (id, source, type, specversion), optional attributes
  • HTTP binary mode vs structured mode: Eventarc dùng binary mode
  • GCP-specific extension attributes: resourcename, servicename, methodname
  • At-least-once delivery: nguyên nhân từ Pub/Sub lease-based model
  • Retry: exponential backoff, 24h retention, cấu hình qua Pub/Sub subscription
  • Dead letter: DLT thông qua underlying Pub/Sub subscription
  • Idempotency implications cho consumer

3. Eventarc Advanced — Bus, Enrollment & Pipeline

Eventarc Advanced là một product khác biệt hoàn toàn so với Standard. Nó giải quyết governance gap: trong Standard, không có cách nào enforce policy tập trung, không có content-based access control, không có payload transformation. Advanced giới thiệu ba primitive mới: bus (governance layer), enrollment (subscription + filter), và pipeline (delivery + transformation).

Nội dung chính:

  • Tại sao Advanced xuất hiện: governance gap trong Standard
  • Bus architecture: Envoy-based router, centralized policy, FGAC via CloudEvents attributes
  • Enrollment: CEL filter expression trên event attributes
  • Pipeline: transformation via CEL, format conversion, HTTP Message Destination Binding
  • Delivery guarantees trong Advanced: at-least-once, không ordering, 24h retention
  • Quotas: 1 bus/project/region, 100 pipelines
  • Khi nào dùng Advanced vs Standard

Điều kiện tiên quyết

  • Chương 35: Cloud Pub/Sub architecture, delivery semantics, ack mechanics
  • CloudEvents spec basics: spec v1.0 format, context attributes
  • Cloud Run hoặc GKE fundamentals: để hiểu destination behavior

Quan hệ với các chương khác

Eventarc trong hệ sinh thái GCP event-driven:

Event Sources:
  Cloud Audit Logs (Chương 34)   → Audit Log trigger → [Eventarc]
  Cloud Storage                  → GCS notification   → [Eventarc]
  Cloud Pub/Sub (Chương 35)      → Pub/Sub trigger    → [Eventarc]

Event Destinations:
  [Eventarc] → HTTP POST     → Cloud Run service
  [Eventarc] → gke-forwarder → GKE workload
  [Eventarc] → execution     → Cloud Workflows
  [Eventarc] → HTTP POST     → Cloud Functions (Gen2)

Identity:
  IAM service account cho trigger   → Chương 31
  Workload Identity cho GKE target  → Chương 13

Tham khảo nhanh

Khái niệmMô tả
TriggerDeclaration routing event từ source đến destination
CloudEventsOpen standard format cho event metadata và data
HTTP binary modeContext attributes trong HTTP headers, data trong body
at-least-onceDelivery guarantee kế thừa từ Pub/Sub transport
gke-forwarderPod trong GKE cluster pull event qua Pub/Sub StreamingPull
BusCentral event router trong Eventarc Advanced
EnrollmentSubscription + CEL filter trong Eventarc Advanced
PipelineDelivery intermediary + transformation trong Eventarc Advanced

Tài liệu tham khảo chính