Skip to content

Part 8 · Blueprint 47

Real-Time OLAP & Columnar Analytics (ClickHouse / Apache Pinot)

15 min reading · Sources · Editorial review pending

Interactive scans improve when layout matches filters and aggregations, not merely because storage is columnar.

More
20px
Reading list
Page details

Published date · Last edited:

Draft edition. Editorial review and supplementary reading recommendations are still being completed.

Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Indexes & Storage Engines: B-Trees vs. LSM Trees, Database Sharding & Consistent Hashing, Real-Time Stream Processing Engine (Apache Flink Internals).

Sixty-second mental model

Problem: Interactive scans improve when layout matches filters and aggregations, not merely because storage is columnar.

Use: Choose sort keys, partitions and pre-aggregation from the query mix.

Design boundary: Serve large analytical scans by storing selected columns and pruning irrelevant parts. Sorting, partitioning and aggregation must follow query patterns rather than transactional point-lookup assumptions.

Layer 1 · Intuition

Hypothetical scenario: Northwind is designing columnar analytics. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one scanned row means and which component owns the analytical table snapshot.

Think of reading selected columns from many ledger pages. Separate the requester from analytical table snapshot, then identify the retained evidence needed after failure.

Authority
The entitled state owner.
Invariant
A rule preserved across concurrency and failures.

Architecture and worked reasoning

Design boundary: Serve large analytical scans by storing selected columns and pruning irrelevant parts. Sorting, partitioning and aggregation must follow query patterns rather than transactional point-lookup assumptions.

Responsibilities on the request path

Columnar analytics: responsibilities and request directionServe large analytical scans by storing selected columns and pruning irrelevant parts. Sorting, partitioning and aggregation must follow query patterns rather than transactional point-lookup assumptions.Ingest bufferColumn partsSparse indexQuery aggregator
Serve large analytical scans by storing selected columns and pruning irrelevant parts. Sorting, partitioning and aggregation must follow query patterns rather than transactional point-lookup assumptions.

Workload and limiting resource

Hypothetical table has 100 columns each eight raw bytes/row and 100,000,000 rows. Reading all columns implies 80 GB raw; reading five implies 4 GB before compression/pruning. This is an I/O-volume comparison, not a 20× measured latency claim.

Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.

Mutation or publication path

Columnar analytics: mutation boundaryBatch incoming rows under a defined visibility policy. Then: Write immutable columnar parts. Then: Merge/compact without changing logical row/deduplication semantics.Step 1
Batch incoming rows under a defined visibility policy.
Step 2
Write immutable columnar parts.
Step 3
Merge/compact without changing logical row/deduplication semantics.
Batch incoming rows under a defined visibility policy. Then: Write immutable columnar parts. Then: Merge/compact without changing logical row/deduplication semantics.
  1. Batch incoming rows under a defined visibility policy.
  2. Write immutable columnar parts.
  3. Merge/compact without changing logical row/deduplication semantics.

Observation and recovery path

Columnar analytics: observation boundaryPrune partitions and sorted ranges. Then: Read required columns only. Then: Aggregate with bounded memory and spill behavior.Step 1
Prune partitions and sorted ranges.
Step 2
Read required columns only.
Step 3
Aggregate with bounded memory and spill behavior.
Prune partitions and sorted ranges. Then: Read required columns only. Then: Aggregate with bounded memory and spill behavior.
  1. Prune partitions and sorted ranges.
  2. Read required columns only.
  3. Aggregate with bounded memory and spill behavior.

Failure that changes the decision

Hypothetical scenario: Many tiny inserts create too many parts and background merge pressure. Batch without hiding the resulting freshness/acknowledgement trade-off.

Attempt this decision before reading the explanation

Can an analytical engine automatically enforce the same update semantics as a transactional primary?

No. Establish its actual replacement/deduplication and visibility rules. Fast aggregation does not imply transactional row ownership or immediate mutation visibility.

Supporting mechanism analysis

Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.

Hypothetical scenario. Northwind has chosen a relational starting model. The category page still needs its first twenty eligible products in the required order. Dev adds indexes to several columns; Priya asks him to trace the actual query through one of them.

Maya: “Show the read this structure helps and the work a price change must now maintain.”

Follow a declared access pattern into an ordered access path. Keep lookup work, returned rows and elapsed time distinct. The result should justify a particular index and account for its storage and update consequences, rather than prescribe an index for every field.

Before you continue: Does adding an index establish that the query will be fast?

Column names alone do not show whether key order, predicates and result order fit. Trace the selected plan and the remaining work before claiming a benefit.

That makes the proposal testable. The following examples count selected access and maintenance work without inventing a latency measurement.

A table contains records. An index provides another organization of selected keys and references or included data that can help locate qualifying records. A B-tree index maintains an ordered search structure. It can support suitable equality and range conditions without inspecting every record, subject to the particular database’s capabilities and chosen plan.

The existence of an index does not force the optimizer to use it. A query returning much of a small table may be better served by a scan. Estimates, data distribution, ordering and required columns influence the decision. “Indexed” describes an available access structure, not a measured latency result.

PostgreSQL’s index documentation describes several index types and associated capabilities. Northwind’s first proposal uses an ordinary ordered index because its category read combines equality selection with ordered output. Do not transfer every B-tree statement to every specialized index type.

Consider membership records keyed for access by category, market, display rank and product identifier. With a suitable index in that order, a query fixing category and market can seek toward the corresponding group, then traverse entries in rank and identifier order. The product identifier breaks ties so that the requested ordering is complete.

The price still comes from the applicable price record. This index does not magically include every product field or establish its age. A plan may find membership identifiers efficiently and then fetch product and price records. That remaining work belongs in the request budget, even though the membership selection became cheaper.

Hypothetical scenario. Compare a B-tree access path with an LSM-backed alternative for the same category-and-order query. Keep the database implementation explicit: the existing PostgreSQL discussion is not a claim that its ordinary tables use an LSM engine.

Choose eight leaf pages to inspect in one illustrative index path and three qualifying heap pages to fetch. Logical page visits are 8 + 3 = 11; this is not eleven disk reads or a latency estimate. Buffer residency, visibility checks and concurrent changes determine further work. An index-only plan also needs the engine's visibility conditions, not merely a covering list of columns.

An LSM design can batch sorted writes but eventually pays compaction work and may consult multiple sorted runs on reads. A B-tree maintains its own pages and splits. Neither structure eliminates write, read or space amplification. Compare them under the same update mix and free-space budget, and include background work in survivor capacity. A fast foreground benchmark that ignores deferred compaction debt can select an unsustainable design.

Primary mechanism reference: RocksDB compaction explanation . Use its implementation scope when evaluating this design.

Hypothetical worked example. Choose a table containing 100,000 membership records and a simplified storage layout of one hundred records per data page. A full scan then visits 100,000 ÷ 100 = 1,000 data pages. This is a teaching layout, not an actual PostgreSQL row-size or page-occupancy claim.

Now choose an index path requiring three internal-page visits and one leaf-page visit to locate and hold the selected twenty entries. If their needed records reside on twenty distinct data pages, selected visits are 3 + 1 + 20 = 24 pages before any separately required price lookups. Relative to the selected scan, avoided visits are 1,000 − 24 = 976.

If those records instead share two data pages, the chosen count becomes 3 + 1 + 2 = 6. The difference between six and twenty-four demonstrates why physical locality and the required fields matter. Neither page count can be converted into milliseconds without additional evidence about caching, storage, concurrency and the actual execution path.

For a separate simplified storage estimate, choose forty-eight bytes per index entry. Across 100,000 entries, that is 100,000 × 48 = 4,800,000 bytes of entry payload. Two equivalent-sized indexes contain 2 × 4,800,000 = 9,600,000 bytes before structural overhead, free space and database-specific representation. These are selected accounting inputs, not a storage benchmark.

An inserted membership record also needs entries in each applicable maintained index. With one table and three selected indexes, the logical structures touched are 1 + 3 = 4. This is not a claim of four physical disk writes: logging, buffering, page splits and other implementation work determine physical I/O.

Updates need more careful reasoning. Changing an unindexed field differs from changing an indexed key or a predicate controlling index membership. Adding every column to every index increases maintenance obligations and may enlarge the working set. Give each structure a concrete read requirement and remove one only after checking the workloads that depend on it.

A covered or index-only path can reduce separate record access when its requirements are met. Do not infer that behavior solely because some requested fields appear in an index definition. Database-specific visibility and execution rules matter. The design should say what it expects and retain the plan evidence that confirms or challenges it.

Hypothetical failure scenario. Northwind retrieves the first twenty indexed category members, then removes withdrawn products in application code. Only twelve remain. The service reports that the category contains no more eligible results, even though later members qualify. The index made selection fast while the application changed the meaning of the requested page.

Layer 3 · Internals

A columnar engine stores values so analytical queries can read selected columns rather than deserialize complete transactional rows. ClickHouse MergeTree tables also use sorted data parts, sparse indexing and background merging. A partition key primarily controls coarse data organization and management; the ordering key influences how effectively a query can narrow the rows it reads. Neither should be chosen from a generic rule such as one partition per customer without considering part counts and operational limits.

A hypothetical scan of ten million rows needing two eight-byte numeric columns has 10,000,000 × 2 × 8 = 160,000,000 logical bytes before compression and engine overhead. Adding a large unused text column need not add its full payload to that columnar scan, but filtering, decoding and aggregation still consume work. Pre-aggregated tables can lower repeated query cost while introducing update and late-correction obligations. An analytical dashboard should not silently become the authority for a transactional credit or inventory decision simply because its query returns quickly.

Trade-offs and limits

ApproachProvidesRequires
Query raw columnar partsPreserves flexible filters and grouping.Large scans still consume CPU and I/O.
Materialized aggregationReduces repeated work for a known query family.Late corrections and schema changes must update the derived state.

Recovery decision

Hypothetical scenario: Many tiny inserts create too many parts and background merge pressure. Batch without hiding the resulting freshness/acknowledgement trade-off.

No. Establish its actual replacement/deduplication and visibility rules. Fast aggregation does not imply transactional row ownership or immediate mutation visibility.

Write your design before revealing the review

Can an analytical engine automatically enforce the same update semantics as a transactional primary?

Evidence you can explain in your own design

Drafts and self-review are stored only in this browser. They are separate from reading completion.

Compare your decision

No. Establish its actual replacement/deduplication and visibility rules. Fast aggregation does not imply transactional row ownership or immediate mutation visibility.

Many tiny inserts create too many parts and background merge pressure. Batch without hiding the resulting freshness/acknowledgement trade-off.

Check your understanding

Can an analytical engine automatically enforce the same update semantics as a transactional primary?

No. Establish its actual replacement/deduplication and visibility rules. Fast aggregation does not imply transactional row ownership or immediate mutation visibility.

How would you recover from this failure: Many tiny inserts create too many parts and background merge pressure. Batch without hiding the resulting freshness/acknowledgement trade-off.

Start with the exact boundary that failed. Batch incoming rows under a defined visibility policy. Write immutable columnar parts. Merge/compact without changing logical row/deduplication semantics. Then recover evidence through the observation path: Prune partitions and sorted ranges. Read required columns only. Aggregate with bounded memory and spill behavior. Preserve the distinction between a confirmed state change and an unavailable response.

Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?

Hypothetical table has 100 columns each eight raw bytes/row and 100,000,000 rows. Reading all columns implies 80 GB raw; reading five implies 4 GB before compression/pruning. This is an I/O-volume comparison, not a 20× measured latency claim. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Serve large analytical scans by storing selected columns and pruning irrelevant parts. Sorting, partitioning and aggregation must follow query patterns rather than transactional point-lookup assumptions.

Which component in this topology could be removed from a smaller first deployment?

Ingest buffer, Column parts, Sparse index, Query aggregator name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Batch incoming rows under a defined visibility policy.

What evidence must a caller have before relying on the observation path?

Prune partitions and sorted ranges. Read required columns only. Aggregate with bounded memory and spill behavior. No. Establish its actual replacement/deduplication and visibility rules. Fast aggregation does not imply transactional row ownership or immediate mutation visibility.

45-minute interview rubric

  1. 00–05: scope scanned row and analytical table snapshot.
  2. 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
  3. 12–28: draw analytical table snapshot, numbered writes and reads.
  4. 28–40: challenge recovery: Choose sort keys, partitions and pre-aggregation from the query mix.
  5. 40–45: defend event_date placement, observations and remaining assumptions.

Go deeper

Decision log

Choose sort keys, partitions and pre-aggregation from the query mix.

Preserve scanned row identity and analytical table snapshot ownership.

Revisit changed workload, observations or recovery objectives.