Trench is an open-source analytics infrastructure designed for teams that need scalable, real-time event tracking without the complexity of managing Kafka and ClickHouse separately. Built by Frigade to solve their own scaling bottlenecks, it replaces slow Postgres-based event tables with a high-throughput system capable of processing thousands of events per second on a single node. It’s ideal for product teams, SaaS founders, and engineers building analytics dashboards, user behavior pipelines, or LLM RAG data sources.
Trench packages Kafka for event ingestion, ClickHouse for fast SQL queries, and a Node.js API layer into a single Docker image. It supports self-hosting on any cloud provider with full control over data, or via a managed Cloud option with serverless autoscaling. The system is GDPR and PECR compliant, with full data access, rectification, and deletion controls. It’s compatible with Segment’s Track, Identify, and Group APIs, making it a drop-in replacement for tools like PostHog or Matomo.
What You Get
- Segment API Compliance - Supports Track, Identify, and Group events using the exact Segment API schema, enabling seamless migration from tools like PostHog or Mixpanel.
- Single Production-Ready Docker Image - Deploys Kafka, ClickHouse, and the Node.js API in one containerized stack with pre-configured best practices, eliminating manual infrastructure setup.
- Real-Time SQL Queries - Query event data directly via REST API or raw SQL against ClickHouse, enabling ad-hoc analysis without pre-built dashboards.
- Kafka-Based Event Ingestion - Handles thousands of events per second on a single node using Apache Kafka’s distributed streaming capabilities for high throughput and durability.
- GDPR & PECR Compliant - No cookies used; users have full control to access, rectify, or delete their event data with built-in data governance controls.
- Webhook Integration - Send event data to external systems (e.g., Slack, CRM, LLMs) via configurable, throttled webhooks with custom payload templates.
Common Use Cases
- Building a product analytics dashboard - A SaaS founder uses Trench to track user interactions (e.g., button clicks, feature usage) and visualizes them in Grafana using real-time SQL queries.
- Powering LLM RAG systems with user behavior data - An AI startup ingests user event streams into Trench and uses the data as context for RAG prompts to personalize AI responses.
- Replacing Postgres-based event tracking at scale - A startup migrates from a bloated Postgres events table to Trench, reducing infrastructure costs by 42% and eliminating query latency spikes during traffic surges.
- Running a compliance-first analytics stack - A European fintech company uses Trench to track user activity without cookies, ensuring full GDPR compliance while maintaining real-time analytics.
Under The Hood
Architecture
- Monorepo structure with Turbo and pnpm enables independent development of applications and shared packages, promoting reuse and consistency
- NestJS enforces modular design through clearly defined modules, dependency injection, and layered separation of controllers, services, and data access objects
- Authentication and authorization are cleanly abstracted via guards, keeping business logic decoupled from HTTP concerns
- Kafka and Redis are integrated via dependency injection to support event streaming and caching without tight coupling
- Tooling pipeline with Turbo ensures parallelized builds and tests, while TypeScript path aliases enhance type safety and maintainability
Tech Stack
- Node.js backend powered by NestJS with Fastify as the HTTP server, supporting static asset serving and high-performance routing
- Event ingestion and analytics rely on Kafka for streaming and ClickHouse for scalable storage, forming a high-throughput data pipeline
- GraphQL API is exposed via Mercurius with Swagger documentation for developer ergonomics
- Testing stack includes Jest and Supertest with reusable utilities for authentication and polling, ensuring robust end-to-end validation
- Caching is handled by Redis and cache-manager, while TypeORM manages relational data and scheduled tasks via @nestjs/schedule
Code Quality
- Extensive end-to-end and unit tests cover API behavior, query parsing, and webhook logic with precise assertions and realistic scenarios
- Strong TypeScript typing is applied consistently across APIs, Kafka events, and response structures, minimizing runtime errors
- Clear naming conventions and separation of test layers (E2E, unit, plugin) improve readability and maintainability
- Centralized test utilities reduce duplication and enhance test reliability, though error handling could benefit from custom error classes
What Makes It Unique
- Native ClickHouse integration with real-time Kafka streaming eliminates the need for external ETL pipelines
- Custom date formatting and string escaping utilities are purpose-built for ClickHouse query safety, mitigating injection risks at the data layer
- Modular NestJS architecture allows independent scaling of data ingestion and analytics components
- Bootstrap service provides a unified entry point for initializing distributed system state
- Event-driven pipeline decouples ingestion from querying, enabling asynchronous, high-volume event processing
- Built-in migration tracking with checksum validation ensures schema integrity across deployments without external tooling