PostHog Dossier • Architecture • Pipeline Engineering

PostHog Architecture & ClickHouse Teardown

A technical teardown of PostHog's data path: from client browser telemetry to Rust ingestion workers, Kafka streaming queues, and ClickHouse table engines.

1. The Ingestion Pipeline: Capture to ClickHouse

When a web or mobile application invokes posthog.capture(), the event payload travels through a high-speed ingestion gateway written in Rust (Capture service). This gateway validates incoming tokens, rate-limits abusive clients, and immediately streams the raw JSON payloads into an Apache Kafka topic.

Plugin workers pull batches of events from Kafka, execute enrichment scripts (such as IP geo-lookups and user property assignment), and perform bulk insert operations into ClickHouse's sharded_events table using the ReplacingMergeTree engine.

2. Session Replay via rrweb DOM Serialization

Unlike video recording which consumes massive network bandwidth, PostHog's session replay engine uses rrweb. When a user visits a page, the library creates an initial snapshot of the Document Object Model (DOM) as a lightweight tree structure.

Subsequent user actions (mouse movements, clicks, keystrokes, and DOM mutations) are recorded as a continuous stream of JSON delta events. When playing back a session, PostHog reconstructs the DOM inside an isolated iframe and applies the recorded mutations in real time, consuming less than 50 KB of network bandwidth per minute.

← PostHog Overview Query Benchmarks →
Arkajit Das
Author • Verified Entity

Co-Founder & Chief Product Officer at Fraoula. Technology product executive leading enterprise AI, data platform architecture, and distributed systems.