Case studies
A social metrics pipeline into a warehouse
Stream publishing events and metric checkpoints into your warehouse with signed, idempotent webhooks, and backfill history.
Brightline Media (an illustrative publisher) reports social performance next to web and revenue data in their warehouse. They needed every published post, every metric checkpoint, and campaign and content-pillar dimensions, without scraping dashboards.
Data flow#
Outboxer ── webhooks (signed) ──▶ ingest endpoint ──▶ raw_events (append-only, keyed by event id)
variant.published │
metrics.updated (1h, 24h, 7d, 30d) ▼
post.published dbt models: posts, variants, metrics_daily
▲
nightly backfill: GET /posts?status=published + /posts/{id}/metrics1. Subscribe#
Each webhook endpoint belongs to one workspace (organization-level events such as billing also reach it). Create one per workspace you report on:
OB=https://api.outboxer.dev/v1 # ADMIN_KEY: an owner or admin's API key
curl -s -X POST $OB/webhooks -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \
-d '{"workspace_id": "brightline", "url": "https://ingest.brightline.example/outboxer",
"events": ["variant.published", "post.published", "metrics.updated"]}'
# → {"id": "wh_…", "secret": "whsec_…"} ← store the secret; it is shown once2. Verify and ingest idempotently#
Every delivery is signed with Outboxer-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>.
Deliveries are retried with backoff and can be redelivered by hand, so the event id is your primary key:
func handler(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
if !verify(body, r.Header.Get("Outboxer-Signature"), os.Getenv("OUTBOXER_WEBHOOK_SECRET"), 5*time.Minute) {
http.Error(w, "bad signature", http.StatusBadRequest)
return
}
var evt struct {
ID string `json:"id"`
Type string `json:"type"`
WorkspaceID string `json:"workspace_id"`
Data json.RawMessage `json:"data"`
}
json.Unmarshal(body, &evt)
// INSERT … ON CONFLICT (event_id) DO NOTHING — redeliveries are harmless
db.Exec(`insert into raw_events (event_id, type, payload, received_at) values ($1, $2, $3, now())
on conflict (event_id) do nothing`, evt.ID, evt.Type, body)
w.WriteHeader(http.StatusNoContent) // answer fast; transform later
}
func verify(body []byte, header, secret string, tolerance time.Duration) bool {
var ts, sig string
for _, part := range strings.Split(header, ",") {
k, v, _ := strings.Cut(strings.TrimSpace(part), "=")
if k == "t" { ts = v } else if k == "v1" { sig = v }
}
t, err := strconv.ParseInt(ts, 10, 64)
if err != nil || time.Since(time.Unix(t, 0)).Abs() > tolerance { return false }
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(ts + "." + string(body)))
return hmac.Equal([]byte(hex.EncodeToString(mac.Sum(nil))), []byte(sig))
}metrics.updated carries post_id, variant_id, checkpoint (1h, 24h, 7d, 30d) and a metrics object
(impressions, reach, engagement, clicks, video views, likes, comments, shares, depending on the platform).
3. Backfill and reconcile nightly#
Webhooks give you freshness, and a nightly job makes the data complete. Page through published posts with the cursor, and pull metrics for anything changed:
cursor = None
while True:
page = requests.get(f"{OB}/workspaces/brightline/posts", headers=H,
params={"status": "published", "from": since, "limit": 200, "cursor": cursor}).json()
for post in page["data"]:
upsert_post(post) # campaign_id, labels (pillars), author (human or agent)
upsert_metrics(requests.get(f"{OB}/posts/{post['id']}/metrics", headers=H).json())
if not page["has_more"]:
break
cursor = page["next_cursor"]For a quick sanity check against the warehouse, GET /v1/workspaces/{ws}/analytics?days=30 returns breakdowns by
author type, agent, label (content pillar) and campaign.
4. Model it#
| Table | Grain | Key fields |
|---|---|---|
posts |
post | post_id, workspace_id, campaign_id, labels[], author_type, agent_id, published_at |
variants |
post × channel | variant_id, provider, post_type, permalink, external_id |
metrics |
variant × checkpoint | checkpoint, impressions, reach, engagement, clicks, video_views |
labels are the brand's content pillars, so pillar-level ROI is a single join. author_type = agent compared with
user shows how agent-drafted content performs.
What this setup gives Brightline#
- Fresh data. Checkpoints land within seconds of collection.
- Exactly-once rows despite retries and redeliveries, keyed on the event
id. - Complete history from a cursor-paginated backfill that tolerates gaps in delivery.
- Business dimensions (campaign, pillar, human or agent) attached at the source.
