Architecture Diagrams — Simplicity Grade
Architecture Diagrams — Simplicity Grade
Visual models of the Simplicity Grade architecture
(v2.0, Google Cloud). They match 01-Acme-Simplicity-Architecture.md
and the reference code in src/.
The simple picture
If you only look at one diagram, look at this one. Every box is one product; nothing runs between jobs.
flowchart LR
S["<b>Your tools</b><br/>Salesforce, HubSpot,<br/>Google Ads"] -->|"every 30 min"| J["<b>Small scheduled job</b><br/>Cloud Run"]
J --> D[("<b>Data store</b><br/>Cloud Storage")]
D --> B[("<b>Reports database</b><br/>BigQuery")]
B --> R["<b>Dashboards</b><br/>Looker Studio or Power BI"]
J -. "if something fails" .-> A["<b>Alert</b><br/>e-mail or Slack"]
A scheduled job collects the data from your tools, stores it, loads it into a reports database and the dashboards read from there. If a job fails, someone gets an e-mail or a Slack message. About $5-25 per month.
The diagrams below add the detail an engineer needs.
1. C4 Container Diagram
C4Container
title Container Diagram — Acme Marketing Group (Simplicity Grade)
Person(marketer, "Marketing & Sales Ops", "Views dashboards, receives alerts")
Person(engineer, "Data / Analytics Engineer", "Develops adapters, reads job logs")
System_Ext(salesforce, "Salesforce CRM", "Leads, Opportunities")
System_Ext(hubspot, "HubSpot", "Contacts, Companies, Deals")
System_Ext(google_ads, "Google Ads", "Campaign performance")
System_Boundary(c1, "Acme Simplicity Lakehouse (Google Cloud)") {
Container(scheduler, "Cloud Scheduler", "3 schedules", "Triggers the jobs")
Container(sync, "Sync job", "Cloud Run job, Python", "Source adapters: rate limit, retry, paging, landing")
Container(build, "Build job", "Cloud Run job, Python + delta-rs", "Silver MERGE, pseudonymisation, Gold, load to BigQuery")
ContainerDb(landing, "Landing", "Cloud Storage, JSONL, 21-day lifecycle", "Immutable raw pages")
ContainerDb(lake, "Silver and Gold", "Cloud Storage, Delta tables", "Pseudonymised Silver with tombstones, Gold star schema")
ContainerDb(bq, "BigQuery", "Gold tables", "Reporting store")
}
System_Ext(secrets, "Secret Manager", "API tokens, pseudonym key")
System_Ext(bi, "Looker Studio / Power BI", "Dashboards")
System_Ext(alerts, "Email / Slack / Teams", "Failure and pacing alerts")
Rel(scheduler, sync, "Triggers", "Cloud Run job")
Rel(scheduler, build, "Triggers daily", "Cloud Run job")
Rel(sync, salesforce, "Polls incremental", "HTTPS, OAuth2")
Rel(sync, hubspot, "Keyset search", "HTTPS, private app")
Rel(sync, google_ads, "Trailing-window reports", "HTTPS, OAuth2")
Rel(sync, landing, "Appends pages", "Conditional create")
Rel(build, landing, "Reads pages")
Rel(build, lake, "Idempotent MERGE", "Delta protocol")
Rel(build, bq, "Loads Gold")
Rel(sync, secrets, "Reads API tokens")
Rel(build, secrets, "Reads pseudonym key")
Rel(bi, bq, "Queries", "SQL")
Rel(marketer, bi, "Explores metrics", "HTTPS")
Rel(sync, alerts, "Failure alert", "Cloud Monitoring")
Rel(build, alerts, "Failure and pacing alert", "Cloud Monitoring / webhook")
Rel(engineer, sync, "Reads logs, runs backfill")
2. Ingestion & Transformation Sequence
sequenceDiagram
autonumber
participant Sched as Cloud Scheduler
participant Sync as Sync job (HubSpotAdapter)
participant API as HubSpot REST API
participant Landing as Landing (JSONL)
participant Build as Build step (Silver)
participant Delta as Silver / Gold Delta
participant BQ as BigQuery
Sched->>Sync: start (every 30 minutes)
Sync->>Sync: read watermark, window = (watermark, now - 5 min)
loop until a page has fewer than 200 rows
Sync->>API: POST /crm/v3/objects/contacts/search (hs_object_id > cursor)
alt HTTP 429
API-->>Sync: 429 (Retry-After)
Sync->>Sync: backoff with full jitter, retry
end
API-->>Sync: 200 (up to 200 records)
Sync->>Landing: write run_{batch}_p{page}.jsonl (never overwrites)
end
Sync->>Sync: commit watermark
Sync->>Build: promote landing files
Build->>Build: drop erased subjects, HMAC pseudonyms, drop names
Build->>Delta: MERGE (newest wins, tombstones kept)
Note over Sched,BQ: Daily build at 06:00 UTC
Build->>Delta: build Gold (is_deleted = false)
Build->>BQ: load Gold tables
3. Adapter Pattern Class Structure
Matches src/acme_simplicity/adapters/.
classDiagram
class BaseSourceAdapter {
<<abstract>>
+source_name: str
+storage_sink: ILandingStorageSink
+limiter: TokenBucket
+test_connection() bool*
#_fetch_records(entity, start, end, cursor) page*
#_auth_headers() dict
#_refresh_credentials() bool
+execute_http_request(method, url, ...) Response
+extract_window(entity, start, end) ExtractionResult
+extract_historical(entity, start, end, chunk_days) Iterator
}
class SalesforceAdapter {
+api_version
+include_deleted
follows nextRecordsUrl
}
class HubSpotAdapter {
+properties
keyset paging, 200 per page
}
class GoogleAdsAdapter {
+customer_id
+extract_trailing(entity, as_of)
}
class FutureAdapter {
illustrative, e.g. TikTok Ads
}
class ILandingStorageSink {
<<interface>>
+write_records(...) str
}
class LocalLandingSink
BaseSourceAdapter <|-- SalesforceAdapter
BaseSourceAdapter <|-- HubSpotAdapter
BaseSourceAdapter <|-- GoogleAdsAdapter
BaseSourceAdapter <|-- FutureAdapter
BaseSourceAdapter --> ILandingStorageSink
ILandingStorageSink <|.. LocalLandingSink