I came across a thread on r/Database and couldn't stop thinking about it. The author runs an on-prem PostgreSQL 14 deployment: ~40 TB logical, ~500 billion rows of IoT telemetry, partitioned by business day, with a primary and read replica in separate data centres. Performance today is fine. The question is whether to shard Postgres, move to ClickHouse, or reach for something else as the system grows.
The detail that matters isn't the size — it's the workload shape. The queries are point lookups: every column for one device over a 4–5 day range, up to a million times an hour, each under 100 ms. That's OLTP, not analytics. Most of the confident answers in the thread assumed otherwise.
I run Oracle, Aurora PostgreSQL, MongoDB, and Elasticsearch across a large AWS estate, so I used the thread as a springboard: I interviewed an AI across every sharding model I touch, pushing hardest on the parts I already had opinions about. What follows is that conversation, edited — the questions and the judgment are mine.
Is sharding just partitioning with pg_partman?
Q. When people say "shard Postgres," is that the same as partitioning a big table with pg_partman?
A. No — the axis is location. Partitioning (pg_partman's job) splits one logical table into child tables on the same server and disk; it automates partition creation and retention drops and never crosses a machine boundary. Sharding splits rows across independent servers, each with its own CPU, RAM, and disk. Postgres has no native sharding — you reach for Citus, application-level routing, or postgres_fdw. Partitioning buys single-node maintainability (partition pruning, cheap retention via DROP TABLE); sharding buys capacity. They compose: each shard is usually time-partitioned internally.
My take. The OP was already partitioning; sharding by device_id is a categorically heavier move, not an extension of it. For an indexed point-lookup workload, data size at rest doesn't slow queries — partition pruning does the work regardless of total size. The real pain at 40 TB is operational: backup, restore, and major-version upgrades. "Big and nervous" is not a workload description. Size and access pattern are different axes, and conflating them is how teams talk themselves into migrations they don't need.
So is ClickHouse the answer?
Q. Half the thread says move to ClickHouse. What is it, and does it fit?
A. ClickHouse is a columnar OLAP engine. A row store (Postgres) keeps a row's columns contiguous — ideal for fetching or updating whole records by key. A column store keeps each column contiguous and compressed, so a scan reads only the columns it needs. That, plus a sort key, is why aggregations fly. The OP is tempted by two numbers: 16× compression (vs their 5×) and native sharding. But their access pattern is point lookups — reconstruct all columns of one row — which scatters reads across separate column files. The right sort key makes it tolerable, but you're fighting the engine and giving up transactions and efficient single-row operations.
My take. Point lookup = index-jump to a few adjacent rows. Aggregation scan = sweep one column across billions. ClickHouse is built for the second; this workload is the first. Compression and native sharding are the wrong reasons to pick an OLAP engine for an OLTP shape. Reach for ClickHouse exactly where the OP said they have no need: large aggregations over append-only history.
Once you shard Postgres, how do standby and DR work?
Q. After sharding, is one shard's data replicated to another node as a secondary? How do HA and DR work?
A. Sharding and replication are orthogonal. Sharding alone gives zero redundancy. Each shard gets its own standby via ordinary streaming replication; shards don't back each other up. The coordinator (which holds the shard map) needs its own standby too. DR's catch: shards replicate independently and asynchronously, so a cross-region copy is not a globally consistent snapshot — a cross-shard 2PC transaction can be committed on one shard's replica and not another's. A regional failover becomes an orchestration problem (promote every shard plus the coordinator), and point-in-time recovery means coordinating a recovery target across all shards.
My take. This is the hidden tax of DIY sharding, and it doesn't show up in a proof of concept. One primary/standby pair I can reason about completely; N shards plus a coordinator — each its own failover domain — explodes the operational surface. The cross-shard consistency gap is the one I'd lose sleep over: DR looks fine until you fail over mid-transaction and the shards disagree. Budget as much design time for failover and restore as for the sharding itself.
The managed option: Amazon Aurora Limitless
Q. If I don't want to hand-roll sharding, how does Amazon's own sharded Postgres — Aurora Limitless — handle standby and DR?
A. Strong in-region, weaker cross-region. Storage: six copies across three Availability Zones, so durability is automatic. Compute: you choose 0, 1, or 2 standbys per node at shard-group creation for fast failover. Cross-shard writes use two-phase commit, and Aurora recovers in-flight prepared transactions on failover — no half-committed cross-shard write. It carries a 99.99% availability SLA. The catch: Aurora Global Database — the usual cross-region mechanism (~5 s RPO, sub-minute RTO) — is not supported for Limitless, and a Limitless cluster can't be a replication source. Cross-region DR falls back to copying a cluster snapshot and restoring: coarse, manual, higher RPO and RTO.
My take. This is the finding that would most shape my decision — and I only trust it because I checked the live AWS docs rather than memory; these managed-service limits shift between releases. In-region, Limitless removes the hardest parts of DIY sharding: coordinator HA and cross-shard transaction recovery are handled for me. But losing Global Database is a real DR downgrade — the failover/failback pattern I rely on elsewhere simply doesn't apply, so a Limitless cluster needs a snapshot-based runbook. If low-RPO cross-region DR is a hard requirement, that gap is where the risk concentrates. Verify it at build time.
A real schema isn't one big table
Q. My databases mix partitioned fact tables, several metadata tables, config tables, and transactional logging tables. How does that survive sharding?
A. Sort every table into one of three placements:
- Distributed (sharded) — large tables split by a shard key: your fact tables and high-volume logs. Time partitioning composes within each shard.
- Reference — small, read-heavy tables that everything joins against (metadata, most config): a full copy on every node so joins stay local; writes cost more because they touch every copy (2PC).
- Local — small, self-contained tables that live on one node.
The make-or-break concept is colocation: related sharded tables must share the shard key so their matching shards sit together and joins stay local. The constraints you inherit are the real work — foreign keys only across colocated tables or to reference tables, unique keys must include the shard key, and cross-shard transactions run through 2PC.
My take. The shift is from "how do I shard my database" to "what role does each table play, so where should its rows live." Then a messy schema sorts itself quickly: big and keyed by the common column → sharded and colocated; small and universally joined → reference; everything else → local. Log tables are the cleanest to shard — append-only, no joins to colocate, time partitioning already handles retention. Most of the migration effort isn't the big tables; it's reconciling the foreign keys and unique constraints that quietly assumed a single node.
How is MongoDB different — and is data copied between shards?
Q. How does Mongo sharding differ from Postgres, and is data replicated between the shards?
A. Between shards, no — each shard holds a disjoint subset. Within a shard, always: every MongoDB shard is itself a replica set. Replication is the native building block, not a bolt-on — the biggest contrast with Postgres, where you assemble the two yourself. Three tiers: stateless mongos routers (the coordinator), a config-server replica set holding the chunk map (the metadata), and the shards. Mongo auto-rebalances via a background balancer (Citus is manual). It pursues locality through embedding — denormalize related data into one document so it lives on one shard — versus Postgres colocation and reference tables. DR is just placing replica-set members across regions; failover is the ordinary election, uniform on every shard.
My take. Let me be precise, because two things are easy to conflate: data replicates within each shard (to its secondaries), never between shards — the shards hold disjoint data. And that within-shard replication isn't optional: MongoDB requires every production shard to be a replica set. That's exactly the part I'd push back on operationally. A production sharded cluster isn't one system, it's many — a replica set per shard, plus a config-server replica set, plus the mongos routers. Several clusters to patch, back up, monitor, and fail over — the cost that never shows up in a demo. The upside is that geographic DR is uniform (place replica-set members across regions) and the thing I already operate is the shard. But if the appeal of a model is "one cluster that manages itself," Mongo's many-replica-sets topology sits at the opposite end of that spectrum — a fair reason to prefer something like Elasticsearch, where the cluster is a single self-balancing unit. The trade Mongo extracts for its locality is the join: you design around it by embedding at write time.
The model I like most: Elasticsearch's elastic shards
Q. Of all of these, I like Elasticsearch's model best — primaries and replicas, per index or cluster-wide, replicas that serve traffic, and no index-tuning guesswork. Joins between indices are bad; if I must, I join in the application on a common key. Am I right to like it this much?
A. Well-founded, with two asterisks. The real wins: Elasticsearch decouples the two axes Postgres fuses — primaries are the partitioning knob, replicas the replication knob, independently dialable — and replicas aren't passive standbys; they actively serve searches, so scaling them buys redundancy and read throughput in one dynamic setting. The operational self-management beats babysitting per-shard Postgres replication. And index-free, tokenized search inverts the Postgres game: everything is indexed, and the analyzer pipeline gives linguistic matching for free. Asterisk 1: only replicas are elastic — primary count is fixed at index creation, so raising it means a reindex (oversharding is the classic footgun). Asterisk 2: the tuning work doesn't vanish, it moves — from reactive query-and-index tuning to getting mappings and analyzers right up front, which is harder to change later. It earns the elegance by relaxing what a system of record provides: no multi-document ACID, no real joins, near-real-time (refresh-based) rather than immediate visibility.
My take. The application-side join on a common key is the correct, idiomatic answer — just go in knowing it has no cross-index transactional consistency and won't scale like a colocated relational join. The idiomatic next step when it hurts isn't "join better," it's to denormalize at write time so the join mostly disappears — the same instinct as Mongo embedding. What I love is what you'd love: the operational smoothness, the shard management the cluster just handles, and not having to guess indexes. But I keep the asterisk visible — it's superior at its job (search, analytics, horizontal read scale), not superior in general.
The architecture, side by side
| Dimension | Postgres + Citus | Aurora Limitless | MongoDB | Elasticsearch | ClickHouse |
|---|---|---|---|---|---|
| Distribution unit | Shard (hash/range of key) | Shard (hash of key) | Chunk (shard-key range) | Primary shard (Lucene index) | Shard (sharding key) |
| Replication | Per-node streaming (you add it) | 6-way storage + 0–2 compute standbys | Replica set per shard (native) | Replica shards, live, serve reads | ReplicatedMergeTree per shard |
| Rebalancing | Manual (rebalance_table_shards) |
Managed | Automatic balancer | Automatic shard allocation | Manual |
| Routing / metadata | Coordinator | Transaction routers (managed) |
mongos + config-server RS |
Any node (cluster state) | Distributed table / cluster config |
| Cross-shard txn | 2PC | 2PC, recovered on failover | Multi-doc txn (4.2+) | None | Limited |
| Cross-region DR | Per-shard replica (DIY) | Snapshot copy (no Global DB) | Replica-set member placement | Cross-cluster replication | Replication / backup |
| Join strategy | Colocation + reference tables | Colocation + reference tables | Embed / app-side | App-side / denormalize | Mostly denormalize |
| Consistency / visibility | Strong, immediate | Strong, immediate | Tunable read/write concern | Near-real-time (refresh) | Eventually consistent inserts |
Architectural areas worth probing further
A short map for anyone taking this past the blog-post stage:
- Shard-key choice and skew. Hashed keys spread writes evenly but kill range scans; ranged keys enable pruning but risk hot ranges. A monotonic key (timestamp, sequence) sends every new write to the last shard — the classic hotspot.
- Rebalancing and online data movement. Adding a shard means moving data: Mongo chunk migration and Elasticsearch shard relocation are throttled background work; Citus shard moves are operator-driven. All of it competes with live traffic.
-
The router/coordinator as bottleneck and SPOF. Stateless
mongosscale out trivially; a Citus coordinator needs its own HA and a connection-pooling layer (PgBouncer) in front of fan-out queries. - Cross-shard transactions. 2PC adds latency and a prepared-transaction recovery path you must test; the cheapest distributed transaction is the one your data model avoids.
- Backup and restore topology. Per-shard snapshots, consistent recovery targets across shards, and crash-consistent multi-volume snapshots are their own design problem at scale.
- Observability. Per-shard metrics, replica lag per shard, balancer queue depth, and hot-shard detection — a single cluster-wide dashboard hides the shard that's on fire.
- Capacity and shard sizing. Keep shards in a sane size band; oversharding wastes heap and metadata, undersharding limits parallelism. Elasticsearch's own guidance (tens of GB per shard) exists for exactly this reason.
Where I land: the conservation law of sharding
One pattern falls out of every system here: each model makes cross-partition work cheap by making something else your problem. Citus gives you relational joins but makes you choose a shard key and colocate. Aurora Limitless hands you managed in-region HA but takes away Global Database. MongoDB and Elasticsearch give you effortless elastic distribution but hand the join back to your application, nudging you to denormalize at write time. Nobody escapes the trade — they relocate it: to the shard key, the mapping, the ingestion pipeline, or the app.
So why does Elasticsearch win for me on the axes I care about — operational smoothness and index-free querying? The same thing that makes it that good is why it hands the join back: it moved the hard decisions to write time and kept the read path simple. For a decide-it-once design temperament over continuous reactive tuning, that's a trade I keep wanting to make. But I keep my source of truth in the thing that will still say no to a half-committed transaction. These systems coexist as layers, not rivals: a relational or document store as the system of record (correctness, transactions, relationships), and Elasticsearch as the search/analytics tier fed from it by change data capture. Elasticsearch gets its elastic-replica elegance precisely because something upstream is holding the ACID line.
The lens I'd offer anyone staring at a sharding decision: stop asking which model is best, and start asking which guarantee you refuse to give up. That answer — not the row count — tells you where the cost is allowed to land.
How you found this — and how I research with AI
You probably arrived here from a search or a shared link, chasing the same question that pulled me in. That's how I learn new topics now, and the method matters as much as the answer. I didn't start from a course — I started from a real artifact (a messy 40 TB Reddit thread) and used the AI as an interview subject, not an oracle: explain, push back with what I know, make it defend the parts that sound too neat, and verify the one answer that could go stale (Limitless and Global Database) against the live vendor docs rather than trusting recall. The AI is fast and broad; my job is judgment, production scars, and skepticism.
Four habits if you want to try it: anchor on something real (a concrete scenario forces concrete answers); interrogate rather than accept (ask why, ask what it trades away, ask where it breaks); verify anything time-sensitive — versions, limits, pricing, managed-service features — against primary sources; and translate each answer back through your own experience, because that's what turns information into understanding. Writing it up is the test of whether I actually learned it.
I write about the systems I run day to day — this is one of a series.
Sources & further reading
Every claim here is grounded in primary documentation. One caveat on method: managed-service limits (Aurora Limitless especially) shift between releases, so verify against the live docs before you design around them.
The original thread
Partitioning and Postgres sharding (Citus)
- PostgreSQL — Table Partitioning
- pg_partman
- Citus — Concepts: distributed, reference, and local tables; algorithmic sharding
- Citus — Creating and Modifying Distributed Objects (DDL): colocation, foreign-key rules, 2PC on reference tables
ClickHouse
Amazon Aurora Limitless
- Requirements and considerations — Aurora Global Database, read replicas, and acting as a replication source are all listed under "features not supported"
- Backing up and restoring Aurora PostgreSQL Limitless Database
MongoDB sharding
- Sharding — each shard must be deployed as a replica set;
mongos; config servers - Sharded cluster components
- Shards — must be deployed as a replica set to provide redundancy and high availability
Elasticsearch






Top comments (0)