1οΈβ£3οΈβ£ Messaging & Event Driven Systems - Overview¶
Learn event-driven architecture on Google Cloud Platform.
π Table of Contents¶
- Introduction
- Messaging Patterns
- Services Comparison
- Decision Framework
- Architecture Patterns
- Cost Considerations
- Quick Reference
Introduction¶
GCP provides multiple services for building event-driven and message-based architectures.
Messaging Stack¶
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Event-Driven Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β Pub/Sub β β Eventarc β β Cloud β β
β β β β β β Tasks β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β
β ββββββββββββ ββββββββββββ β
β β Cloud β β Workflowsβ β
β β Schedulerβ β β β
β ββββββββββββ ββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Messaging Patterns¶
1. Pub/Sub (Publish-Subscribe)¶
Asynchronous messaging service
βββββββββββββββββββββββββββββββββββββββ
β Pub/Sub β
βββββββββββββββββββββββββββββββββββββββ€
β Publishers β
β β β
β βββββββββββ β
β β Topic β β
β ββββββ¬βββββ β
β β β
β βββββββββββββββββββββββ β
β β Subscriptions β β
β βββββββββββββββββββββββ€ β
β β β’ Push β β
β β β’ Pull β β
β β β’ BigQuery β β
β β β’ Cloud Storage β β
β βββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β β’ At-least-once delivery β
β β’ Message ordering β
β β’ Dead letter topics β
β β’ Message filtering β
β β’ Exactly-once delivery β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - Asynchronous messaging - Decoupled services - Scalable (millions of messages/sec) - Global availability - Message retention (7 days)
Use Cases: - Microservices communication - Event streaming - Data ingestion - Async processing - Fan-out patterns
2. Eventarc¶
Event routing and delivery
βββββββββββββββββββββββββββββββββββββββ
β Eventarc β
βββββββββββββββββββββββββββββββββββββββ€
β Event Sources: β
β β’ Cloud Storage β
β β’ Pub/Sub β
β β’ Cloud Audit Logs β
β β’ Custom events β
β β β
β βββββββββββ β
β βEventarc β β
β β Routing β β
β ββββββ¬βββββ β
β β β
β Event Targets: β
β β’ Cloud Run β
β β’ Cloud Functions β
β β’ GKE β
β β’ Workflows β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β β’ CloudEvents format β
β β’ Event filtering β
β β’ Multiple sources β
β β’ Declarative routing β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - Event routing - CloudEvents standard - Multiple sources - Declarative configuration - Serverless integration
Use Cases: - Event-driven workflows - Cloud event handling - Serverless triggers - Multi-source events - Event orchestration
3. Cloud Tasks¶
Asynchronous task execution
βββββββββββββββββββββββββββββββββββββββ
β Cloud Tasks β
βββββββββββββββββββββββββββββββββββββββ€
β Task Queue β
β βββββββββββββββββββββββββββββββ β
β β Task 1 β HTTP Target β β
β β Task 2 β HTTP Target β β
β β Task 3 β HTTP Target β β
β βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β β’ Scheduled execution β
β β’ Rate limiting β
β β’ Retry logic β
β β’ Task deduplication β
β β’ HTTP/App Engine targets β
βββββββββββββββββββββββββββββββββββββββ€
β Queue Types: β
β β’ Push queues β
β β’ Pull queues (deprecated) β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - Task scheduling - Guaranteed execution - Rate control - Retry mechanism - HTTP-based
Use Cases: - Background jobs - Scheduled tasks - Rate-limited operations - Reliable task execution - Async API calls
4. Cloud Scheduler¶
Cron job service
βββββββββββββββββββββββββββββββββββββββ
β Cloud Scheduler β
βββββββββββββββββββββββββββββββββββββββ€
β Cron Jobs: β
β βββββββββββββββββββββββββββββββ β
β β */5 * * * * β HTTP Target β β
β β 0 9 * * 1 β Pub/Sub Topic β β
β β 0 0 * * * β App Engine β β
β βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β β’ Cron syntax β
β β’ Multiple targets β
β β’ Retry configuration β
β β’ Time zones β
β β’ Monitoring β
βββββββββββββββββββββββββββββββββββββββ€
β Targets: β
β β’ HTTP endpoints β
β β’ Pub/Sub topics β
β β’ App Engine β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - Scheduled jobs - Cron syntax - Multiple targets - Reliable execution - Fully managed
Use Cases: - Periodic tasks - Batch processing - Report generation - Data cleanup - Health checks
5. Workflows¶
Service orchestration
βββββββββββββββββββββββββββββββββββββββ
β Workflows β
βββββββββββββββββββββββββββββββββββββββ€
β Workflow Definition (YAML): β
β βββββββββββββββββββββββββββββββ β
β β Step 1: Call API A β β
β β β β β
β β Step 2: Process data β β
β β β β β
β β Step 3: Call API B β β
β β β β β
β β Step 4: Store result β β
β βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ€
β Features: β
β β’ Service orchestration β
β β’ Error handling β
β β’ Conditional logic β
β β’ Parallel execution β
β β’ Built-in connectors β
βββββββββββββββββββββββββββββββββββββββ
Characteristics: - Service orchestration - YAML-based workflows - Error handling - Conditional logic - Serverless
Use Cases: - Multi-step processes - Service orchestration - Business workflows - Data pipelines - API composition
Services Comparison¶
Feature Matrix¶
| Feature | Pub/Sub | Eventarc | Cloud Tasks | Cloud Scheduler | Workflows |
|---|---|---|---|---|---|
| Type | Messaging | Event routing | Task queue | Cron jobs | Orchestration |
| Pattern | Pub/Sub | Event-driven | Queue | Scheduled | Sequential |
| Delivery | At-least-once | At-least-once | At-least-once | At-least-once | Exactly-once |
| Ordering | Yes (optional) | No | Yes | N/A | Yes |
| Retry | Yes | Yes | Yes | Yes | Yes |
| Targets | Multiple | Multiple | HTTP | HTTP/Pub/Sub | APIs |
| Scheduling | No | No | Yes | Yes | No |
| Max Retention | 7 days | N/A | 30 days | N/A | 1 year |
Decision Framework¶
Service Selection¶
What do you need?
|
ββ> Async messaging between services?
| ββ> Pub/Sub
|
ββ> React to cloud events?
| ββ> Eventarc
|
ββ> Execute tasks asynchronously?
| ββ> Cloud Tasks
|
ββ> Schedule periodic jobs?
| ββ> Cloud Scheduler
|
ββ> Orchestrate multiple services?
ββ> Workflows
Use Case Matrix¶
| Requirement | Recommended | Alternative |
|---|---|---|
| Microservices messaging | Pub/Sub | Eventarc |
| Event-driven architecture | Eventarc | Pub/Sub |
| Background jobs | Cloud Tasks | Pub/Sub |
| Scheduled tasks | Cloud Scheduler | Cloud Tasks |
| Service orchestration | Workflows | Cloud Tasks |
| Data streaming | Pub/Sub | Dataflow |
| File upload triggers | Eventarc | Cloud Functions |
| Rate-limited operations | Cloud Tasks | Pub/Sub |
Architecture Patterns¶
Pattern 1: Event-Driven Microservices¶
βββββββββββββββββββββββββββββββββββββββ
β Event-Driven Architecture β
βββββββββββββββββββββββββββββββββββββββ
Service A Service B
| |
v v
ββββββββββ ββββββββββ
βPublish β βPublish β
βββββ¬βββββ βββββ¬βββββ
| |
βββββββββ¬ββββββββββββββββ
v
βββββββββββββββββ
β Pub/Sub β
β Topic β
βββββββββ¬ββββββββ
|
βββββββββΌββββββββ
v v v
ββββββββββββββββββββββββββββββ
βService ββService ββService β
β C ββ D ββ E β
ββββββββββββββββββββββββββββββ
Pattern 2: Event Processing Pipeline¶
Cloud Storage
|
| (File uploaded)
v
βββββββββββββββββββββββ
β Eventarc β
ββββββββββββ¬βββββββββββ
v
βββββββββββββββββββββββ
β Cloud Function β
β (Process file) β
ββββββββββββ¬βββββββββββ
v
βββββββββββββββββββββββ
β Pub/Sub β
ββββββββββββ¬βββββββββββ
v
βββββββββββββββββββββββ
β Dataflow β
β (Transform data) β
ββββββββββββ¬βββββββββββ
v
βββββββββββββββββββββββ
β BigQuery β
βββββββββββββββββββββββ
Pattern 3: Task Queue Pattern¶
API Request
|
v
βββββββββββββββββββββββ
β Cloud Run β
β (API Service) β
ββββββββββββ¬βββββββββββ
|
(Create task)
v
βββββββββββββββββββββββ
β Cloud Tasks β
β (Task Queue) β
ββββββββββββ¬βββββββββββ
|
(Execute task)
v
βββββββββββββββββββββββ
β Cloud Run β
β (Worker Service) β
βββββββββββββββββββββββ
Pattern 4: Scheduled Workflow¶
βββββββββββββββββββββββ
β Cloud Scheduler β
β (Daily at 9 AM) β
ββββββββββββ¬βββββββββββ
v
βββββββββββββββββββββββ
β Pub/Sub β
ββββββββββββ¬βββββββββββ
v
βββββββββββββββββββββββ
β Workflows β
β βββββββββββββββββ β
β β 1. Fetch data β β
β β 2. Process β β
β β 3. Store β β
β β 4. Notify β β
β βββββββββββββββββ β
βββββββββββββββββββββββ
Pattern 5: Fan-Out/Fan-In¶
βββββββββββββββββββββββ
β Single Event β
ββββββββββββ¬βββββββββββ
v
βββββββββββββββββββββββ
β Pub/Sub β
β Topic β
ββββββββββββ¬βββββββββββ
|
ββββββββΌβββββββ (Fan-Out)
v v v
ββββββββββββββββββββββββ
βSub 1 ββSub 2 ββSub 3 β
βββββ¬ββββββββ¬ββββββββ¬βββ
| | |
ββββββββΌβββββββ (Fan-In)
v
βββββββββββββββββββββββ
β Aggregator β
βββββββββββββββββββββββ
Cost Considerations¶
Pricing Overview¶
Pub/Sub: - First 10 GB/month: Free - Additional data: $0.04 per GB - Message delivery: $0.04 per GB
Eventarc: - First 100,000 events/month: Free - Additional: $0.40 per million events
Cloud Tasks: - First 1 million operations/month: Free - Additional: $0.40 per million operations
Cloud Scheduler: - First 3 jobs/month: Free - Additional: $0.10 per job/month
Workflows: - First 5,000 steps/month: Free - Additional: $0.01 per 1,000 steps
Cost Optimization¶
# Use message filtering to reduce processing
gcloud pubsub subscriptions create filtered-sub \
--topic=my-topic \
--message-filter='attributes.priority="high"'
# Set appropriate message retention
gcloud pubsub topics update my-topic \
--message-retention-duration=1h
# Use dead letter topics
gcloud pubsub subscriptions update my-sub \
--dead-letter-topic=dead-letter-topic \
--max-delivery-attempts=5
Quick Reference¶
Pub/Sub¶
# Create topic
gcloud pubsub topics create my-topic
# Create subscription
gcloud pubsub subscriptions create my-sub \
--topic=my-topic
# Publish message
gcloud pubsub topics publish my-topic \
--message="Hello World"
# Pull messages
gcloud pubsub subscriptions pull my-sub --auto-ack
Eventarc¶
# Create trigger
gcloud eventarc triggers create my-trigger \
--location=us-central1 \
--destination-run-service=my-service \
--destination-run-region=us-central1 \
--event-filters="type=google.cloud.storage.object.v1.finalized" \
--event-filters="bucket=my-bucket"
Cloud Tasks¶
# Create queue
gcloud tasks queues create my-queue
# Create task
gcloud tasks create-http-task \
--queue=my-queue \
--url=https://example.com/process \
--method=POST \
--body-content='{"data":"value"}'
Cloud Scheduler¶
# Create job
gcloud scheduler jobs create http my-job \
--schedule="0 9 * * *" \
--uri="https://example.com/endpoint" \
--http-method=POST
Workflows¶
# workflow.yaml
main:
steps:
- step1:
call: http.get
args:
url: https://api.example.com/data
result: apiResponse
- step2:
return: ${apiResponse.body}
# Deploy workflow
gcloud workflows deploy my-workflow \
--source=workflow.yaml \
--location=us-central1
Best Practices¶
Pub/Sub¶
β
Use message attributes for filtering
β
Implement idempotent message processing
β
Set appropriate acknowledgment deadlines
β
Use dead letter topics
β
Enable message ordering when needed
β
Monitor subscription backlog
β
Use push subscriptions for low latency
β
Implement retry logic
Eventarc¶
β
Use CloudEvents format
β
Implement event filtering
β
Handle duplicate events
β
Monitor event delivery
β
Use appropriate event sources
β
Implement error handling
Cloud Tasks¶
β
Set appropriate task deadlines
β
Implement idempotent handlers
β
Use rate limiting
β
Monitor queue depth
β
Configure retry policies
β
Use task deduplication
Cloud Scheduler¶
β
Use appropriate time zones
β
Implement idempotent jobs
β
Monitor job execution
β
Set retry configuration
β
Use Pub/Sub for fan-out
Workflows¶
β
Implement error handling
β
Use retries appropriately
β
Keep workflows simple
β
Monitor execution
β
Use variables effectively
β
Implement timeouts
Next Steps¶
- Pub/Sub - Messaging service
- Eventarc - Event routing
- Cloud Tasks - Task queue
- Cloud Scheduler - Cron jobs
- Workflows - Service orchestration
- Best Practices - Production guidelines
Additional Resources¶
- Pub/Sub Documentation
- Eventarc Documentation
- Cloud Tasks Documentation
- Cloud Scheduler Documentation
- Workflows Documentation
Last Updated: March 2026
Status: β
Complete