<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/postgres-vs-clickhouse-is-the-wrong-question-i-use-both--kj77irn0i" -->

---
title: Postgres vs ClickHouse is the wrong question. I use both.
description: A practical breakdown of when to use Postgres versus ClickHouse in the same application, using an uptime monitoring platform as a real-world example. The core...
canonical: https://daily.dev/posts/postgres-vs-clickhouse-is-the-wrong-question-i-use-both--kj77irn0i
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Postgres vs ClickHouse is the wrong question. I use both. | daily.dev
og:description: A practical breakdown of when to use Postgres versus ClickHouse in the same application, using an uptime monitoring platform as a real-world example. The core...
og:url: https://daily.dev/posts/postgres-vs-clickhouse-is-the-wrong-question-i-use-both--kj77irn0i
og:image: https://api.daily.dev/og/posts/KJ77irn0i.png
og:image:alt: Postgres vs ClickHouse is the wrong question. I use both.
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Postgres vs ClickHouse is the wrong question. I use both.

**[Medium](https://daily.dev/sources/medium_js)** · 9 min read · 0 upvotes · 0 comments

## Summary

A practical breakdown of when to use Postgres versus ClickHouse in the same application, using an uptime monitoring platform as a real-world example. The core rule: split data by how it is written — mutable rows with constraints belong in Postgres, append-only streams belong in ClickHouse. Covers four concrete ClickHouse techniques: choosing codecs by data shape (DoubleDelta for steady timestamps, T64 for small-range integers), putting tenant IDs in the sort key rather than the partition key, per-row TTL columns for flexible retention without migrations, and enabling non-replicated deduplication to make retried inserts idempotent. Also includes a materialized view pattern for rolling up raw check results into per-minute and per-hour summaries to keep dashboard queries fast.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://medium.com/@slima4/postgres-vs-clickhouse-is-the-wrong-question-i-use-both-5b5a1c2f2f64>

## Questions this post answers

### Should I partition ClickHouse tables by tenant ID (org_id) in a multi-tenant application?

No, the tenant ID should go in the ORDER BY sort key, not the PARTITION BY clause. Partitioning by org_id in a multi-tenant ClickHouse setup created a flood of tiny parts, merges couldn't keep up, and startup got slower as customer count grew. Instead, partition by something low-cardinality you delete by, like day (toYYYYMMDD(timestamp)), and put org_id first in ORDER BY so per-org queries walk the sorted primary index efficiently.

_Anyone tuning ClickHouse schemas for multi-tenant workloads can compare real-world partitioning lessons on daily.dev._

### How do I make ClickHouse inserts idempotent to avoid duplicate rows from retried batches?

Enable non_replicated_deduplication_window on a plain (non-Replicated) MergeTree table, which is off by default. ClickHouse hashes each inserted block and remembers a configurable number of recent hashes (e.g. 1000); a retried block with an identical hash gets dropped instead of appended again. Set the window larger than the maximum number of blocks a single retry could resend so duplicate inserts from network blips never double-count data.

_Developers hardening ClickHouse ingestion pipelines against retries can track patterns like this on daily.dev._

### Which ClickHouse compression codec should I use for a steady-interval timestamp column?

Use CODEC(DoubleDelta, ZSTD(1)) for timestamps recorded at a steady interval, such as every 20 seconds. DoubleDelta stores the change in the change, so for a constant interval the deltas collapse to nearly zero, packing each row after the first down to about a bit. The codec originates from Facebook's Gorilla time-series paper. Use T64 instead for small-range integers like latency in milliseconds, which have a different value shape than a steady clock.

_Engineers picking ClickHouse codecs for time-series columns can compare real schema tricks on daily.dev._

## Similar posts on daily.dev

- [ClickHouse vs PostgreSQL: Choosing the Right Database for Analytics](https://daily.dev/posts/clickhouse-vs-postgresql-choosing-the-right-database-for-analytics-ckxz2ek9o) · BigData Boutique blog · 3 upvotes · 0 comments
- [Switching from PostgreSQL to ClickHouse for Improved Performance and Scalability](https://daily.dev/posts/switching-from-postgresql-to-clickhouse-for-improved-performance-and-scalability-kjtwee69g) · InfoQ · 5 upvotes · 0 comments
- [Postgres \+ ClickHouse: The OSS Stack To Handle Agentic AI Scale](https://daily.dev/posts/postgres-clickhouse-the-oss-stack-to-handle-agentic-ai-scale-porzekft6) · The New Stack · 1 upvotes · 0 comments
- [Postgres vs MariaDB](https://daily.dev/posts/postgres-vs-mariadb-sp1u6ijeb) · Tinybird · 0 upvotes · 0 comments

---

Tags: [#data-science](https://daily.dev/tags/data-science), [#postgresql](https://daily.dev/tags/postgresql), [#clickhouse](https://daily.dev/tags/clickhouse)

[View this post on daily.dev](https://daily.dev/posts/postgres-vs-clickhouse-is-the-wrong-question-i-use-both--kj77irn0i)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Postgres vs ClickHouse is the wrong question. I use both.","url":"https://daily.dev/posts/postgres-vs-clickhouse-is-the-wrong-question-i-use-both--kj77irn0i","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/postgres-vs-clickhouse-is-the-wrong-question-i-use-both--kj77irn0i"},"datePublished":"2026-07-23T19:30:36.948Z","dateModified":"2026-09-13T19:28:30.558Z","description":"A practical breakdown of when to use Postgres versus ClickHouse in the same application, using an uptime monitoring platform as a real-world example. The core...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b5819a9874c08f7ea95b581fbce03d79?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b5819a9874c08f7ea95b581fbce03d79?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/postgres-vs-clickhouse-is-the-wrong-question-i-use-both--kj77irn0i","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"data-science,postgresql,clickhouse","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"Postgres vs ClickHouse is the wrong question. I use both."}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/postgres-vs-clickhouse-is-the-wrong-question-i-use-both--kj77irn0i#faq","mainEntity":[{"@type":"Question","name":"Should I partition ClickHouse tables by tenant ID (org_id) in a multi-tenant application?","acceptedAnswer":{"@type":"Answer","text":"No, the tenant ID should go in the ORDER BY sort key, not the PARTITION BY clause. Partitioning by org_id in a multi-tenant ClickHouse setup created a flood of tiny parts, merges couldn't keep up, and startup got slower as customer count grew. Instead, partition by something low-cardinality you delete by, like day (toYYYYMMDD(timestamp)), and put org_id first in ORDER BY so per-org queries walk the sorted primary index efficiently. Anyone tuning ClickHouse schemas for multi-tenant workloads can compare real-world partitioning lessons on daily.dev."}},{"@type":"Question","name":"How do I make ClickHouse inserts idempotent to avoid duplicate rows from retried batches?","acceptedAnswer":{"@type":"Answer","text":"Enable non_replicated_deduplication_window on a plain (non-Replicated) MergeTree table, which is off by default. ClickHouse hashes each inserted block and remembers a configurable number of recent hashes (e.g. 1000); a retried block with an identical hash gets dropped instead of appended again. Set the window larger than the maximum number of blocks a single retry could resend so duplicate inserts from network blips never double-count data. Developers hardening ClickHouse ingestion pipelines against retries can track patterns like this on daily.dev."}},{"@type":"Question","name":"Which ClickHouse compression codec should I use for a steady-interval timestamp column?","acceptedAnswer":{"@type":"Answer","text":"Use CODEC(DoubleDelta, ZSTD(1)) for timestamps recorded at a steady interval, such as every 20 seconds. DoubleDelta stores the change in the change, so for a constant interval the deltas collapse to nearly zero, packing each row after the first down to about a bit. The codec originates from Facebook's Gorilla time-series paper. Use T64 instead for small-range integers like latency in milliseconds, which have a different value shape than a steady clock. Engineers picking ClickHouse codecs for time-series columns can compare real schema tricks on daily.dev."}}]}
```

