google-cloud-solution-event-driven-decoupling
Decouples tightly coupled services or monoliths with Google Cloud Pub/Sub so services scale and fail independently, using Go reference implementations adaptable to Java, Python, Node.js, and other stacks. Use when breaking apart synchronous chains, defining transaction boundaries, bulkheads, and Tra
- 01Installs
- New
- 02Files scanned
- 8
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 722953fc5758222a… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
Event-driven decoupling with Pub/Sub
Break a distributed monolith or tightly coupled service chain apart with
asynchronous messaging on Pub/Sub so services scale and fail independently.
This skill uses progressive disclosure across Phases 0–5 (with Phase 0
inline below and modular references/ files for Phases 1–5): run the full
end-to-end migration sequence for architecture journeys, or load only the
single phase reference needed for a focused design, code, or troubleshooting
request.
Usage Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read and follow the instructions in
Usage Attribution.
Progressive disclosure: load only the phase you need
| Phase & module | Reference to load | Produces | Load when |
|---|---|---|---|
| 0. Frame the goal | Inline in SKILL.md (see End-to-end workflow and phase gates) | Business outcome, runtime/DB constraints, measurable acceptance criteria | Starting any end-to-end decoupling journey before design begins |
| 1. Assess (Synchronous coupling assessment) | Coupling assessment & transaction boundaries; plus Go & SQL outbox, post-commit, and bulkheads when authoring producer/outbox code | Measured baseline, call graph, transaction cut, outbox vs state-marker decision, event catalog, bulkhead plan | Auditing synchronous HTTP/gRPC/DB chains, Cloud Trace / Cloud SQL lock waits, dual writes, schema freezes, reference-lookup caching, or deciding what becomes an event |
| 2. Design messaging (Pub/Sub topic and subscription design) | Pub/Sub topology, flow-control sizing, DLQ, and claim-check | Domain topics vs dedicated topics, subscription filters, dead-letter policy + service-agent IAM, backoff, DB-bounded flow control, 10 MB claim-check | Sizing MaxOutstandingMessages, ack deadlines, or retry delays; choosing filtered vs per-event topics; handling payloads near/above 1–10 MB; or fixing DLQ delivery |
| 3. Build consumers (Event-driven workflow triggering) | Consumer ack/nack matrix, SIGTERM drain, GKE HPA, and Cloud Run | Idempotent Go dispatcher, sentinel-error ack/nack/quarantine matrix, single-deadline SIGTERM drain, GKE autoscaling/v2 HPA, Cloud Run / Eventarc / Cloud Run functions (--retry) | Writing or reviewing consumer handlers, fixing rollout context canceled or duplicate bugs, scaling GKE on num_undelivered_messages, or configuring Cloud Run / Eventarc triggers |
| 4. Observe (Distributed trace instrumentation) | OpenTelemetry propagation, OTLP export, and Cloud Logging correlation | otelhttp/otelgrpc wrapping, Pub/Sub built-in tracing or attribute carrier, telemetry.googleapis.com:443 OTLP + Cloud Run sampler, slog correlation, InMemoryExporter tests | Propagating traces across Pub/Sub, instrumenting synchronous HTTP/gRPC-only services, fixing missing Cloud Run traces or unlinked slog logs, or before Phase 1 when a service has no traces |
| 5. Cut over & validate (Cut-over & acceptance) | Solution checklist and hand-off template | Phase gate table, event catalog template, budget worksheet, observable acceptance checks | Defining measurable acceptance criteria, tracking phase hand-offs, executing Strangler dual-run cut-over, or validating post-cut-over gates |
Routing rules:
- End-to-end requests: run Phases 0–5 sequentially, loading each phase's
reference only when that phase begins. Two exceptions apply:
- Greenfield consumers: run Phases 3 and 4 together so new consumers ship with distributed tracing from day one.
- Missing observability: if the user's primary problem is missing latency visibility or absent distributed traces, run Phase 4 (references/phase4-distributed-tracing.md) first to establish a trace baseline before proposing Pub/Sub changes, then resume Phases 1–3.
- Focused single-phase requests: load only the matching phase
reference, name which phase file applies, and never dump unrelated phases:
- Flow-control / subscription configuration questions
(
MaxOutstandingMessages, ack deadline,max-delivery-attempts, backoff): load only Phase 2 (references/phase2-pubsub-topology-and-sizing.md). Relate flow control to the database connection pool and ack deadline to the per-message processing timeout; do not present the Phase 1 coupling matrix, Transactional Outbox, or Phase 3 consumer handler code. - Consumer handler ack/nack questions: load only Phase 3 (references/phase3-consumer-and-autoscaling.md). Provide the handler logic (never provisioning commands alone) and note that the subscription ack deadline must exceed the handler's processing timeout.
- Flow-control / subscription configuration questions
(
- Non-Go languages and other SQL engines: Phases 1, 3, and 4 provide
compiled Go (
cloud.google.com/go/pubsub/v2,database/sql, OpenTelemetry Go) and PostgreSQL reference code, while Phase 2 maps flow-control fields across Go, Python, Java, and Node.js. When the user's workload uses another language (such as Java, Python, or Node.js) or database (such as MySQL or Oracle), keep every architectural invariant and phase gate unchanged, translate the patterns into idiomatic SDK and SQL constructs for the requested stack, and state explicitly that you are adapting the Go reference patterns.
Prerequisites
Use the Google Cloud CLI (install guide:
https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt) and, for GKE,
kubectl. Never install host tools or grant IAM bindings without explicit user
approval: both alter the user's host or production access. If gcloud is
unavailable, produce design artifacts, code, Kubernetes YAML, or Terraform
directly.
-
Billing is attached to
{project_id}. Pub/Sub, Cloud Trace, and Cloud Logging have free allotments, but an active billing account is still required (https://cloud.google.com/pricing, https://cloud.google.com/pubsub/pricing, https://cloud.google.com/run/pricing, https://cloud.google.com/kubernetes-engine/pricing, https://cloud.google.com/stackdriver/pricing). -
Project, region, authentication, and APIs (default
us-central1, https://cloud.google.com/about/locations):gcloud config set project {project_id} gcloud config set compute/region {region} gcloud auth login # Local CLI gcloud auth application-default login # SDK / ADC; workloads use Workload Identity Federation for GKE or GOOGLE_APPLICATION_CREDENTIALS gcloud services enable pubsub.googleapis.com cloudtrace.googleapis.com telemetry.googleapis.com logging.googleapis.com monitoring.googleapis.com # Add per workload: cloudprofiler.googleapis.com (Phase 1), storage.googleapis.com (claim-check), # container.googleapis.com (GKE, default), or run.googleapis.com eventarc.googleapis.com cloudfunctions.googleapis.com (Cloud Run) -
Least-privilege IAM: one service account per producer and consumer; never
roles/editor(why: basic roles grant project-wide write across every service).Principal Role Scope Phase Assessor identity (read-only) roles/cloudtrace.user,roles/monitoring.viewer,roles/cloudprofiler.user{project_id}1 Producer service account roles/pubsub.publisher(+ roles/storage.objectCreatoron{claim_check_bucket}if claim-check){topic_id}2 Consumer service account roles/pubsub.subscriber(+ roles/storage.objectVieweron{claim_check_bucket}if claim-check){subscription_id}2–3 Pub/Sub service agent service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.comroles/pubsub.publisheron{dlq_topic_id}androles/pubsub.subscriberon{subscription_id}dead-lettering 2 Metrics adapter ( custom-metrics-stackdriver-adapter)roles/monitoring.viewer{project_id}3 Push / Eventarc trigger service account (Cloud Run path) roles/run.invoker,roles/eventarc.eventReceiverservice / trigger 3 Producer and consumer service accounts roles/telemetry.tracesWriter,roles/logging.logWriter{project_id}4
End-to-end workflow and phase gates
- Phase 0 - Frame the goal: capture the business outcome (independent scaling, isolated failure, shorter p99, removable batch windows) and constraints (schema freeze, language, runtime GKE vs Cloud Run, data residency) as measurable acceptance criteria before designing.
- Phase 1 - Assess (phase1-coupling-assessment.md,
phase1-outbox-and-bulkheads-go.md).
Gate: baseline p99 latency, connection saturation, and lock-wait
numbers recorded per hop; every outbound event has a name, owning team,
idempotency key, and Transactional Outbox vs state-marker decision; zero
network calls remain inside a database transaction. Gate enforcement:
if the user claims assessment is finished and asks for
gcloudtopic or subscription creation commands while only naming events without confirming those Phase 1 gate items, do not emitgcloud pubsub topics createorsubscriptions createcommands and do not invent payload schemas or owners; ask to confirm the missing Phase 1 gate items first and state that Phase 2 (references/phase2-pubsub-topology-and-sizing.md) is the next step once the gate is met. - Phase 2 - Design messaging (phase2-pubsub-topology-and-sizing.md). Gate: per-replica flow control derived from the database pool; dead-letter topic paired with its own pull subscription and both Pub/Sub service-agent IAM bindings; Cloud Storage claim-check decision for any payload that can exceed 1 MB (Pub/Sub hard limit: 10 MB).
- Phase 3 - Build consumers (phase3-consumer-and-autoscaling.md).
Gate: unit tests for every branch of the ack/nack/quarantine matrix;
shutdown test proving the database pool closes strictly after
Receivereturns and in-flight commits finish; GKE HPAmaxReplicasor Cloud Run concurrency capped within the database connection budget. - Phase 4 - Observe (phase4-distributed-tracing.md).
Gate: one continuous trace ID from producer request through Pub/Sub to
consumer database stages, structured logs correlated via
logging.googleapis.com/trace, explicit sampling policy per environment. - Phase 5 - Cut over incrementally: Strangler pattern per event type.
Dual-run (synchronous path plus event) behind
{feature_flag}so a single flip restores the synchronous call, compare outcomes, and remove the synchronous call only after{dlq_subscription_id}stays empty for{soak_period}(default: one full business cycle, at least 7 days). - Validate → fix → repeat: re-verify all phase gates post-cut-over using solution-checklist.md.
Cross-cutting rules and scope boundaries
- One default, one escape hatch per decision: every phase names one default and one escape hatch; do not add a third option.
- Idempotency is non-negotiable: Pub/Sub delivers at least once. Every consumer deduplicates on an event ID or natural key before side effects and acks duplicates (nacking duplicates loops valid data into the DLQ).
- Budgets flow downstream: database connection budget → per-replica pool
→
MaxOutstandingMessages→ HPAmaxReplicas. Enforce the invariantper_replica_pool * max_replicas <= database_connection_budget(derive whichever of the three values is unknown, tie HPAmaxReplicasto that budget, never leave client flow-control defaults of 1000 messages / 1 GiB in place, and derive per-replica flow control with Phase 2 (references/phase2-pubsub-topology-and-sizing.md) and the HPA manifest with Phase 3 (references/phase3-consumer-and-autoscaling.md)). - Never leave a dead-letter topic without a subscription: it silently
discards messages; alert on
subscription/dead_letter_message_count. - Other brokers (Kafka, RabbitMQ, SQS, self-managed queues): state
plainly that this skill is specific to Google Cloud Pub/Sub, offer only
broker-agnostic principles explicitly labeled as such (or redirect to
broker-specific docs), never present Pub/Sub flags, flow-control settings,
or fabricated
gcloudcommands as Kafka config, and never suggest migrating to Pub/Sub as the answer to a Kafka tuning question. - Synchronous HTTP/gRPC-only services (no Pub/Sub): load only Phase 4
(
TracerProvider+ Cloud RunWithRemoteParentNotSampledsampler,otelhttp,otelgrpcstats handlers, DB stage spans,slogcorrelation); never introduce Pub/Sub topics or message carriers. - Querying existing traces ("find traces slower than 2s"): state that
this is a Cloud Trace query task rather than instrumentation; point to the
Cloud Trace console/API
(https://docs.cloud.google.com/trace/docs/finding-traces.md.txt) or the
cloud-trace-queryingskill. Never emit OpenTelemetry SDK setup code, never require re-instrumenting first, and never invent a trace query DSL. - Orchestration engines & sagas: Workflows, Managed Service for Apache
Airflow (
managed-airflow-*), Application Integration (application-integration-basics), and multi-service compensating sagas are out of scope; keep each aggregate's state change in one transaction.
Validation checklist
- Producer and consumer deploy, scale, and fail independently: with the
consumer stopped, producer p99 is unchanged,
num_undelivered_messagesgrows, and the backlog drains on restart with matching row counts. - No dual writes: a fault injected between commit and publish is recovered by the outbox relay or sweeper with zero duplicate side effects.
- A malformed message lands in
{dlq_subscription_id}aftermax-delivery-attempts(or in quarantine when chosen) while healthy messages keep flowing (subscription/dead_letter_message_count> 0). - Rolling consumer restarts under load produce zero
context canceledcommits and zero duplicate side effects. - One trace ID links producer request, Pub/Sub hop, consumer processing,
and database stages, with
logging.googleapis.com/traceon log lines. - Every acceptance criterion names an observable signal (metric, log field, row count, or test assertion), never a qualitative claim like "services are decoupled".
Resource cleanup
Remove only temporary test or dual-run resources in a non-production
project. Before running or proposing any delete command after a migration,
explicitly ask the user to confirm the exact test resource names and
{test_project_id}, distinguish test/dual-run resources from live production
topics and subscriptions, and never delete production resources carrying
live traffic:
gcloud pubsub subscriptions delete {test_subscription_id} --project={test_project_id}
gcloud pubsub topics delete {test_topic_id} --project={test_project_id}
Files
8- SKILL.md
6af867a5f916.9 KB - references/attribution.md
e692c4d05a1.9 KB - references/phase1-coupling-assessment.md
2820ea89299.9 KB - references/phase1-outbox-and-bulkheads-go.md
380c07f62b19.5 KB - references/phase2-pubsub-topology-and-sizing.md
5ce0a078f318.2 KB - references/phase3-consumer-and-autoscaling.md
ffd6d0425123.2 KB - references/phase4-distributed-tracing.md
1a28e423e422.7 KB - references/solution-checklist.md
bb199344133.8 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from google/skills8
Audits AI agent data access, blast radius, and blocked policy operations in Google Cloud by querying Cloud Audit Logs via BigQuery. Use when investigating what resources or services an agent accessed, identifying top originating principals the agent is acting as, or triaging PERMISSION_DENIED errors
Manages Google Cloud Agent Registry (agentregistry.googleapis.com) resources using gcloud CLI and Kubernetes manifests, including agents, MCP servers, endpoints, services, bindings, AI applications, skills and skill revisions, resource-level IAM policies, Cloud Run and GKE automatic workload registr
Configures best-practice alerting policies for AI agents using OpenTelemetry (OTel) metrics, generating output as Terraform (.tf) configuration files. Use when analyzing, writing, or deploying alerting policies to monitor agent latency, error rates, token usage, and quality metrics. Don't use for st
Designs, engineers, and validates enterprise Gemini platform architectures. Use when designing multi-project hierarchies (Host, Central Governance Hub, Runtime Spoke, Tool/MCP Spoke), configuring Agent Gateway, authoring Agent Connectivity Templates (ALL_TRAFFIC vs PRIVATE_RANGES_ONLY), deploying Se
Customizes an autorater (evaluation metric) for an AI agent so its grades match the user's own judgment, starting from the agent's real trajectories. Use when a user wants a metric tailored to their agent, wants to turn failing trajectories into rubrics, says an existing autorater grades their agent
Deploy open models or custom weights from Model Garden to Agent Platform endpoints, check the status of an in-progress deployment operation, or clean up resources by undeploying models and deleting endpoints. Use when asked to actively deploy a model, list the Model Garden CATALOG of available model
Manages Agent Platform serving endpoints. Use when you need to create, list, describe, update, or delete serving endpoints for model deployment on Agent Platform. Also use when troubleshooting endpoint permission, quota, or resource busy errors. Don't use for deploying models to endpoints or for run
Measures and improves the quality of AI models and agents on Google Cloud using the Eval Quality Flywheel methodology. Use when generating synthetic user scenarios, evaluating an agent or model, building an eval dataset, picking or writing evaluation metrics, analyzing failures, comparing results be
Related backend skillsscan passed
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
Report browser/API/CLI/job/worker/webhook bugs. Use for: qa report only, just report bugs, test but dont fix. (gstack)
Generate a complete Go MCP server project with proper structure, dependencies, and implementation using the official github.com/modelcontextprotocol/go-sdk.
This skill should be used when the user asks to "build an MCP server", "create an MCP", "make an MCP integration", "wrap an API for Claude", "expose tools to Claude", "make an MCP app", or discusses building something with the Model Context Protocol. It is the entry point for MCP server development
Calibrate a new dataset from live RTSP camera streams via the AutoMagicCalib REST API. Use when the user provides RTSP URLs or asks to calibrate live cameras; VIOS records clips, AMC ingests them, then runs calibration.