---
title: "Lago - Using ClickHouse to Scale an Events Engine"
description: "Lago, an open-source usage-based billing platform ingesting millions of events per minute, moved its streamed billable events from Postgres to ClickHouse Cloud and kept Postgres for all other transactional data."
url: "https://swe.quest/articles/lago-using-clickhouse-to-scale-an-events-engine-c476ec4bca3b5c9d"
canonical: "https://clickhouse.com/blog/lago-using-clickhouse-to-scale-an-events-engine"
source: "ClickHouse"
published: "2024-05-29"
difficulty: "medium"
kind: "Case study"
reading_minutes: 7
tags: ["analytics","postgres","payments","performance","databases"]
---

# Lago - Using ClickHouse to Scale an Events Engine

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2024-05-29, 7 min read, Case study. Original: [https://clickhouse.com/blog/lago-using-clickhouse-to-scale-an-events-engine](https://clickhouse.com/blog/lago-using-clickhouse-to-scale-an-events-engine)

## Summary

Lago, an open-source usage-based billing platform ingesting millions of events per minute, moved its streamed billable events from Postgres to ClickHouse Cloud and kept Postgres for all other transactional data. The ClickHouse side is small: a Kafka-engine queue table, a materialized view that maps event metadata from JSON into a string array, and a MergeTree raw\_events table keyed on organization, subscription, code and timestamp. Aggregation queries got 18x to 137x faster; for example, a weighted sum dropped from 6.6s to 48ms. The post also covers OLTP vs OLAP tradeoffs, columnar storage, insert-time materialized views and vectorized execution.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Payments & fintech](https://swe.quest/tags/payments.md) (Domains)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- SQL databases ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- OLTP vs OLAP basics ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, PostgreSQL, Lago, Kafka, MergeTree, ClickHouse Cloud, Ruby on Rails

## Related posts

- [Data Hive: The story of beehiiv’s journey from Postgres to ClickHouse](https://swe.quest/articles/data-hive-the-story-of-beehiiv-s-journey-from-postgres-to-clickhouse-467867cb2bebb87b.md): ClickHouse · 2024-08-21 · Easy · 6 min read · Analytics & OLAP, Databases, PostgreSQL, Stream processing, Queues & messaging
  beehiiv replaced its Postgres-and-Ruby-queue analytics system, which struggled with billions of email events and had multi-hour reporting delays, with a Kafka-fed ClickHouse Cloud pipeline.
- [98% faster queries, 50% lower cloud costs: Verihubs’ journey from Postgres to ClickHouse](https://swe.quest/articles/98-faster-queries-50-lower-cloud-costs-verihubs-journey-from-postgres-to-f6535061aff525b1.md): ClickHouse · 2026-07-06 · Medium · 6 min read · Analytics & OLAP, Data pipelines, PostgreSQL, Event-driven architecture
  Verihubs replaced a Postgres warehouse fed by daily Airflow batch pulls with a ClickHouse-based real-time OLAP stack.
- [How GitLab serves sub-second analytics to 50 million users](https://swe.quest/articles/how-gitlab-serves-sub-second-analytics-to-50-million-users-cabf627f25c869fd.md): ClickHouse · 2025-10-21 · Easy · 10 min read · Analytics & OLAP, PostgreSQL, Databases, Scaling
  GitLab moved its user-facing product analytics from Postgres to ClickHouse after dashboards repeatedly hit its 15-second performance ceiling.
- [Front-end observability at scale: How OpenReplay captures billions of daily events in real time with ClickHouse](https://swe.quest/articles/front-end-observability-at-scale-how-openreplay-captures-billions-of-daily-b210d948927bb0e9.md): ClickHouse · 2026-10-21 · Easy · 8 min read · Analytics & OLAP, Observability, Data pipelines, PostgreSQL, Scaling
  OpenReplay, a self-hosted session replay and product analytics platform, moved behavioral event storage from Postgres to ClickHouse.
- [How Kami scaled from 80M to nearly 2B events per week with ClickHouse](https://swe.quest/articles/how-kami-scaled-from-80m-to-nearly-2b-events-per-week-with-clickhouse-77ce1b06efbf532e.md): ClickHouse · 2025-05-16 · Medium · 7 min read · Analytics & OLAP, Data pipelines, PostgreSQL, Scaling, Schema migrations
  Kami's Postgres event tracking (Rails writing JSONB rows, queried via Redash) collapsed when COVID pushed weekly events from about 80M to nearly 2B.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
