PostHog

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

31.9Kstars
2.4Kforks
Other
Python

PostHog is an open source platform that gives product engineers every tool they need to understand user behavior and ship better products — without stitching together multiple SaaS subscriptions or sending customer data to third parties. It unifies product analytics, web analytics, session replay, feature flags, A/B experiments, error tracking, surveys, data warehousing, and CDP pipelines into a single deployable stack. Teams get a generous free tier on PostHog Cloud, or can self-host the MIT-licensed open source core on their own infrastructure.

The platform is built on a polyglot architecture: a Django 5 backend handles the product API and business logic, high-throughput event ingestion runs in Rust (the capture service handles millions of events per second with sub-millisecond overhead), feature flag evaluation is served from a dedicated Rust flags service for low latency, and the frontend is a large TypeScript/React application using Kea for state management. ClickHouse is the analytical backbone for querying billions of events, while PostgreSQL handles transactional data.

PostHog has grown beyond analytics into a full product OS. It now ships AI observability (tracing LLM generations, latency, and cost), workflow automation, a built-in MCP server for AI assistants, revenue analytics, desktop and mobile session recordings, and a visual review tool for design feedback. The codebase is actively evolving toward a modular product-boundary architecture using Turborepo selective testing and tach import enforcement, letting individual product teams iterate independently at scale.

With over 35,000 GitHub stars, 78 distinct product modules, and more than 2,900 commits per month, PostHog is one of the most actively developed open source projects in the developer tools space.

What You Get

  • Product Analytics - Autocapture JavaScript events or manually instrument with SDKs for 15+ languages and frameworks; analyze with visual funnels, retention curves, cohort analysis, and full SQL via ClickHouse.
  • Session Replay - Record real user sessions including mouse movements, clicks, network requests, and console errors for web, iOS, Android, and React Native apps; filter by feature flag or user properties.
  • Feature Flags - Roll out features to targeted user segments using percentage rollouts, cohort-based targeting, or multi-variate variants; evaluate flags locally in a dedicated low-latency Rust service.
  • Experiments (A/B Testing) - Run statistically rigorous A/B and multivariate tests on any feature, linked directly to feature flags; built-in significance calculations and goal metric tracking.
  • Error Tracking - Automatically capture and group frontend and backend exceptions with full stack traces, source map support via posthog-cli, and user context for reproduction.
  • Surveys - Deploy no-code NPS, CSAT, and open-text surveys with conditional branching logic directly in-app, or build fully custom surveys using the survey API.
  • Data Warehouse & CDP - Sync data from Stripe, HubSpot, Snowflake, and 120+ sources into a built-in ClickHouse warehouse; transform and route events to 25+ destinations via pipeline functions with SQL.
  • AI Observability - Trace LLM generations, measure latency, track token cost, and monitor model performance for AI-powered applications using the dedicated observability capture pipeline.
  • Web Analytics - Monitor page views, sessions, bounce rates, Core Web Vitals, and revenue with a GA-style dashboard that runs on the same event data as product analytics.
  • Workflows - Automate actions triggered by user events or flag changes: send Slack alerts, trigger emails, update CRM records, or call webhooks without custom code.

Common Use Cases

  • Shipping features faster with confidence - A product team uses feature flags to gradually roll out a new checkout flow to 10% of users, monitors the funnel and error rate in real time, and promotes to 100% once the experiment reaches significance.
  • Debugging UX issues without user reports - A frontend engineer watches session replays of users who rage-clicked a form submit button, identifies a broken validation error that only appeared on mobile Safari, and fixes it before it impacts revenue.
  • Replacing five tools with one stack - A seed-stage startup eliminates monthly bills for Mixpanel, Hotjar, LaunchDarkly, Sentry, and Segment by self-hosting PostHog on a single $20/month server, keeping all user data on their own infrastructure.
  • Understanding AI product usage - An AI startup instruments their LLM-powered summarization feature with PostHog’s AI observability to track generation latency by model, token cost per user cohort, and failure rates by prompt type.
  • Syncing payment data with behavior - A growth team connects Stripe via the data warehouse integration to analyze which in-app activation milestones correlate with paid plan conversion, then creates a cohort to target with an in-app survey asking why they upgraded.

Under The Hood

Architecture PostHog’s backend is a Django 5 monolith that is actively being restructured into 78 explicit product modules under a products/ directory, each a self-contained vertical slice with its own backend, frontend, migrations, facade API, and contract types enforced by the tach import boundary tool. High-throughput paths have been extracted into dedicated Rust microservices: the capture service ingests events over HTTP, the flags service evaluates feature flags with single-digit millisecond p99 latency, and Cyclotron manages background job queuing — all communicating through Kafka for event-driven data flow. The frontend is a large React + TypeScript single-page application using Kea for predictable, logic-layer state management, built and coordinated by Turborepo which enables selective testing so only affected products re-run their CI suites on each change.

Tech Stack The backend runs Python 3.13 on Django 5.2 with Django REST Framework, Celery for async task queuing, and Dagster for orchestrating data pipeline DAGs. The analytical store is ClickHouse, queried via HogQL (PostHog’s own SQL dialect), while PostgreSQL serves as the transactional store. The Rust workspace includes more than thirty crates spanning the capture service, feature flags evaluator, Cymbal error symbolication, embedding workers, and a Personhog distributed persons coordination layer. The TypeScript frontend uses React with Kea state management and is bundled with esbuild; end-to-end tests run on Playwright. OpenTelemetry with OTLP exporters provides distributed tracing across all services.

Code Quality The repository has abundant test coverage across all layers: over 1,600 TypeScript test files in the frontend and extensive Python test suites that are selectively executed by Turborepo’s task cache, meaning only tests for changed products re-run in CI. The Python codebase uses Ruff for linting and formatting with strict rules, mypy for type checking, and enforces import boundaries with tach to prevent accidental cross-product coupling. The Rust services use standard cargo test with property-based testing in critical paths. GitHub Actions orchestrates the full CI matrix including Playwright browser tests, contract checks, and Docker image builds. Error handling in the Rust services is explicit with typed error enums, while the Python layer uses structured logging via structlog throughout.

What Makes It Unique PostHog’s most architecturally distinctive feature is HogQL — a ClickHouse-backed SQL dialect with a custom ANTLR grammar that powers every analysis in the platform and can be extended by users through the query API. Hog Functions allow users to write custom event processing logic in a sandboxed domain-specific language directly in the UI, replacing the need for external transformation tools. The Cyclotron job queue, built in Rust, enables reliable scheduled and triggered automation without external dependencies like Temporal. PostHog also exposes a native MCP server, letting AI assistants like Claude query product data directly, and ships AI observability tooling for instrumenting LLM-powered applications — a category it pioneered before most analytics vendors acknowledged it.

Self-Hosting

PostHog’s core is released under the MIT Expat license, which grants broad rights: you can use it commercially, modify it, distribute it, and sublicense it with no copyleft obligations. The only restriction is that the ee/ directory — which contains billing integrations, SSO enforcement, advanced permission models, audit logs, and certain enterprise analytics features — is under the PostHog Enterprise License, a source-available license that requires a commercial agreement for production use. For many self-hosters running the hobby or community deployment, the ee/ features are simply absent, and the MIT core provides a fully functional analytics platform including all the product analytics, session replay, feature flags, and CDP capabilities.

Running PostHog yourself requires meaningful infrastructure investment. The officially supported self-hosted path uses Docker Compose and is documented as a “hobby deploy” targeting up to 100,000 events per month, with PostHog explicitly stating they do not provide customer support for open source deployments. Scaling beyond that requires knowledge of ClickHouse cluster management, Kafka tuning, PostgreSQL backups, and Kubernetes if you want high availability. PostHog recommends migrating to their cloud after the hobby tier’s limits are reached, and they provide migration tooling for this path. You own backups, uptime, and security patching entirely.

The PostHog Cloud offering — available on US and EU infrastructure — removes all of that operational burden and includes a generous free tier (1 million events, 5,000 session recordings, 1 million flag requests, and 100,000 exceptions per month at no cost). The paid cloud tiers add priority support, SLAs, managed ClickHouse scaling, high availability, and access to all enterprise features in the ee/ directory including SAML SSO, role-based access control, and audit logging. For teams who want the data ownership of self-hosting but the operational simplicity of managed infrastructure, PostHog’s cloud deployments in the EU make it compliant with GDPR without running your own servers.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack

No spam. Unsubscribe anytime.

Join 750+ subscribers
No spam. Unsubscribe anytime.

Search