Skip to main content
Mati Data, home

How I design data platforms

First the choices that set a platform's shape and cost, then the data-intensive systems principles I build it by, each shown in my public code where it can be.

The choices I make first

A few choices set most of a platform's cost and risk before any code is written. My default for each, the options, and where my public work shows it.

  • Warehouse, lake or lakehouse?

    My default: A lakehouse on an open table format when BI and machine learning read the same data. A warehouse when the questions are known, the data is structured and the team is small.

    Warehouse
    The questions are known, the data is structured, and analysts need fast SQL more than raw history.
    Lake
    Raw and semi-structured data has to be kept cheaply for uses nobody has named yet.
    Lakehouse
    BI and machine learning share tables, so open files such as Iceberg or Delta need warehouse guarantees.
  • Managed services or an open lakehouse core?

    My default: Keep the data in open table formats behind a catalog any engine can reach, so an engine can change without moving the data. Buy managed services where they remove real work and leaving stays cheap.

    Fully managed stack
    One provider is a settled choice, the team is small, and having nothing to run matters more than a way out.
    Open format, managed catalog
    Open files and engine choice matter, but the team cannot take on another stateful service to run.
    Open format, open catalog
    Several engines write the same tables, leaving a provider must stay possible, and the team can run stateful services.

    Where it shows

  • ETL, ELT or change data capture?

    My default: ELT with dbt for analytics, so raw data lands once and every transformation is versioned and tested. Change data capture from the database log when freshness or deletes matter.

    ETL
    Sensitive fields must be dropped or masked before data leaves the source, or the target cannot do the work.
    ELT
    The warehouse can transform at scale, and analysts gain from raw history and tested dbt models.
    Change data capture
    Freshness matters, deletes must reach the warehouse, or polling would load the source database.
  • Central, hub-and-spoke or domain ownership?

    My default: Start central, with data contracts at the boundaries so the team does not become the bottleneck later. Move to hub-and-spoke as domains gain their own analysts. A data mesh is an organisational change, not a tool.

    Central
    One team runs one platform for a modest number of sources and consumers.
    Hub-and-spoke
    A platform team keeps the infrastructure and standards while domain teams build their own models.
    Domains (data mesh)
    Domains can own data products end to end, with contracts, documentation and support.
  • Where do definitions live?

    My default: In one place, enforced where data crosses a boundary: a catalog for what exists, a semantic layer for what a number means, lineage for where it came from, and contracts that fail fast.

    Catalog
    People cannot find the data, or cannot tell who owns it.
    Semantic layer
    Teams report different numbers for the same metric.
    Lineage
    A change upstream breaks something downstream and nobody can say what.
    Data contracts
    A producer's change should fail its own build, before consumers see wrong data.

The principles

Each one comes from Designing Data-Intensive Applications or Database Internals, with a real example where my public work shows it.

  1. 1

    Replication and change data capture

    The log is the source of truth

    A database's write-ahead log or binlog already records every change in commit order. Reading changes from the log, instead of querying tables for what looks new, captures deletes, keeps order, and lets any downstream table be rebuilt by replaying it.

    In practice: In wb-cdc-analytics Debezium reads the PostgreSQL write-ahead log through pgoutput instead of polling tables, so deletes arrive as events with the operation and the LSN beside each row, and ClickHouse keeps an immutable event log that the marts can be rebuilt from.

    World Bank CDC analytics: PostgreSQL to ClickHouse, orchestrated by Airflow

  2. 2

    Idempotence and exactly-once semantics

    Every hop is at-least-once, so make duplicates harmless

    Networks retry and consumers crash after writing but before acknowledging. Rather than pretend duplicates cannot happen, design every write to be idempotent: a stable natural key, and a store that collapses a repeated event into the row it repeats.

    In practice: In wb-cdc-analytics the event log is keyed on the Kafka topic, partition and offset, so a redelivered message lands on the row it duplicates, and the fact table is rebuilt with delete-and-insert on the natural key.

    World Bank CDC analytics: PostgreSQL to ClickHouse, orchestrated by Airflow

  3. 3

    Ordering, logical clocks and log positions

    Order by the source's commit order, not by arrival

    Events arrive out of order under retries and parallelism. The newest version of a row is the one with the highest log position at the source, so that position, not the arrival time, decides which version wins.

    In practice: In wb-cdc-analytics the ClickHouse landing tables are ReplacingMergeTree tables versioned by the source LSN, so the newest version of a row follows PostgreSQL's commit order even when its events arrive out of order.

    World Bank CDC analytics: PostgreSQL to ClickHouse, orchestrated by Airflow

  4. 4

    Transactions and atomic commit

    Commit the data and the watermark together

    A pipeline that records progress separately from the data it wrote can claim work that rolled back, or redo work that succeeded. Writing the data and the new watermark in one transaction makes a retried run either fully applied or not at all.

    In practice: In wb-cdc-analytics the rows, the audit row and the watermark commit in one PostgreSQL transaction, so a recorded position can never claim work that rolled back, and a second run of the same data writes nothing.

    World Bank CDC analytics: PostgreSQL to ClickHouse, orchestrated by Airflow

  5. 5

    Storage engines: B-trees, log-structured and merge trees

    Choose the storage engine for the access pattern

    B-tree row stores serve transactions and point lookups; log-structured and merge-tree engines trade write cost for scan speed and merge in the background. Each engine's merge and compaction behaviour decides when a read is correct, not only how fast it is.

    In practice: ClickHouse ReplacingMergeTree deduplicates only when parts merge, so a plain SELECT can legitimately return duplicates. In wb-cdc-analytics correct reads go through one shared macro that applies FINAL and drops tombstones.

    World Bank CDC analytics: PostgreSQL to ClickHouse, orchestrated by Airflow

  6. 6

    Sharding and partitioning

    Partition when the data asks for it

    Partitioning pays off when it prunes scans or lets retention drop whole partitions. Below that size it only creates many small parts, slower merges and, in merge-tree engines, a path to refused inserts. The trigger for partitioning belongs in writing, next to the design.

    In practice: The reference CDC pipeline deliberately does not partition its tables at its current size, and documents the volume and retention conditions under which monthly partitions become worth it.

    World Bank CDC analytics: PostgreSQL to ClickHouse, orchestrated by Airflow

  7. 7

    Reliability and faults

    Design for the failure that raises no error

    The expensive failures are the quiet ones: a component that keeps running while producing wrong data. Where a design can fail loudly or fail silently, choose loudly: reject bad rows with a reason, gate models on contracts, and alert on drift.

    In practice: In wb-cdc-analytics the Kafka engine reads raw JSON and types it in materialized views, because typed Kafka-engine columns turn one parse failure into a consumer that retries forever without an error. CDC lag is measured against a heartbeat, so a stopped connector cannot look like a quiet table.

    World Bank CDC analytics: PostgreSQL to ClickHouse, orchestrated by Airflow

  8. 8

    Concurrency and resource contention

    Schedule shared resources before buying bigger ones

    Many performance incidents are contention, not capacity: jobs that each run fine collide when they start at the same moment. Spreading the work across time is often cheaper and safer than a larger instance.

References I design from

  • Designing Data-Intensive Applications, 2nd edition

    Martin Kleppmann and Chris Riccomini

    The vocabulary I use in design reviews: replication, sharding, transactions, consistency, and batch and stream processing, with the tradeoffs between them.

  • Database Internals

    Alex Petrov

    How storage engines and distributed databases work underneath: B-trees and log-structured storage, then replication, consistency and consensus.