FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Real-Time OLAP: Pinot and StarRocks

Compare Pinot segment routing and Star-Tree pre-aggregation with StarRocks distributed SQL and continuous Kafka ingestion.

Freshness: current•12 min read•Data Engineering and Databases
Full Technical Reference Document

Mental model

Real-time OLAP systems make fresh event data queryable by partitioning it into columnar segments and distributing scans across workers. Apache Pinot routes queries to servers that own relevant segments and can combine Kafka-fed real-time with batch-built offline segments. StarRocks plans distributed SQL queries over OLAP tables and can continuously ingest Kafka. Indexes and summaries accelerate only query shapes their stored layout supports.

Learning outcomes

  • Trace how Pinot moves from stream ingestion to segment placement, broker routing, and merged query results.
  • Explain when a Pinot Star-Tree can replace raw-row aggregation work and when its dimension layout does not match a query.
  • Distinguish StarRocks Kafka ingestion and duplicate-key table behavior from Pinot hybrid-table segment routing.
  • Estimate the maximum aggregation reduction from the cardinality of a dashboard's grouping dimensions.

Theory

Pinot and StarRocks both serve analytical queries over recent data, but their execution paths and tuning surfaces differ. Pinot is organized around tables whose segments are assigned to servers. A Controller manages table and cluster metadata; Servers consume or host segments; Brokers use segment-location metadata to route a request to the relevant Servers and combine their partial results. This avoids asking every node to scan every segment.

A Pinot real-time table consumes a stream such as Kafka and builds segments as records arrive. A segment is first mutable while it is being consumed, then flushed and committed as an immutable segment. Offline segments are built by a batch process and pushed into the cluster. A hybrid table exposes real-time and offline tables under one logical table name. The Broker federates across both sides while respecting the time coverage boundary so a record covered by an offline segment is not also counted from the real-time side.

Pinot indexes reduce the work inside a selected segment. An inverted index maps a column value to matching document IDs, which helps selective filters. A Star-Tree serves a different purpose: during segment construction, it groups documents by an ordered set of dimensions and stores pre-aggregated metric values at tree nodes. A query can use those stored aggregates when its group-by dimensions, filters, and requested metrics fit the index configuration. It does not make arbitrary SQL cheap; a new dimension, unsupported predicate, or unconfigured metric can force more raw-document work.

StarRocks uses a distributed SQL architecture. The Frontend (FE) parses and plans a query, then coordinates parallel execution across Backend (BE) nodes in a shared-nothing deployment. A table's partitioning, distribution key, and sort key affect pruning, data placement, and local scan order. For append-only event facts, a Duplicate Key table retains repeated rows, which is useful for raw logs but does not deduplicate business events. Continuous Kafka ingestion uses a persistent Routine Load job that creates tasks to consume topic partitions and load batches into the table. Its exactly-once loading semantics protect delivery through job retries; they do not decide whether two separately produced messages represent the same logical event.

One workload, two execution paths

ConcernApache PinotStarRocks
Fresh data pathServer consumes stream partitions into real-time segments; completed segments are committed.Routine Load tasks consume Kafka partitions and load table batches.
Query coordinationBroker selects servers and segments from cluster metadata, then merges results.FE plans the distributed SQL query and coordinates BE execution.
Main pruning or aggregation leverSegment assignment, column indexes, and query-compatible Star-Tree aggregates.Partition and sort-key pruning, distribution, plus workload-specific indexes or materialized views.
Common mismatchStar-Tree dimensions or metrics do not cover the dashboard query.Table keys and distribution do not match the selective filters or joins.

These are complementary designs rather than equivalent index names. Pinot's Star-Tree is a segment-level pre-aggregation structure. StarRocks is a general MPP database where the schema, keys, distribution, and optional materialized structures shape SQL execution. Evaluate each with the same event distribution, filter selectivity, freshness target, and query concurrency instead of comparing an index in isolation.

Mechanism and worked calculation

Suppose one tenant receives 6,000,000 request events in an hour. A dashboard groups them into 60 one-minute buckets, 8 model revisions, and 3 response classes. The maximum number of non-empty result groups is 60×8×3=1,44060 \times 8 \times 3 = 1{,}440. If the Pinot Star-Tree is built with these dimensions and stores the needed count and sum(latency_ms) metrics, it can answer a compatible grouped aggregate from at most 1,440 aggregate combinations instead of combining 6,000,000 raw rows.

Rideal=NG=6,000,000 events60 buckets×8 revisions×3 classes≈4,167R_{ideal} = \frac{N}{G} = \frac{6{,}000{,}000\ \text{events}}{60\ \text{buckets} \times 8\ \text{revisions} \times 3\ \text{classes}} \approx 4{,}167

Here NN is the number of matching input events, GG is the maximum number of groups represented by the configured dimensions, and RidealR_{ideal} is a unitless upper-bound reduction in aggregation candidates. It is not a promise of a 4,167-fold latency improvement: segment fan-out, index size, filter selectivity, cache state, network merge, and concurrency still contribute to query time. If users add a high-cardinality trace ID to the grouping, the group count may approach the row count and the pre-aggregation advantage can disappear.

The Pinot path has five meaningful stages: the Controller publishes table and segment metadata; a Server consumes Kafka into a real-time segment; flush and commit make a segment available for indexed queries; a Broker chooses the real-time and offline segment coverage for the requested time range; and Servers evaluate filters or Star-Tree aggregates before the Broker merges partial results.

Controller publishes table and segment metadata
Server consumes Kafka and builds a real-time segment
Flush and commit make the indexed segment queryable
Broker routes across real-time and offline segment coverage
Servers aggregate and Broker merges the partial results
Conceptual teaching model synthesized from:apache-pinot-architecture,apache-pinot-table-architecture,apache-pinot-star-tree-index,starrocks-architecture-docs,starrocks-routine-load-docs

Implementation pattern

This StarRocks table keeps append-only request events and distributes tenant-scoped work by tenant_id. The query computes a mean from additive values so the same aggregation can be rolled up safely across partitions; percentile calculations require a different strategy and should not be inferred from this mean.

sql
CREATE TABLE IF NOT EXISTS model_latency (
event_time DATETIME NOT NULL,
tenant_id BIGINT NOT NULL,
model_revision VARCHAR(64) NOT NULL,
latency_ms DOUBLE NOT NULL,
status_code INT NOT NULL
)
ENGINE = OLAP
DUPLICATE KEY (event_time, tenant_id, model_revision)
DISTRIBUTED BY HASH (tenant_id) BUCKETS 16
PROPERTIES ("replication_num" = "3");
​
SELECT DATE_TRUNC('minute', event_time) AS minute_bucket,
model_revision,
status_code,
COUNT(*) AS request_count,
SUM(latency_ms) / COUNT(*) AS mean_latency_ms
FROM model_latency
WHERE tenant_id = 42
AND event_time >= NOW() - INTERVAL 1 HOUR
GROUP BY DATE_TRUNC('minute', event_time), model_revision, status_code
ORDER BY minute_bucket DESC;

To feed this table, a Routine Load job can map Kafka JSON fields into the columns and consume partitions concurrently. Monitor the job's state and lag alongside query latency. The DDL's Duplicate Key model deliberately preserves repeated records; use a business event key and an appropriate upsert model or a deduplication stage when duplicate logical events must collapse.

Trade-offs

Pre-aggregation spends storage and ingestion or segment-build work to reduce repeated query aggregation. Choose a Star-Tree only for stable, frequent groupings whose dimensions and metrics are known; keep a raw-query path for exploratory dimensions. Adding dimensions can increase the index's aggregate combinations, so test index size and build time with the actual cardinalities. In Pinot, shorter real-time segment flush intervals can expose data sooner while increasing the number of small segments and the metadata, scheduling, and query fan-out they create.

StarRocks offers flexible SQL and table models for raw events, aggregates, and joins. That flexibility still requires matching the physical table to the workload. Hash distribution on a tenant key helps tenant-scoped parallel scans but can create skew if a few tenants dominate. Routine Load provides continuous ingestion and retry behavior, but operators still need to watch Kafka lag, load task failures, schema compatibility, and FE/BE capacity. Neither system removes the need to set a freshness objective and measure ingestion delay separately from query execution time.

Failure modes and misconceptions

  • A Star-Tree is not a universal cache. A filter or grouping outside the configured dimensions may not use the intended pre-aggregated nodes. Compare the query plan and scanned documents with a compatible baseline.
  • A hybrid table can miscount at the real-time/offline boundary. Late data, overlapping segment coverage, or an incorrect time column can cause a gap or double count. Reconcile counts by event-time window during offline replacement and recovery.
  • Exactly-once ingestion is not business-level deduplication. Routine Load's delivery guarantee addresses retries within the load pipeline. If the producer emits the same logical request under two message IDs, a Duplicate Key table retains both.
  • A fast average can hide a slow tail. Segment fan-out, skewed distribution, concurrent load tasks, and cold indexes can inflate p95 latency even when average latency looks healthy. Track p50/p95 query latency, scanned rows, ingestion lag, and per-node load.
  • More dimensions can erase the space advantage. High-cardinality dimensions create many aggregate combinations and increase segment build size. Recheck index size and query benefit whenever the dashboard's grouping contract changes.

Decision scenario

A service team wants a dashboard that refreshes every 10 seconds, filters by tenant and status, and groups one-hour traffic by minute and model revision. It also needs a daily batch correction for late events. The team should first confirm that Pinot's Star-Tree includes the requested grouping dimensions and additive metrics, then run a hybrid-table canary that verifies the offline replacement boundary against a count by event-time minute. If the dashboard later needs arbitrary trace-ID groupings, keep a raw scan or evaluate StarRocks for that query family instead of expanding a Star-Tree without measuring its cardinality and build cost.

Reflect before revealing the guide

Prerequisites & Related Concepts (2)

Private notes

0 words
Recommended Free Track
Free · Verifiable Credential

FS-201Production LLM Engineer

Design an observable full-stack LLM product from capability validation through interfaces retrieval evaluation security and operations.

37 concepts~35h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.

Next