Architecture kata · K—07

Unified Marketing Intelligence on Google Cloud

Architecture kata · design study on a fictional brief

Sector
E-commerce marketing
Technologies
BigQuery, Dataform, Pub/Sub, Cloud Composer, Cloud Run, Vertex AI, Dataplex, Power BI
Flow: five sources land in layered BigQuery datasets, pass a publish gate, feed BI, an LLM and agents via one metric API.
The design at a glance: the one-page, 30-minute live drawing.

In short

One certified metric layer over a GA4 stream, four batch sources and the warehouse, so dashboards, an LLM and agents quote one number.

Problem

An e-commerce retailer on Google Cloud has five data sources that do not talk to each other. They are a GA4 stream, daily competitor files, social and ad APIs, search data and the enterprise warehouse. Marketing reconciles CSV exports by hand, and a question such as “did our price or the competitor’s cause yesterday’s conversion drop?” takes two days. The company wants one platform for four consumers. These are Power BI for about 400 users, an LLM assistant with agents, machine-learning models and audience exports to ad platforms.

Approach

The binding goal is a single source of truth. Power BI, the LLM and the agents must give the same number for the same question. Cadence differs: GA4 should be queryable within minutes, competitor files arrive daily, and social APIs revise up to seven days of history. Cost is the third concern, because four consumer groups can drive the BigQuery bill. The design layers the data, publishes through a gate, and binds every consumer to one metric contract.

Architecture

  • Ingestion: a server-side collector and Pub/Sub for GA4, Cloud Composer for batch files, and a Cloud Run connector for APIs. The warehouse is read through authorised views, not copied.
  • Layers: raw, staging, conformed keys, then certified marts, built with Dataform SQL and tests.
  • Publish gate: marts are built as candidates, assertions run, and a view swap makes them live. A late batch never shows half-loaded data.
  • Serving: metrics are defined once in Git. A metric API runs them, and Power BI models are generated from the same definition.
  • LLM and agents: the model translates a question into metric, filter and date range. The number comes from the API. Agents propose actions into an approval queue.
Architecture: five sources land in layered BigQuery, pass a publish gate and reach BI, LLM and agents via one metric layer.
Solution overview: GA4 near real time and four batch sources into conformed BigQuery marts, one certified metric layer, and Power BI, LLM, agent, ML and audience consumers.Open full size (opens in new tab)

Why these components

Need Choice Why
GA4 streaming ingest Server-side Google Tag Manager collector, Pub/Sub, BigQuery subscription GA4 has no native Pub/Sub export. A BigQuery subscription needs no code, and a streaming view meets the two-minute target. Dataflow only for real enrichment; one Dataflow job per stream is needless cost.
Batch file ingest Cloud Composer, managed Airflow Competitor files need retries, backfill and dependencies, a classic orchestration problem. Airflow is an open standard, and the managed service keeps the DAGs portable.
API ingest Cloud Run connector service Social, Ads and Search Console APIs need token handling, rate limits and a watermark per source. A small, stateless service that scales; Composer only triggers it on schedule.
Warehouse access Authorised views The warehouse already sits in BigQuery in the same organisation; no Analytics Hub listing needed. A copy adds cost and a second truth. Views read the same rows, and the data team keeps ownership.
Storage and compute BigQuery with layered datasets Every source already lands here; another engine means a second copy and a second truth. Marts are partitioned by event date. This lock-in is deliberate; Trino or ClickHouse on Iceberg is the named alternative.
Transformation Dataform with SQL and assertions in Git SQL with versions and a dependency graph, and the assertions are the publish gate’s test set. The same model can be rebuilt in dbt Core, so the dependency is low.
Publish gate Dataform assertions and a view swap by publish ID Candidate tables are built and tested, then CREATE OR REPLACE VIEW points the marts at them. On failure the views stay on yesterday. Rollback is a view change, with no reload.
Semantic layer Metric contract in Git and a metric API on Cloud Run The heart of the design, and deliberately our own code. One definition feeds Power BI, the LLM and the agents. Cube or dbt Semantic Layer could replace it, but the definition stays ours.
BI Power BI tabular model, import with incremental refresh 400 users are trained, it is the company standard and the licence exists. Import mode keeps clicks away from BigQuery. Measures and row-level roles are generated from the contract. Superset is the open alternative.
LLM Vertex AI Gemini on EU endpoints The model turns a question into metric, filter and date range as structured output; the metric API produces the number. Data stays inside the perimeter. An open-weight model on vLLM would keep the same interface.
Agents Vertex Agent Engine with an approval queue The tools are the metric API, the catalogue and a proposal writer. There is no raw SQL tool and no direct Ads change. Every action is stored with evidence, approver and a rollback record.
ML feed Vertex AI Feature Store Features come from the same marts, so there is no second pipeline and the model uses the report’s definitions. Feast on BigQuery follows the same pattern.
Catalogue and contract Dataplex Certified versus raw shows as a badge. Lineage is native in BigQuery, and Dataplex tags carry contract version and freshness target. Metadata can be exported to OpenMetadata.
Identity, privacy and secrets IAM, policy tags, row access policies, Cloud DLP, Secret Manager Column policy tags stop the marketing role from selecting identifiers. Row access policies filter brand and country on ad-hoc and LLM paths. API tokens rotate automatically.

Decisions and trade-offs

  • No raw SQL for consumers. Text-to-SQL is flexible but inconsistent: two queries for one question give two numbers. Once an answer disagrees with Power BI, trust is gone. A question without a certified metric is refused and goes to the metric backlog. The same-number guarantee comes from architecture, not prompting. The cost is a metric contract that needs owners; ownership is the biggest risk.
  • View swap instead of a second engine. In BigQuery a view replacement is atomic and needs no copy. If a batch is late, yesterday’s numbers stay with yesterday’s stamp, so nobody sees half a day. GA4 gets a provisional streaming view with a freshness flag. The cost is that certified marts run one day behind.
  • Agents propose, they do not apply. The approval service calls the Ads API, not the agent; the agent’s service account lacks that right. Each run has a spend change limit, and every action keeps a rollback record. The cost: every new kind of action needs its own approval flow.
  • Google Cloud lock-in, on purpose. The warehouse is already in BigQuery and GA4 lands there natively. Moving it would add cost and delay with no business value. I spend the portability budget where value builds up: key mappings, the metric contract and agent tool definitions live in Git. If the warehouse moves, the metric API points to another engine and consumers see the same interface.
  • Read the warehouse, do not copy it. Authorised views read the same rows and add no load to the warehouse. The data team keeps ownership. The cost is schema change risk, so the service level with that team is the most fragile part of the contract.
  • Cost follows data volume, not users. Power BI runs in import mode, so 400 users’ clicks never reach BigQuery. The metric API caches by metric, filter and publish ID, and the result cannot change until the next publish. Each consumer group has its own project, reservation and quota, with a budget alert at 80%.
Flow: one stream and four batches are conformed, checked at a publish gate and exposed through one certified metric answer.
One number from mixed cadence: how the stream and four batches become one certified answer, so Power BI, the LLM and the agents cannot disagree.Open full size (opens in new tab)

What I would revisit

  • Server-side collector. Without one, GA4 falls back to the hourly intraday export and the two-minute target fails.
  • Competitor SKU coverage. I assumed 90%. Categories under 95% answer with a coverage warning. If coverage is low, mapping quality comes first, not architecture.
  • Primary BI tool. Power BI and Looker Studio can both be supported, but certification work and cost double.
  • Warehouse team service level. How much notice comes before an authorised view’s schema changes?

Outcome notes (design assumptions, not measurements)

This is a design exercise, not a delivered platform. The output is a four-page diagram set, a one-page whiteboard version and a 16-page Turkish PDF. The metric list and its owners (50 assumed) are still open.

Sources

  • Architecture PDF (Turkish, 16 pages).
  • draw.io diagrams (English labels): four-page set and a one-page 30-minute version.

Real projects on this topic

  1. P—01

    Completed

    Featured

    Enterprise Data Warehouse Migration to Google BigQuery

    80 TB warehouse moved from SQL Server and a 15-node Cloudera cluster to BigQuery: $550K annual savings, 75% lower infrastructure cost, 7x faster workflows.

    • Data platform
    • Data quality
    • Analytics-ready data
    • Orchestration
    • Cloud

    Role

    Design and lead · Senior Data Engineering & Data Architecture Group Manager

  2. P—02

    Completed

    Featured

    GA4 Analytics Modernization: Gold Layer, Streaming and Anomaly Detection

    GA4 analytics rebuilt on BigQuery with a Gold e-commerce model and drift checks: monthly cost $9K to $3K, heaviest queries 46 minutes to 8 seconds.

    • Analytics-ready data
    • Decision support
    • Data quality
    • Data observability
    • Cloud

    Role

    Program lead · Data Solution Architect

Decisions: projects, katas and publications

About the katas

Write to me about a similar design problem.