Open-Source Analytics Stack Setup
Assembling a Stack From Independent Pieces
Unlike GA4, which bundles collection, storage, and reporting into one product, an open-source analytics stack is assembled from independently-chosen pieces: an event collection layer, a warehouse, a transformation layer, and a BI/reporting layer. A common composition is Snowplow or PostHog (or a custom collector) for event collection, PostgreSQL or ClickHouse for storage, dbt for transformation, and Metabase or Superset for reporting. The appeal is full control over every layer and no per-event pricing from a single vendor; the cost is that you own integration, uptime, and schema evolution across every seam.
Open-source analytics stack layers
| Layer | Common Open-Source Options | Key Consideration |
|---|---|---|
| Collection | Snowplow, PostHog, custom collector + queue | Schema validation at ingest time saves enormous cleanup later |
| Storage | PostgreSQL, ClickHouse, DuckDB | ClickHouse scales far better for high-cardinality event analytics |
| Transformation | dbt | Version-controlled SQL models, testable and documented |
| Reporting/BI | Metabase, Apache Superset, Lightdash | Metabase is fastest to onboard non-technical stakeholders |
Why ClickHouse Specifically for Event Data
Event-level analytics data is high-volume, append-only, and queried with aggregations over huge row counts (COUNT, SUM, percentile calculations across millions of events) — exactly the workload column-oriented databases like ClickHouse are optimized for. PostgreSQL works fine at moderate scale, but once you're querying hundreds of millions of events with GROUP BY and window functions, ClickHouse's columnar storage and vectorized execution routinely outperform row-oriented Postgres by one or two orders of magnitude on the same hardware. PostHog itself migrated its own backend from Postgres to ClickHouse for exactly this reason.
CREATE TABLE events
(
event_id UUID,
event_name LowCardinality(String),
user_id String,
session_id String,
timestamp DateTime64(3),
properties String, -- JSON blob, parsed at query time via JSONExtract
page_url String,
utm_source LowCardinality(String),
utm_campaign String
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(timestamp)
ORDER BY (event_name, user_id, timestamp);
-- LowCardinality columns are a ClickHouse-specific optimization for
-- fields with a small set of repeated distinct values (event names,
-- UTM sources) -- dramatically reduces storage and speeds up filters.Schema Validation at the Edge Prevents the Most Common Failure Mode
dbt as the Transformation Contract
Raw event data is rarely queryable directly by business stakeholders — dbt's role is turning raw events rows into clean, tested, documented models (stg_events, fct_sessions, dim_users) through version-controlled SQL, with dbt test enforcing assumptions (uniqueness, not-null, referential integrity) automatically on every run. This is the layer that makes an open-source stack maintainable at all; without it, every dashboard tends to accumulate its own slightly-different ad hoc SQL interpretation of 'what counts as a session,' and definitions drift apart across teams.
Operational Costs People Underestimate
Running this stack yourself means you own: ingestion pipeline uptime and backpressure handling during traffic spikes, database scaling and index/partition tuning as volume grows, dbt job orchestration (via Airflow, Dagster, or a scheduler), BI tool user management and dashboard governance, and backup/disaster recovery for a system now holding business-critical historical data. None of this is free even though the software licenses are — budget for the engineering time, not just the hosting bill, when comparing total cost against a managed SaaS analytics platform.
Start Simpler Than You Think You Need
What's Next?
PostHog sits at an interesting middle point in this landscape — open-source, but bundling collection, product analytics, session replay, and feature flagging into one opinionated product rather than requiring you to assemble the stack yourself.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.