Skip to content

Phase 6: Analytics and Event Log Offload

Goal

Keep Prisma Postgres focused on transactional product state. Move high-volume analytics, logs, traces, raw payloads, and event streams out of Prisma before they distort operation count, storage, and performance.

Current-state audit

Run:

bash
grep -RniE "analytics|event|events|log|logs|audit|trace|metric|pageView|click|impression|webhook|usage|token|generation|scheduler" prisma src

Run:

bash
grep -RniE "prisma\.[a-zA-Z0-9_]+\.(create|createMany|update|upsert)" src

Classify every write path.

DB table audit

sql
SELECT
  schemaname,
  relname AS table_name,
  n_live_tup AS approx_rows,
  pg_size_pretty(pg_total_relation_size(relid)) AS total_size,
  pg_total_relation_size(relid) AS total_bytes
FROM pg_stat_user_tables
ORDER BY pg_total_relation_size(relid) DESC;

Event/log candidates:

sql
SELECT
  relname AS table_name,
  n_live_tup AS approx_rows,
  pg_size_pretty(pg_total_relation_size(relid)) AS total_size
FROM pg_stat_user_tables
WHERE relname ILIKE '%event%'
   OR relname ILIKE '%log%'
   OR relname ILIKE '%audit%'
   OR relname ILIKE '%metric%'
   OR relname ILIKE '%trace%'
   OR relname ILIKE '%analytics%'
   OR relname ILIKE '%webhook%'
ORDER BY pg_total_relation_size(relid) DESC;

Classification rules

Data typeKeep in Prisma?Destination
Transactional audit log visible in appMaybePrisma, capped/archived
User-visible activity feedMaybePrisma, capped/archived
Raw product analyticsNoPostHog
Page views / clicksNoPostHog
Session replayNoPostHog
AI traces / generation spansNoLangfuse or PostHog AI Observability
Raw webhook payload archiveNoR2
Scheduler heartbeat logsNoAxiom/GCP logs
API request logsNoAxiom/GCP logs
Error logsNoAxiom/GCP logs/PostHog error tracking
Customer-facing analytics APINot primary PrismaTinybird/ClickHouse/BigQuery

Future TendSocial event categories

CategoryExamplesRecommended destination
Product analyticsfeature usage, page views, funnelsPostHog
UX/session replaysessions, rage clicks, form frictionPostHog
App logsAPI logs, worker logs, queue failuresAxiom or Google Cloud Logging
AI observabilityprompt, model, latency, cost, tracesLangfuse or PostHog AI Observability
Raw payload archivewebhook payloads, social sync payloadsCloudflare R2 NDJSON/Parquet
Customer analyticscontent performance dashboardsTinybird/ClickHouse/BigQuery
Long-term BIrevenue, cohort, customer reportingBigQuery or ClickHouse

Destination options and pricing snapshot

PostHog

Best for product analytics, web analytics, feature flags, session replay, errors, and some AI observability.

Current free tier includes 1M analytics events/month, 5k session replay recordings, 1M feature flag requests, 100k exceptions, 1M data warehouse rows, 100k AI observability events, and 50 GB logs ingest. Product analytics overage starts at $0.00005/event and gets cheaper at higher volume. Source: PostHog pricing.

Cloudflare R2

Best for cheap raw append-only archive: webhook payloads, social sync payloads, NDJSON, and Parquet batches.

R2 Standard free tier includes 10 GB-month storage, 1M Class A operations, 10M Class B operations, and free egress. Standard storage example pricing implies $0.015/GB-month after the free tier. Source: Cloudflare R2 pricing.

Axiom

Best for application logs and operational telemetry.

Axiom Cloud's Personal plan has no charge and includes 500 GB/month data loading, 10 GB-hours/month query compute, and 25 GB/month storage. Axiom also describes Always Free allowances for Axiom Cloud: 1,000 GB/month data loading compute, 100 GB-hours/month query compute, and 100 GB/month storage. Source: Axiom pricing.

Tinybird

Best for custom real-time analytics APIs backed by ClickHouse.

Tinybird Free includes shared infrastructure, 0.25 vCPU, 1 thread/request, 1k requests/day, 10 GB included storage. Developer starts at $25/month. Source: Tinybird pricing.

BigQuery

Best for long-term warehouse and ad-hoc analytical queries.

Google Cloud Free Tier includes 1 TiB querying/month and 10 GiB storage/month for BigQuery. Source: Google Cloud Free Tier.

Langfuse

Best for LLM/AI traces, prompt evaluation, generation cost/latency tracking, and AI observability. Use only if AI trace debugging becomes important enough to justify a specialized tool. Source: Langfuse pricing.

text
Prisma Postgres
  transactional product state only

PostHog
  product analytics
  web analytics
  feature usage
  session replay if needed
  error tracking if desired

Cloudflare R2
  raw webhook payload archive
  raw social sync payload archive
  large append-only event exports

Axiom or Google Cloud Logging
  backend logs
  worker logs
  scheduler logs
  operational errors

Langfuse or PostHog AI Observability
  AI traces and generation observability

Tinybird/BigQuery later
  customer-facing analytics or warehouse reporting

Event producer abstraction

Create one internal interface so app code does not directly write analytics/log events to Prisma:

ts
export const analytics = {
  track: async (eventName: string, properties: Record<string, unknown>) => {
    // PostHog
  },
};

export const eventArchive = {
  write: async (stream: string, payload: unknown) => {
    // R2 NDJSON/Parquet later
  },
};

export const appLog = {
  info: async (message: string, fields?: Record<string, unknown>) => {
    // Axiom/GCP logger
  },
  error: async (message: string, fields?: Record<string, unknown>) => {
    // Axiom/GCP logger
  },
};

export const aiTrace = {
  record: async (payload: unknown) => {
    // Langfuse/PostHog AI Observability
  },
};

Migration tasks

  1. Identify current Prisma event/log/analytics tables.
  2. Identify current write paths.
  3. Classify each table/write path.
  4. Keep only transactional records in Prisma.
  5. Stop high-volume writes to Prisma.
  6. Route product analytics to PostHog.
  7. Route raw payload archive to R2.
  8. Route operational logs to Axiom/GCP.
  9. Route AI traces to Langfuse/PostHog if needed.
  10. Backfill/export existing data only if useful.
  11. Drop or truncate old high-volume tables after validation.
  12. Add code review guardrail: no new high-volume event tables in Prisma without explicit approval.

Acceptance criteria

ItemTarget
Current analytics/event/log tables identified100%
Current high-volume write paths identified100%
Destination chosen for each streamYes
New high-volume writes removed from PrismaYes
Existing data archived/exported where usefulYes
Prisma contains only transactional product stateYes
Operation tests re-run after offloadYes
Prisma monthly operation estimate recalculatedYes

Sources

TendSocial Documentation