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
Schema search
Run:
grep -RniE "analytics|event|events|log|logs|audit|trace|metric|pageView|click|impression|webhook|usage|token|generation|scheduler" prisma srcWrite-path search
Run:
grep -RniE "prisma\.[a-zA-Z0-9_]+\.(create|createMany|update|upsert)" srcClassify every write path.
DB table audit
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:
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 type | Keep in Prisma? | Destination |
|---|---|---|
| Transactional audit log visible in app | Maybe | Prisma, capped/archived |
| User-visible activity feed | Maybe | Prisma, capped/archived |
| Raw product analytics | No | PostHog |
| Page views / clicks | No | PostHog |
| Session replay | No | PostHog |
| AI traces / generation spans | No | Langfuse or PostHog AI Observability |
| Raw webhook payload archive | No | R2 |
| Scheduler heartbeat logs | No | Axiom/GCP logs |
| API request logs | No | Axiom/GCP logs |
| Error logs | No | Axiom/GCP logs/PostHog error tracking |
| Customer-facing analytics API | Not primary Prisma | Tinybird/ClickHouse/BigQuery |
Future TendSocial event categories
| Category | Examples | Recommended destination |
|---|---|---|
| Product analytics | feature usage, page views, funnels | PostHog |
| UX/session replay | sessions, rage clicks, form friction | PostHog |
| App logs | API logs, worker logs, queue failures | Axiom or Google Cloud Logging |
| AI observability | prompt, model, latency, cost, traces | Langfuse or PostHog AI Observability |
| Raw payload archive | webhook payloads, social sync payloads | Cloudflare R2 NDJSON/Parquet |
| Customer analytics | content performance dashboards | Tinybird/ClickHouse/BigQuery |
| Long-term BI | revenue, cohort, customer reporting | BigQuery 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.
Recommended starting architecture
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 reportingEvent producer abstraction
Create one internal interface so app code does not directly write analytics/log events to Prisma:
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
- Identify current Prisma event/log/analytics tables.
- Identify current write paths.
- Classify each table/write path.
- Keep only transactional records in Prisma.
- Stop high-volume writes to Prisma.
- Route product analytics to PostHog.
- Route raw payload archive to R2.
- Route operational logs to Axiom/GCP.
- Route AI traces to Langfuse/PostHog if needed.
- Backfill/export existing data only if useful.
- Drop or truncate old high-volume tables after validation.
- Add code review guardrail: no new high-volume event tables in Prisma without explicit approval.
Acceptance criteria
| Item | Target |
|---|---|
| Current analytics/event/log tables identified | 100% |
| Current high-volume write paths identified | 100% |
| Destination chosen for each stream | Yes |
| New high-volume writes removed from Prisma | Yes |
| Existing data archived/exported where useful | Yes |
| Prisma contains only transactional product state | Yes |
| Operation tests re-run after offload | Yes |
| Prisma monthly operation estimate recalculated | Yes |