Data pipelines | Data pipelines

Data pipelines

A data pipeline runs a scheduled MQL aggregation query against your captured data and stores the results as precomputed summary documents. Instead of querying 86,000 raw sensor readings to compute an hourly average, you query a single summary document that the pipeline already computed.

When to use pipelines

Pipelines are useful when:

Pipelines are not necessary when:

Pipelines don't reduce data transfer

Pipelines run in the cloud against data that has already been synced. They reduce query time, not bandwidth or storage volume. To reduce what gets sent from the machine, see Filter at the edge.

How pipelines work

A pipeline has four parts:

  1. An MQL aggregation query. A sequence of MongoDB aggregation stages ($match, $group, $project, and others) that transforms raw documents into summary documents. You write the query; the pipeline runs it automatically. See Examples and tips for common patterns.

  2. A cron schedule. Determines how often the pipeline runs. The schedule also determines the query time window: an hourly schedule (0 * * * *) scopes each run to the previous hour of data. A 15-minute schedule (*/15 * * * *) scopes each run to the previous 15 minutes. Schedules are in UTC.

  3. A data source. Either standard (the raw readings collection containing all historical data) or hot-storage (the hot data store containing a rolling window of recent data). See Data source types for the full list.

  4. A pipeline sink. The destination collection where results are stored. Each pipeline has its own sink. You query pipeline results by specifying the pipeline-sink data source type and the pipeline’s ID.

Execution flow

When a pipeline’s cron schedule triggers:

  1. The pipeline determines the time window from the schedule (for example, 02:00 to 03:00 PM for an hourly pipeline running at 03:00 PM).
  2. It prepends a time constraint to your MQL query that limits it to documents within that window.
  3. It executes the query against the configured data source with a 5-minute timeout.
  4. If the query produces 10,000 or fewer documents, results are written to the pipeline sink.
  5. The run is marked as completed or failed.

Each run processes exactly one time window with no gaps and no overlaps between consecutive runs.

Backfill

When you enable backfill on a pipeline, Viam processes historical time windows that the pipeline missed. This is useful in two scenarios:

When backfill is disabled, each time window is processed exactly once. Late-arriving data is not incorporated into past summaries.

Limits

Data source types

Source type What it queries When to use
standard The raw readings collection containing all historical tabular data Default. Use for aggregations over any time range.
hot-storage The hot data store containing a rolling window of recent data Use when your pipeline only needs recent data and you want lower query latency.
pipeline-sink The output of another pipeline Use when chaining pipelines: one pipeline produces summaries, another aggregates those summaries further. Requires the source pipeline’s ID.

What’s next