← Back to Guides
Profile image for Daniel Cosby
Published 25th April 2025

How to self-host PostHog on Northflank

PostHog is an open-source product analytics platform designed to help teams build better products by offering deep insights into user behavior. Unlike traditional analytics tools that often rely on event tracking alone, PostHog provides a suite of features—including session replays, feature flags, heatmaps, A/B testing, and user funnels—all within a single platform.

While PostHog offers a cloud version, self-hosting removes their imposed limits on some features (projects and data retention), as well as giving you complete control over your data and infrastructure. Northflank makes self-hosting PostHog straightforward by providing a ready-to-deploy Infrastructure-as-Code (IaC) stack template. This template encompasses all the necessary services and addons to run your own PostHog instance. You can also deploy these services directly into your existing cloud accounts using Northflank's Bring Your Own Cloud (BYOC) feature.

This article guides you through using the Northflank PostHog stack template to deploy a PostHog instance on Northflank.

PostHog Self-Hosted Architecture

The Northflank stack template for PostHog deploys a comprehensive set of components to ensure a fully functional analytics platform:

  • Services (16): These deploy the various PostHog components, including:
    • posthog-web: The web interface you interact to configure PostHog integrations.
    • posthog-worker: Handles background tasks and processing.
    • posthog-plugins: Runs the PostHog plugin server.
    • clickhouse: An open-source column-oriented database management system used for storing and querying large volumes of analytical data.
    • kafka: An event streaming platform used for handling event ingestion.
    • zookeeper: A centralised service for maintaining configuration information, naming, providing distributed synchronisation, and providing group services, often used by Kafka and ClickHouse.
    • capture & replay-capture: services capturing events and session recording data.
    • temporal, temporal-ui, temporal-admin-tools, temporal-django-worker: Components of the Temporal workflow orchestration system, used by PostHog for managing workflows and scheduled processes.
    • livestream: live events API.
    • property-defs-rs, cyclotron-fetch, cyclotron-janitor: Supporting services for various internal PostHog functions.
  • Addons (4): Managed services:
    • postgres: A PostgreSQL database used for storing configuration, metadata, and user information.
    • minio: S3-compatible object storage used for storing larger data like session recordings.
    • redis & redis7: Two Redis instances used as message brokers and for caching.
  • Volumes (3): Persistent storage attached to stateful services:
    • clickhouse-storage: Persists ClickHouse data.
    • kafka-storage: Persists Kafka data.
    • zookeeper-storage: Persists ZooKeeper data.
  • Jobs (4): Run-once tasks for setup and maintenance:
    • Initialisation jobs for the database (postgres) and object storage (minio).
    • Database migration jobs (posthog-web, async-migrations-check).

This distributed architecture ensures scalability and resilience for your PostHog deployment.

Prerequisites

Before deploying PostHog on Northflank, ensure you have completed the following:

Deploying PostHog using Northflank Stack Templates

To deploy PostHog using the Northflank stack template, click the button and follow these steps:

  1. Customise your project name, colour, and region, if desired.
  2. Click Deploy stack to save and run the PostHog template. The PostHog stack template running in Northflank
  3. Once the template run has finished deploying all components, open the project and select the posthog-web service. PostHog running in Northflank
  4. When the posthog-web service shows as running, open the code.run domain under Ports & DNS in the service header to access your PostHog instance and begin configuration. The PostHog web service running in Northflank

You should now be able to access your self-hosted PostHog instance and sign in, or create an account.

Configure and integrate PostHog

You can now select whether to launch PostHog in live implementation mode, or just experimenting mode, which has fewer enforced security requirements.

Selecting the PostHog mode

Next, you'll be asked to validate the implementation, which will check that all the PostHog components configured and working.

Validating the PostHog deployment on Northflank

You can then choose which PostHog features you want to use.

PostHog feature select

You can then begin integrating them with your applications by following the in-app guides for the frameworks you use.

Integrate PostHog with your frameworks

After integrating, you should start recieving events in your PostHog dashboard.

PostHog dashboard running on Northflank

Next Steps

With your PostHog instance running, consider exploring these Northflank features and PostHog configurations:

Explore Northflank's Features

  • Custom Domains: Replace the default code.run domain for the posthog-web service with your own custom domain or subdomain using Northflank's custom domain configuration.
  • Logs and Metrics: Monitor your deployment and debug issues easily using Northflank's real-time and historic container logs and metrics, accessible via the UI and CLI for all services, jobs, and addons.

Explore PostHog Features

If you're deploying PostHog, then you likely already know that it allows you to easily integrate analytics, session recording, feature flags, and much more. Configuring these is very easy from the PostHog dashboard. Other features and configuration options of PostHog that you might want to explore include:

  • Configure Your Instance: PostHog offer many configuration options in their “Instance Settings”. These are accessible on /instance/settings, but only once you have completed onboarding (i.e. setup an integration). See here for more information.
  • Configure Email: PostHog needs configuring to send invite and password reset emails. This can be achieved via either “Instance Settings” or environment variables. See more detail here.
  • Running Behind a Proxy: PostHog provide a detailed guide on implementing a proxy in front of your self-hosted instance.
  • Environment Variables: Some PostHog configuration options are only available through environment variables. A full list of variables can be found here.

Scale PostHog

You can monitor resource usage for each individual PostHog component - vCPU, memory, and storage usage for services and addons.

As your usage increases you can scale PostHog components as required:

Important Notes

  • PostHog Support: Be aware that PostHog does not provide direct support for self-hosted deployments. You'll rely on community support and documentation.
  • Versioning: Changing the PostHog version (by modifying the image tags in the services) might affect features or require specific upgrade steps. Consult PostHog documentation before upgrading.

Security Considerations

You may want to implement added access controls to your PostHog instance. You can use one or more of Northflank's built-in security features found under Ports & DNS for the posthog-web service:

  • IP Policies: Limit access to specific IP addresses or ranges.
  • Basic Auth: Require users to enter a username and password.
  • SSO Provider: Require users to authenticate via your organisation's SSO provider (requires Northflank enterprise plan).
  • Northflank CLI: Use the northflank forward command to securely forward access to the service to your local machine without exposing it publicly.

Consider your organisation's security requirements when choosing the appropriate method(s).

Deploy on Northflank for free

Northflank allows you to deploy your code and databases within minutes. Sign up for a Northflank account and create a free project to get started.

  • Build, deploy, scale, and release from development to production
  • Observe & monitor with real-time metrics & logs
  • Deploy managed databases and storage
  • Manage infrastructure as code
  • Deploy clusters in your own cloud accounts
  • Run GPU workloads
Share this article with your network
X