All work

Architecture study, Online marketplace

A 16-hour backfill was an architecture problem, not an engine problem

A PostgreSQL listings ETL took 16 hours to backfill one large brand against a 4-hour SLA, and the brief asked which engine to move to. The answer was a redesign: an entity model in PostgreSQL that hits the SLA for €0 in new infrastructure, with two bigger architectures nested on top for later.

16h → <4h

backfill SLA target

3–4 wk

to hit the SLA

€0

new infrastructure

≈ €20k

3-year cost, indicative

The brief asked which engine. That was the wrong question.

A PostgreSQL ETL populating an 80-column ads_<make> listings mart took 16 hours to backfill a single large brand against a sub-4-hour SLA. The brief asked which engine to move to. Three facts changed the answer.

  • The 16 hours is a one-time backfill, not the daily run. On an empty mart the watermark falls back to 2018-01-01, so a first run ingests all of history. The daily incremental run (200K–5M rows per country) is already fast: 16 hours for 5M rows would be about 85 rows a second, so the 16 hours can only be the full historical load.
  • A slow backfill freezes the product. The make/model taxonomy is the product’s quality, and improving it means re-deriving the mart. At 16 hours a brand, with 50 brands in each of 15 countries, that is prohibitive: onboarding one country alone means about 50 backfills.
  • The platform has to serve where the business is going: price intelligence, ML deduplication, fraud detection and semantic search. None of that runs on a once-a-day reporting mart.

The slowness is designed in

There are two kinds of cause, and they need different fixes.

Mechanical, fixed by engineering. The job uses 1 of 38 cores. It runs as one 16-hour transaction, which freezes autovacuum across the whole database. It makes tens of millions of per-row UDF calls, re-scans a 3-billion-row price history for every make and portal, and repeats a full four-way join on every run.

Structural, fixed only by redesign. One pipeline does two incompatible jobs. One 80-column table means any change rewrites the whole row. Everything is recomputed instead of precomputed. Analytical work runs row by row in an OLTP engine. And the model is built around listings, while the business is built around items.

Tuning fixes the first list, and that alone gets a PostgreSQL rewrite to 4 hours. Only a redesign fixes the second.

The core insight: the model describes adverts, the business is about items

ads_<make> is keyed one row per listing. But the same physical item appears as many listings: on different portals, and relisted over time. The brief says the mart powers deduplication, collapsing those listings back into one item, yet deduplication has no home in the schema. Deduplication, price history and every AI use case are item-level, and all of them are trapped in an advert-level table.

So model the domain as entities. A listing is one advert on one portal, and many listings resolve to one item, the physical thing. Each listing is placed by a dealer (an SCD2 dimension), each item is classified by the make/model mapping, and each item has a price_event history. Three things follow:

  • Deduplication becomes first-class. Assigning an item_id to listings is entity resolution, and it finally has a home.
  • Analytics get narrow tables. A price change touches one row, not an 80-column rewrite.
  • AI gets a clean substrate. Price models, recommendations and fraud detection all read the entity model.

ads_<make> becomes a view over these entities, so nothing downstream breaks. And dealer, as a dimension, is the natural control point for which personal data reaches which consumer under GDPR.

Three architectures, nested rather than three separate bets

Case 1: Stabilize Case 2: Platformize Case 3: AI-native
Adds Redesign in PostgreSQL: entity model, DuckDB transforms, precomputed price state Debezium CDC to Kafka, ClickHouse serving Iceberg lakehouse, streaming, feature and vector stores
Hits the 4h SLA Yes, structurally Yes, via Case 1 Yes, re-derived continuously
Recurring cost €0 €0 self-hosted, ~€800/mo cloud €1,000–5,000/mo
One-off engineering ≈ €16–24k + ≈ €40–90k A strategic programme
3-year cost, indicative ≈ €20k ≈ €60–145k Strategic-budget scale
Team 1–2 engineers 2–4 engineers 5+, including ML
Timeline 2–3 months, SLA in 3–4 weeks +2–4 months +6–12 months
AI ceiling Low Medium to high Full

Case 2 is Case 1 plus a serving layer and an event backbone; Case 3 is Case 2 plus a lakehouse and ML infrastructure. Because they nest, committing to Case 1 today forecloses nothing. Cost, team size and complexity rise together. The one thing that does not change is that all three hit the SLA, because all three contain Case 1.

Costs assume about €8k loaded cost per engineer-month. All software is open-source, and all data stays in the EU.

How Case 1 hits the SLA

  • Seed job. COPY into index-free partitions, build the indexes in parallel, then ATTACH PARTITION to publish atomically. It is resumable, and chunked by make, portal and listing-id range.
  • Sync job. Resolve the changed listings from mapping first, COPY them to staging, then run a targeted UPDATE … FROM on only the changed rows, so there is no MVCC churn.
  • Transforms in DuckDB. Vectorized and multi-core, reading PostgreSQL or staged Parquet. It moves the join and transform off single-threaded SQL for €0, because DuckDB is a library, not a server.
  • Shift left. Deterministic transforms become GENERATED … STORED columns, and a trigger maintains price_state, so the 3-billion-row scan disappears.
  • Entity model behind a compatibility view, with item_id bootstrapped from a natural key and deterministic rules.

Recommendation: do Case 1 now, and decide the rest on evidence

Now, unconditionally: build Case 1. It hits the SLA in weeks, makes re-deriving the mart cheap, costs €0 in infrastructure, runs across all 15 countries, and is the first phase of Cases 2 and 3, so none of it is wasted.

Later, on evidence. Case 2 when measurement shows analytics is genuinely slow, or taxonomy changes are being throttled. Case 3 when AI products are a funded, staffed strategic commitment. Choosing between them is a strategy-and-funding decision, made later.

What I would not do is the move the brief implied: pick a target engine first. That commits to a destination before the route is known, and migrates a model that has not been fixed.

Phased, and every phase reversible

Phase Delivers Gate
0 · Measure Profile the pipeline and answer the open questions Evidence, not guesses
1 · Split + DuckDB Case 1: the SLA A VW backfill under 4 hours, output bit-identical
2 · Shift left Case 1: precompute, fold the price log Parity-validated
3 · Entity remodel Case 1: the model behind compatibility views Dual-run until parity holds
4 · Serving + CDC Case 2, if chosen Consumers migrate one by one
5 · Lakehouse + ML Case 3, if chosen Staged, each stage valuable on its own

The old pipeline stays behind a feature flag, the rewrite targets the identical ads_<make> schema, and both run side by side until parity holds. The metrics to watch are backfill runtime, the cost of re-deriving after a taxonomy change, row and checksum parity, and analytics p95.

Phase 0 confirms the assumptions the plan rests on: how often a real backfill happens, why price_first and price_last are null (fixing that upstream removes the 3-billion-row scan), whether analytics is measurably slow (the trigger for Case 2), and what the AI strategy is (the trigger for Case 3).

What I traded away

Case 1 keeps analytics on PostgreSQL for now, and its AI ceiling stays low until Case 2 or 3 is funded. That is deliberate. Hitting the SLA first buys the time to choose a platform on measured load, instead of migrating an unfixed model under a deadline.