Skip to content

Block 6 — The Four Stores, Side by Side (Live Dashboard)

Duration: 30 min


What You've Been Looking At

If you opened the dashboard at the start of this section (Block 1), you've already seen it: four live charts comparing the same telemetry as served by RisingWave, TimescaleDB, Timestream for InfluxDB, and Athena/Iceberg side by side.

Chart Y axis Source
Data Freshness Milliseconds — log scale All four tiers
Fleet Free CPU & Memory Percent free (higher = healthier) Both self-managed live DBs
Time Since Last Message Seconds per node Both self-managed live DBs

All four stores serve the same telemetry, so you can directly compare how stale each store's view of the fleet is — a live streaming MV (RisingWave), a live relational scan (TimescaleDB), a managed time-series store polled on demand (Timestream for InfluxDB — Block 5), and an on-demand warehouse query (Athena over the Iceberg table in S3). This block explains how each chart gets its data and, more importantly, what each store is actually good at.

Block 1 owns loading the dashboard (a kubectl port-forward on local port 8888) — if you don't have it open, follow it there. On the running dashboard the RisingWave and TimescaleDB indicators show live · push; InfluxDB and Athena show live · poll.


Chart 1 — Data Freshness (log scale)

All four panels run the same logical query in each store's dialect — Block 1 explains it (the shared shape, the per-tier table/MV, and why freshness uses the pod's wall-clock, not each store's own now()). The exact SQL/Flux each tier runs is in the collapsibles below and in the CLI blocks further down.

The Y axis uses a log₁₀ scale because the four tiers span four orders of magnitude:

Tier Typical freshness
RisingWave MV 100 ms – 1 s (sawtooth — steps with each checkpoint barrier)
TimescaleDB (windowed scan) 100–600 ms
Timestream for InfluxDB (polled) ~1–2 s (Telegraf flush + poll cadence)
Athena/S3 tens of s up to ~300 s

A linear axis would make RisingWave, TimescaleDB, and InfluxDB indistinguishable — the log scale makes all four tiers clearly visible at once.

Freshness vs. query latency — read Data Store Performance Characteristics below

RisingWave and TimescaleDB land in the same freshness band, but for very different reasons, and their read latency and scaling behaviour diverge sharply as the fleet grows. If the newest row is ever seconds-to-minutes stale in a live tier, that's an ingestion/freshness signal — not the read path being slow. It has two distinct causes: an upstream pause (a stopped/redeploying simulator, MSK consumer-lag spike) that starves every tier at once, or a per-store pipeline problem that lags one tier while the others stay fresh — e.g. RisingWave's checkpoint-commit path falling behind (see the worked example at the end of this section). The performance section spells out which store to reach for under a fixed latency budget, and how to tell the two failure modes apart.

Query — RisingWave and TimescaleDB freshness

Open in GitHub

import type { Pool } from "pg";
import type { FreshnessPayload } from "../app/api/freshness/route";

// Shared aggregate queries used by both the polled /api/freshness route and
// the two push-based /api/stream/* routes (#160) — same SQL, same freshness
// formula (Date.now() - MAX(ts_ms)), so a value reported via push always
// matches what a poll of /api/freshness would return at that instant.

interface Row {
  site_id: string;
  avg_free_cpu_pct: string | null;
  avg_free_mem_pct: string | null;
  latest_ts_ms: string;
}

function toPayload(
  rows: Row[],
  source: "risingwave" | "timescaledb",
  queryLatencyMs: number
): FreshnessPayload {
  const now = Date.now();
  const latestTs = rows.length > 0 ? Math.max(...rows.map(r => Number(r.latest_ts_ms))) : 0;
  const avgFreeCpu = rows.length > 0
    ? rows.reduce((s, r) => s + (r.avg_free_cpu_pct != null ? parseFloat(r.avg_free_cpu_pct) : 0), 0) / rows.length
    : null;
  const avgFreeMem = rows.length > 0
    ? rows.reduce((s, r) => s + (r.avg_free_mem_pct != null ? parseFloat(r.avg_free_mem_pct) : 0), 0) / rows.length
    : null;

  return {
    tierFreshness: {
      risingwave_ms: source === "risingwave" && latestTs > 0 ? now - latestTs : null,
      timescaledb_ms: source === "timescaledb" && latestTs > 0 ? now - latestTs : null,
      athena_ms: null,
      influxdb_ms: null,
      appsync_ms: null,
    },
    // Query latency — wall-clock ms to execute this tier's read. Distinct from
    // tierFreshness (data staleness): this is the read-path cost, the metric
    // where RisingWave's pre-aggregated in-memory MV is expected to beat
    // TimescaleDB's relational scan. One tier populated per payload, mirroring
    // tierFreshness so the chart merge logic is identical.
    tierLatency: {
      risingwave_ms: source === "risingwave" ? queryLatencyMs : null,
      timescaledb_ms: source === "timescaledb" ? queryLatencyMs : null,
      athena_ms: null,
      influxdb_ms: null,
      appsync_ms: null,
    },
    // Device→ingest hop (#245) — populated by queryRisingWaveFreshness after
    // this function returns; both stores see the same device hop, but only
    // the RisingWave leg computes it today (risingwave/ddl-cloud.sql).
    deviceHopLatency: {
      risingwave_ms: null,
      timescaledb_ms: null,
      athena_ms: null,
      influxdb_ms: null,
      appsync_ms: null,
    },
    fleetResources: {
      avg_free_cpu_pct: avgFreeCpu,
      avg_free_mem_pct: avgFreeMem,
    },
    nodeAge: rows.map(r => ({
      site_id: r.site_id,
      age_seconds: (now - Number(r.latest_ts_ms)) / 1000,
    })),
    source,
    sampled_at: now,
  };
}

export async function queryRisingWaveFreshness(pool: Pool, deploymentId: string): Promise<FreshnessPayload> {
  const t0 = Date.now();
  // #253: mv_sensor_fleet_latest and mv_device_hop_latency now hold every
  // slot's rows in one shared MV (risingwave/ddl-cloud.sql) — deployment_id
  // scopes each read to the caller's own slot.
  const { rows } = await pool.query<Row>(
    `
    SELECT
      site_id,
      AVG(CASE WHEN sensor = 'cpu_pct'      THEN 100.0 - value END) AS avg_free_cpu_pct,
      AVG(CASE WHEN sensor = 'mem_used_pct' THEN 100.0 - value END) AS avg_free_mem_pct,
      MAX(ts_ms)                                                     AS latest_ts_ms
    FROM mv_sensor_fleet_latest
    WHERE deployment_id = $1
    GROUP BY site_id
    ORDER BY site_id
  `,
    [deploymentId]
  );
  const payload = toPayload(rows, "risingwave", Date.now() - t0);

  // Device→ingest hop (#245): mv_device_hop_latency is now grouped by
  // deployment_id (#253) — AVG is NULL when no recent row in this slot's
  // window carries message_timestamp, which the FreshnessPayload contract
  // treats as "no data" rather than an error.
  const { rows: hopRows } = await pool.query<{ avg_device_hop_ms: string | null }>(
    `SELECT avg_device_hop_ms FROM mv_device_hop_latency WHERE deployment_id = $1`,
    [deploymentId]
  );
  payload.deviceHopLatency.risingwave_ms =
    hopRows[0]?.avg_device_hop_ms != null ? parseFloat(hopRows[0].avg_device_hop_ms) : null;

  return payload;
}

export async function queryTimescaleDbFreshness(pool: Pool, deploymentId: string): Promise<FreshnessPayload> {
  const t0 = Date.now();
  // Unlike RisingWave, TimescaleDB reads the RAW hypertable, not a pre-collapsed
  // MV — so the partition_time predicate is load-bearing for both the
  // query-latency comparison AND freshness correctness. Two effects:
  //
  //   • Latency: `partition_time > now() - interval` lets TimescaleDB do chunk
  //     exclusion (skip every chunk older than the window) instead of scanning
  //     the whole hypertable each poll. Measured on a live 6.9M-row table this
  //     cut the query from ~1.8s (full scan; tens of seconds under load) to
  //     ~11ms. Because freshness is sampled AFTER the query returns, the old
  //     full-scan runtime was also inflating the reported *freshness* number.
  //
  //   • Correctness: the unfiltered query aggregated in long-dead sites too
  //     (leftover sim/test nodes days stale). The window keeps only
  //     actively-reporting nodes, which is what "fleet freshness" should mean.
  //
  // NB: we deliberately do NOT filter by sensor name. The panels compute
  // free-CPU/mem from cpu_pct/mem_used_pct via CASE (null for datasets that
  // don't emit them, e.g. the frac-ops telemetry sensors), but MAX(ts_ms) must
  // see ALL sensors so freshness reflects the newest reading of any kind.
  // 15 min is generous enough that steady-state telemetry always populates it;
  // if ingestion stalls longer, the query returns no rows (freshness → null),
  // correctly surfacing "no recent data" rather than a fast-but-stale number.
  // #253: sensor_readings now holds every slot's rows in one shared
  // hypertable — deployment_id (leading column of idx_sensor_readings_deployment,
  // see helm/cloud-analytics/templates/timescaledb-cluster.yaml) scopes this
  // read to the caller's own slot, same as the partition_time window keeps it
  // chunk-excluded.
  const { rows } = await pool.query<Row>(
    `
    SELECT
      site_id,
      AVG(CASE WHEN sensor = 'cpu_pct'      THEN 100.0 - value END) AS avg_free_cpu_pct,
      AVG(CASE WHEN sensor = 'mem_used_pct' THEN 100.0 - value END) AS avg_free_mem_pct,
      MAX(ts_ms)                                                     AS latest_ts_ms
    FROM sensor_readings
    WHERE deployment_id = $1
      AND partition_time > now() - interval '15 minutes'
    GROUP BY site_id
    ORDER BY site_id
  `,
    [deploymentId]
  );
  return toPayload(rows, "timescaledb", Date.now() - t0);
}

Freshness = Date.now() - MAX(ts_ms). Both tiers use ts_ms/the equivalent column populated from ingest_ts — the epoch-ms timestamp stamped by IoT Core when the message arrived, not the device clock — so clock-skew between EC2 edge nodes and the dashboard is eliminated. Both queries also carry a deployment_id = $1 predicate — the dashboard is one shared instance for every slot (#253), so every read is scoped to the caller's own slot via its ?did= value.

Query — Athena / Iceberg

SELECT
  thing_name AS site_id,
  MAX(message_timestamp) AS latest_ts_ms,
  AVG(100.0 - CAST(cpu_pct AS double))      AS avg_free_cpu_pct,
  AVG(100.0 - CAST(mem_used_pct AS double)) AS avg_free_mem_pct
FROM workshop_telemetry.telemetry
GROUP BY thing_name
Same Date.now() - MAX(...) freshness formula, run against the Iceberg table in S3 via Athena. message_timestamp is the same epoch-ms basis as ts_ms in the other tiers, so the three numbers are apples-to-apples. The route submits the query, polls GetQueryExecution until it succeeds (cap 30 s), and reads the result — which is why this tier reports tens of seconds of "freshness" even when the data itself is recent: you're measuring the warehouse round-trip, not a live push.

CLI — read the same numbers

The panels above render in a browser, but the underlying numbers are just SQL — you can read them from the CLI with the exact same queries the dashboard runs. Each block below prints a one-line JSON {"tier", "freshness_ms", "query_latency_ms", "rows"} capturing two distinct metrics for that tier:

Metric What it is Governed by
freshness_ms now − MAX(timestamp) — how stale the newest row is the ingestion pipeline (arrival lag)
query_latency_ms wall-clock to execute the read query the read path (in-memory MV vs relational scan vs warehouse round-trip)

They're orthogonal: a store can hold second-old data (fresh) yet answer slowly, or hold stale data yet answer instantly. Freshness is computed in-SQL (now() in epoch-ms minus the store's latest timestamp) so there's no dependency on the client clock or a GNU-only date flag; query latency is measured around the query call itself.

The end-to-end suite runs these blocks against a live slot and records each tier's freshness_ms and query_latency_ms in the run report's Data freshness & query latency table, so both ladders are captured on every e2e pass — the CLI equivalent of the dashboard's freshness and query-latency charts.

Measurement trap (#206): never ask RisingWave for its own now()

It's tempting to compute freshness entirely in-SQL — now() - MAX(ts_ms) — the way the TimescaleDB and Athena blocks below do. Don't do this for RisingWave. RW's SQL now() tracks its last committed checkpoint epoch, not wall-clock. If the checkpoint-commit path lags (the CPU-starvation failure mode #211 fixes), now() lags by the same amount — so now() - MAX(ts_ms) computed inside RisingWave cancels the lag out and reports sub-second freshness while the underlying data is minutes old. Worse, if now() ever lags behind the most recent committed row's ts_ms (e.g. right after a barrier catches back up), the subtraction goes negative — an unmistakable tell that something is measuring against the wrong clock. The block below deliberately timestamps with the CLI's own wall-clock (a portable epoch-ms helper — python3 -c 'import time; print(int(time.time()*1000))', which behaves identically on GNU/Linux and BSD/macOS, unlike a millisecond-precision date flag) instead of RW's now(), for the same reason the dashboard's routes use Date.now() (see the note under Chart 1 for the full story).

Why the CLI blocks below use a warm psql \timing reading for query latency

Wrapping the whole psql invocation between two wall-clock reads — the way time psql ... or the naive $(epoch_ms) … $(epoch_ms) pattern would — bundles process spawn, TCP connect, and the kubectl port-forward tunnel's own round-trip in with the query itself. On a live slot that's ~1 s of setup dwarfing the actual read, and it makes RisingWave's in-memory MV lookup look as slow as a warehouse scan (#239). The RisingWave and TimescaleDB blocks below instead open one psql session with \timing on, run the read query once as a discarded warm-up, run it again, and parse the second (warm) Time: <n> ms line — \timing reports only server-side execution plus one round-trip on an already-open connection, the same thing the live dashboard's /api/stream/* routes measure by timing pool.query(...) alone, inside the pod. Treat this CLI reading as a sanity check: the dashboard's Query latency chart, driven by that same server-side timing, is the canonical number.

RisingWave — freshness + query latency (port 4567)

kubectl port-forward -n cloud-analytics svc/risingwave-cloud-frontend 4567:4567 > /tmp/rw-fresh-pf.log 2>&1 &
RW_PF_PID=$!
until grep -q "Forwarding from" /tmp/rw-fresh-pf.log 2>/dev/null; do sleep 1; done
# Same MV the dashboard's /api/stream/risingwave route reads. ts_ms is the
# IoT-Core ingest timestamp (epoch-ms), so freshness is clock-skew-free.
# deployment_id = 'ws-slot00' scopes this to your own slot — the MV holds
# every slot's rows on this shared instance (#253). Timestamp with the
# CLIENT's wall-clock, not RisingWave's own now() — see the measurement-trap
# warning above. One session, \timing on, a discarded warm-up SELECT then
# the measured SELECT — this isolates engine read latency from psql-spawn +
# connect/auth + tunnel cost (see the note above).
epoch_ms() { python3 -c 'import time; print(int(time.time()*1000))'; }
RW_RAW=$(psql -h localhost -p 4567 -U root -d dev -tA -F'|' <<'SQL'
\timing on
SELECT MAX(ts_ms), COUNT(*) FROM mv_sensor_fleet_latest WHERE deployment_id = 'ws-slot00';
SELECT MAX(ts_ms), COUNT(*) FROM mv_sensor_fleet_latest WHERE deployment_id = 'ws-slot00';
SQL
)
RW_NOW=$(epoch_ms)
IFS='|' read -r RW_MAX_TS RW_ROWS < <(echo "$RW_RAW" | grep -v '^Time:' | tail -1)
RW_LAT=$(echo "$RW_RAW" | grep '^Time:' | tail -1 | awk '{print $2}')
RW_LAT=$(printf '%.0f' "${RW_LAT:-0}")
RW_FRESH=""
[ -n "$RW_MAX_TS" ] && RW_FRESH=$(( RW_NOW - RW_MAX_TS ))
kill "$RW_PF_PID" 2>/dev/null || true
echo "{\"tier\":\"risingwave\",\"freshness_ms\":${RW_FRESH:-null},\"query_latency_ms\":${RW_LAT},\"rows\":${RW_ROWS:-0}}"

TimescaleDB — freshness + query latency (port 5432)

TSDB_PASS=$(kubectl get secret timescaledb-cloud-app -n cloud-analytics \
  -o jsonpath='{.data.password}' | base64 -d)
kubectl port-forward -n cloud-analytics svc/timescaledb-cloud-rw 5432:5432 > /tmp/tsdb-fresh-pf.log 2>&1 &
TSDB_PF_PID=$!
until grep -q "Forwarding from" /tmp/tsdb-fresh-pf.log 2>/dev/null; do sleep 1; done
# Same sensor_readings table the dashboard's /api/stream/timescaledb route reads.
# The `partition_time > now() - interval '15 minutes'` predicate is load-bearing:
# it lets TimescaleDB do chunk exclusion (skip every chunk older than the window)
# instead of scanning the whole raw hypertable on every read. deployment_id =
# 'ws-slot00' scopes it to your own slot — this hypertable holds every slot's
# rows on this shared instance (#253), and deployment_id leads the composite
# index so the two predicates stay index-scoped together. One session, \timing
# on, a discarded warm-up SELECT then the measured SELECT — same isolation as
# the RisingWave block above; freshness still comes from the (warm) query's
# own now() - MAX(ts_ms).
TS_RAW=$(PGPASSWORD="$TSDB_PASS" psql -h localhost -p 5432 -U workshop -d edge -tA -F'|' <<'SQL'
\timing on
SELECT (EXTRACT(EPOCH FROM now())*1000)::bigint - MAX(ts_ms), COUNT(*) FROM sensor_readings WHERE deployment_id = 'ws-slot00' AND partition_time > now() - interval '15 minutes';
SELECT (EXTRACT(EPOCH FROM now())*1000)::bigint - MAX(ts_ms), COUNT(*) FROM sensor_readings WHERE deployment_id = 'ws-slot00' AND partition_time > now() - interval '15 minutes';
SQL
)
IFS='|' read -r TS_FRESH TS_ROWS < <(echo "$TS_RAW" | grep -v '^Time:' | tail -1)
TS_LAT=$(echo "$TS_RAW" | grep '^Time:' | tail -1 | awk '{print $2}')
TS_LAT=$(printf '%.0f' "${TS_LAT:-0}")
kill "$TSDB_PF_PID" 2>/dev/null || true
echo "{\"tier\":\"timescaledb\",\"freshness_ms\":${TS_FRESH:-null},\"query_latency_ms\":${TS_LAT},\"rows\":${TS_ROWS:-0}}"

Athena / Iceberg — freshness + query latency (no port-forward)

# Same Iceberg table + message_timestamp basis the dashboard's
# /api/freshness?tier=athena route queries. Both freshness AND query latency
# here include the warehouse round-trip, so both are tens of seconds even
# when the underlying data is recent. Time the full submit→poll→fetch cycle.
epoch_ms() { python3 -c 'import time; print(int(time.time()*1000))'; }
AT_T0=$(epoch_ms)
QUERY_ID=$(aws athena start-query-execution \
  --work-group workshop-shared \
  --query-string "SELECT CAST(to_unixtime(now())*1000 AS bigint) - MAX(message_timestamp) AS freshness_ms, COUNT(*) AS n FROM workshop_telemetry.telemetry WHERE deployment_id='ws-slot00'" \
  --query QueryExecutionId --output text)

for _i in $(seq 1 20); do
  STATE=$(aws athena get-query-execution \
    --query-execution-id "$QUERY_ID" \
    --query 'QueryExecution.Status.State' --output text)
  if [ "$STATE" = "SUCCEEDED" ] || [ "$STATE" = "FAILED" ] || [ "$STATE" = "CANCELLED" ]; then
    break
  fi
  sleep 3
done

AT_FRESH=$(aws athena get-query-results --query-execution-id "$QUERY_ID" \
  --query 'ResultSet.Rows[1].Data[0].VarCharValue' --output text)
AT_ROWS=$(aws athena get-query-results --query-execution-id "$QUERY_ID" \
  --query 'ResultSet.Rows[1].Data[1].VarCharValue' --output text)
AT_LAT=$(( $(epoch_ms) - AT_T0 ))
# aws CLI renders a SQL NULL as the literal "None" in text output — normalise it.
if [ "$AT_FRESH" = "None" ]; then AT_FRESH=""; fi
if [ "$AT_ROWS" = "None" ]; then AT_ROWS=""; fi
echo "{\"tier\":\"athena\",\"freshness_ms\":${AT_FRESH:-null},\"query_latency_ms\":${AT_LAT},\"rows\":${AT_ROWS:-0}}"

Timestream for InfluxDB — freshness + query latency (port 8086)

```bash

Same shared bucket + sensor_reading schema the dashboard's

/api/freshness?tier=influxdb route queries (see Block 5). Assumes a local

tunnel to the managed instance on port 8086 (Block 5 sets this up). The

url/token/org/bucket live in the influxdb-credentials secret (shared

cloud-analytics namespace — #253); read them and run one Flux query for

the newest point's timestamp, filtered to your own slot via

deployment_id. Freshness is subtracted against the CLIENT wall-clock (a

portable epoch-ms helper) — same discipline as the other tiers.

epoch_ms() { python3 -c 'import time; print(int(time.time()*1000))'; } IX_TOKEN=$(kubectl get secret influxdb-credentials -n cloud-analytics -o jsonpath='{.data.INFLUX_TOKEN}' | base64 -d) IX_ORG=$(kubectl get secret influxdb-credentials -n cloud-analytics -o jsonpath='{.data.INFLUX_ORG}' | base64 -d) IX_BUCKET=$(kubectl get secret influxdb-credentials -n cloud-analytics -o jsonpath='{.data.INFLUX_BUCKET}' | base64 -d)

Newest point for this slot, as epoch-ms. Flux last() after a wide

range gives the most-recent sensor_reading; _time is RFC3339 → epoch-ms.

FLUX='from(bucket:"'"$IX_BUCKET"'") |> range(start:-15m) |> filter(fn:(r)=> r._measurement=="sensor_reading" and r._field=="value" and r.deployment_id=="ws-slot00") |> last() |> keep(columns:["_time"]) |> max(column:"_time")' IX_T0=$(epoch_ms) IX_TIME=$(curl -sf -k "https://localhost:8086/api/v2/query?org=${IX_ORG}" \ -H "Authorization: Token ${IX_TOKEN}" \ -H 'Accept: application/csv' \ -H 'Content-Type: application/vnd.flux' \ -d "$FLUX" | awk -F, 'NR>1 && $NF ~ /T/ {print $NF; exit}') IX_NOW=$(epoch_ms) IX_LAT=$(( IX_NOW - IX_T0 )) IX_FRESH="" if [ -n "$IX_TIME" ]; then # Portable RFC3339 -> epoch-ms parse (no GNU-only date-parsing flag). # Pads/truncates the fractional-seconds component to exactly 6 digits so # fromisoformat accepts InfluxDB's nanosecond-precision _time on any # Python 3.7+. IX_TS=$(python3 -c '

import datetime, re, sys s = sys.argv[1].strip().replace("Z", "+00:00") s = re.sub(r".(\d+)", lambda m: "." + (m.group(1) + "000000")[:6], s) print(int(datetime.datetime.fromisoformat(s).timestamp() * 1000)) ' "$IX_TIME" 2>/dev/null) [ -n "$IX_TS" ] && IX_FRESH=$(( IX_NOW - IX_TS )) fi echo "{\"tier\":\"influxdb\",\"freshness_ms\":${IX_FRESH:-null},\"query_latency_ms\":${IX_LAT},\"rows\":null}" ```


Data Store Performance Characteristics

The freshness and query-latency charts show a snapshot at the workshop's 3-device scale. The question that matters in production is different: can each store keep answering within a fixed time budget as the fleet grows? The customer driving this workshop has a hard 2-second end-to-end budget — from "a value lands in the store" to "a query returns it to the dashboard" — that must hold at scale.

This section is a decision guide: what each store is good at, how it behaves serving raw rows vs aggregations, and where each one falls out of a 2 s budget as data volume climbs.

The three stores are not interchangeable

RisingWave TimescaleDB Athena / Iceberg (S3)
Model Streaming MV engine (incremental compute) Relational time-series (Postgres + hypertables) Query engine over columnar files in S3
Where the work happens At write time — the MV is kept up to date as events arrive At read time — scans rows on each query At read time — scans object storage, cold start per query
Best at Pre-defined aggregations, always-current, push Ad-hoc SQL over recent raw rows; range scans Cheap retention of unlimited history; large scans
Freshness driver Checkpoint-barrier cadence (~sub-second, sawtooth) Ingestion sink flush (per-row visible) Batch/compaction into S3 (minutes)
Read latency driver Fixed distributed-query overhead (planning + compute hop) Rows scanned (index/chunk exclusion decisive) S3 round-trip + planning (seconds floor)
Cost driver Compute nodes kept warm 24/7 Storage + compute of the DB instance Per-query bytes scanned (near-zero at rest)

The single most important idea: RisingWave moves aggregation cost to write time; TimescaleDB and Athena pay it at read time. That one difference explains every latency number on the dashboard.

Serving raw data (point lookups & recent-window scans)

"Give me the last N readings for site X," or "the newest row per site."

Store At 3 devices At ~3,000 devices (300 sites) Notes
TimescaleDB ~5–80 ms 10–150 ms if the query is time-bounded Winner for raw reads. A partition_time > now() - interval predicate lets it do chunk exclusion — it touches only the newest chunk regardless of total table size. On slot90's 6.9 M-row table this was the difference between ~11 ms and ~1.8 s (and tens of seconds under load). Without a time bound, cost grows with total rows and blows the budget.
RisingWave ~25–45 ms ~30–80 ms Flat, but a fixed floor: even a 9-row read pays distributed planning + a compute hop. Not built for arbitrary raw scans — it serves the specific rows its MVs materialise.
Athena 1–3 s 2–10 s+ Never inside a 2 s interactive budget for point reads. S3 round-trip + query planning is a seconds-floor cost paid on every query. Fine for "scan a month of history," wrong for "the latest value."

Takeaway for raw reads: TimescaleDB, and the time-window predicate is mandatory, not optional. It is the whole reason the store stays inside budget as the hypertable grows — the fix applied to both the dashboard query and the CLI block above. Athena is disqualified for interactive raw lookups.

Serving aggregations (rates, rollups, fleet summaries)

"Average pump pressure per site over the last minute," "10-second pump-rate," etc. This is where the write-time vs read-time split decides everything.

Store Approach Latency at scale When it breaks the 2 s budget
RisingWave MV computed incrementally at write time; the read is a keyed lookup of an already-computed result Flat — independent of history size, because the aggregate is maintained, not recomputed Effectively never on read; the pressure moves to compute-node sizing and checkpoint cadence, not query time
TimescaleDB Two modes: (a) raw GROUP BY at read time, or (b) a continuous aggregate (see Block 4) — a materialised, incrementally-refreshed rollup (a) grows with rows scanned — breaks budget once the window × fleet size gets large; (b) flat, like RisingWave, because it's pre-materialised Mode (a) at high cardinality / wide windows; mode (b) stays in budget
Athena Full scan-and-aggregate over S3 objects each query Seconds-to-minutes; scales with bytes scanned Almost always for interactive use; it's a reporting/backfill tier

Takeaway for aggregations: if the aggregation is known ahead of time (it usually is — "pump rate," "free CPU," "throughput per site"), materialise it. RisingWave does this natively for the streaming case; TimescaleDB's continuous aggregates do it for the relational case. A materialised aggregate turns an unbounded read-time scan into a flat keyed lookup — the only way either store holds a 2 s budget at fleet scale. Recomputing aggregates from raw rows on every read is the anti-pattern that put TimescaleDB at 34 s on this very dashboard before the window fix.

Scale points and the 2-second budget

Reading the columns as fleet size climbs (1 Hz telemetry, ~10 sensors/device):

Fleet Rows/day (approx) Raw point read Known aggregation History scan
3 devices (workshop) ~2.6 M All three trivially fast All fast Athena seconds
300 devices (~30 sites) ~260 M TSDB windowed ✅ / RW ✅ / Athena ✅⁠(slow) RW MV ✅ / TSDB CAGG ✅ / TSDB raw ⚠️ Athena ✅ / TSDB ⚠️
3,000 devices (300 sites) ~2.6 B TSDB windowed ✅ / RW ✅ / Athena ❌ (interactive) RW MV ✅ / TSDB CAGG ✅ / TSDB raw ❌ Athena ✅ (its home turf) / TSDB ❌
30,000+ devices ~26 B+ RW ✅ / TSDB windowed ✅ with partitioning/retention discipline RW MV ✅ / TSDB CAGG ✅ Athena/Iceberg only

✅ = comfortably inside 2 s · ⚠️ = inside budget only with the right predicate/index · ❌ = exceeds budget for interactive use

What holds the budget as you scale:

  • Never scan unbounded history on the read path. Time-bound every raw query (chunk exclusion) and materialise every known aggregate (RW MV or TSDB continuous aggregate). This is the single highest-leverage rule.
  • RisingWave's read latency is flat with scale because the work happened at write time — its scaling levers are compute-node sizing on EKS (capstone scale notes) and checkpoint cadence, not query tuning. Budget risk shows up as ingestion lag / checkpoint-commit delay, i.e. freshness, not read latency — as the worked example below shows, a mis-tuned barrier interval alone can put freshness minutes behind at trivial load.
  • TimescaleDB's read latency is flat only with the right access pattern — a time predicate for raw, a continuous aggregate for rollups. Get those right and it's the lowest-latency store here; get them wrong and it's the first to blow the budget (as the pre-fix 34 s dashboard showed).
  • Athena is a retention/history tier, not an interactive one. It gets relatively better as data volume grows (columnar scans over S3 are its design point), but its per-query seconds-floor keeps it outside a 2 s interactive budget regardless of scale. Use it for backfill, audits, and large historical scans — not the live panel.

Why a live tier can show minutes of 'freshness' — and why it isn't a latency problem

If RisingWave (or TimescaleDB) reports seconds-to-minutes of freshness, the read path is not slow — the newest row it has committed really is that old. Freshness measures data liveness; query latency measures read cost. They move independently, and freshness has two very different causes:

  • Upstream pause (stopped/redeploying simulator, MSK consumer-lag spike): every tier goes stale together, because they all read the same MSK topics. Fresh-vs-stale is uniform across stores.
  • Per-store pipeline lag: one tier drifts while the others stay current. This is the tell that the problem is inside that store's write/commit path, not upstream.

Because both present as "stale data with a fast query," you diagnose by comparing stores side-by-side on the dashboard — and, critically, by measuring freshness against a trusted external clock, not the store's own now(). (RisingWave's now() tracks its last committed epoch, so when its commit path lags, now() lags too and now() − MAX(ts) computed inside RisingWave cancels the lag out — it looks sub-second while the data is minutes old. The dashboard and the CLI blocks above use the pod's wall-clock Date.now() precisely so the lag can't hide.)

Worked example — RisingWave lagging 2+ minutes at 3-device load (a per-store checkpoint problem)

On slot90, RisingWave freshness climbed to 120–240 s and kept growing, while TimescaleDB — reading the same MSK topics — stayed at ~1 s. Only one tier lagged, so this was a per-store pipeline problem, not an upstream pause. Read latency stayed ~25–45 ms throughout: the read was fast, the data was old.

The cause was checkpoint cadence. RisingWave commits a checkpoint to its meta store on every barrier; the deployment had RW_BARRIER_INTERVAL_MS set to 50 (20 checkpoints/second, vs the RisingWave default of 1000). On a 1-vCPU compute node with an external meta/state store, the commit path couldn't finish a checkpoint in 50 ms, so the committed epoch fell steadily behind wall-clock and never recovered — pure backlog in the commit path, even though the Kafka consumer was reading within a handful of messages of the topic head.

Restoring the default (barrierIntervalMs: 1000 in the chart) dropped freshness from ~150 s to sub-second immediately, with no change to CPU or memory. The lesson for the 2 s budget: RisingWave's budget risk is a write-side tuning problem (checkpoint cadence, compute sizing), not a query problem — and a tier that is stale-but-fast-to-read is the signature of exactly this class of bug.

Worked example — a freshness spike to 100 s+ that is really node instability (not RisingWave)

A second, distinct cause of a big freshness number: the node under the streaming stack recycles. On the shared workshop EKS every node is a burstable t3.medium (~3.4 Gi, ~1.9 vCPU allocatable), and the analytics pod limits oversubscribe it (observed 163 % memory / 155 % CPU of a single node's allocatable). When one such node flaps to NodeNotReady, it evicts whatever streaming/stateful pods share it at once — live on slot90 a single node event took down RisingWave compute and, on another slot, TimescaleDB (failover) + the redpanda-connect sink together. During the flap RisingWave's Kafka sources report AllBrokersDown, the committed MV epoch falls far behind wall-clock, and a dashboard read that lands mid-disruption shows 100 s+ (159.5 s observed). Once the node stabilised the same MV read at 856 ms — proving the spike was transient node instability, not steady-state RisingWave behaviour.

Tell it apart from the checkpoint-cadence case above by looking at pod restarts and node events, not just the freshness number — the shared instance's pods live in the cloud-analytics namespace (#253), not your own slot's:

kubectl get events -n cloud-analytics --field-selector reason=NodeNotReady
kubectl get pods  -n cloud-analytics -o wide   # RESTARTS ages clustered together + shared NODE = one node took them all

The fix is write-side and operational, never a query change. The decisive lever for an in-memory streaming store is giving its compute path CPU it doesn't have to fight for: a burstable instance's CPU credits were throttling RisingWave's checkpoint-commit path 10–29 % of scheduling periods, which dragged its committed-epoch clock behind wall-clock — and that skew is the freshness number. Moving RW compute onto non-burstable CPU cut throttling to under 1 % and steady-state freshness from ~10 s to ~2.3 s, with no change to the read path. The read latency was never the problem; the store's scaling levers are compute sizing and checkpoint cadence.


Chart 2 — Fleet Free CPU & Memory

Pulls cpu_pct and mem_used_pct sensor values from mv_sensor_fleet_latest (RisingWave) or sensor_readings (TimescaleDB), averages them across all nodes, and displays 100 - value as "free" percentage.

Why the two bars are nearly identical

Both databases read the same underlying data from MSK. The difference, if any, reflects propagation lag: TimescaleDB rows arrive via Redpanda Connect's 1-second batch window, so at any instant its averages may lag RisingWave by up to ~2 s.


Chart 3 — Time Since Last Message per Node

Shows how recently each node sent a message, as seen independently by RisingWave and TimescaleDB. In steady state both should be ≤ 2 s (1 Hz publish + pipeline latency). A node going dark (no messages) will show an increasing bar, making it easy to spot a disconnected device.

The node label is shortened from ws-slot00-edge-0 to edge-0 for readability.


How the Push Path Works

RisingWave and TimescaleDB both push updates to the browser instead of being polled — no setInterval for either live tier. Each has a server-side relay route in the dashboard app that holds one long-lived database connection and fans out over Server-Sent Events:

flowchart TD
  B1["Browser"]
  H1["Next.js Route Handler<br/>pg connection: DECLARE ... SUBSCRIPTION CURSOR FOR dashboard_freshness_sub<br/>loop: FETCH FROM cursor → re-run freshness query → push as SSE event"]
  RW["RisingWave<br/>(Block 2's dashboard_freshness_sub)"]

  B2["Browser"]
  H2["Next.js Route Handler<br/>pg connection: LISTEN sensor_readings_change<br/>on NOTIFY → re-run freshness query → push as SSE event"]
  TS["TimescaleDB<br/>(trigger: notify_sensor_reading() → pg_notify, once per INSERT<br/>statement into sensor_readings, not per row)"]

  B1 -->|"EventSource → /api/stream/risingwave (SSE)"| H1 --> RW
  B2 -->|"EventSource → /api/stream/timescaledb (SSE)"| H2 --> TS

RisingWave's native subscription cursor and Postgres's LISTEN/NOTIFY are both wire-protocol primitives — neither needs an external broker. That a store exposes a change feed on its own protocol is itself a datastore property: it's what lets these two tiers push rather than be polled.

Athena and InfluxDB stay on-demand/polled — neither exposes a subscribe primitive we use here (Athena is a warehouse query; Timestream for InfluxDB is a managed store read with a Flux query, not a LISTEN/SUBSCRIBE cursor). So those two tiers are read on a fixed interval — a tighter cadence for InfluxDB's fast time-series read, a slower one for the warehouse round-trip. That the managed store gives up the push primitive is the direct trade for its zero operational surface — see Block 5.