Triage note (2026-04-23): Part of the Matrix Builder epic alongside #35 (road-aware tessellation). Land #35 first. Without #35's road-aware filter toggle, this ticket's estimator would systematically over-predict hex counts (and therefore rows, credits, and duration) for any region with significant uninhabited area. The ESTIMATE_MATRIX_COST procedure must accept the road_filter flag as an input and return distinct estimates for filter ON vs OFF; calibrate both against historical runs.
Summary
Add a pre-flight cost estimation feature to the Matrix Builder that, given a user's configuration (region, resolution, routing profile, bounding box, etc.), predicts:
- Resulting matrix row count — smart calculation based on tessellation resolution and region geometry, before any compute runs.
- Expected Snowflake query cost — warehouse credits consumed for the SQL-side work (tessellation, matrix assembly, writes).
- Expected SPCS / ORS compute cost — compute-pool credits consumed by ORS services answering matrix calls.
- Expected wall-clock duration — based on historical runs of comparable shapes/resolutions.
The goal is to let users make an informed choice before kicking off a potentially expensive matrix build.
Motivation
Today users configure a region + H3 resolution + routing profile and click build with no visibility into:
- How many origin/destination pairs this will produce (can easily be millions)
- How many warehouse credits will be burned
- How much SPCS compute the ORS services will consume
- How long it will take
This leads to surprise bills, stuck long-running jobs, and unrealistic resolutions (e.g. res 9 over a metropolitan region).
Proposed Work
1. Smart row-count estimation
- Compute the effective tessellation cell count for the chosen region + resolution without materializing the tessellation.
- Use
ST_AREA(region_geometry) divided by average H3 cell area at the chosen resolution, adjusted for coastline/boundary clipping.
- Validate against actual counts from previously-built regions; store calibration factors per resolution.
- Resulting matrix rows =
cells * cells (or cells * cells - cells if diagonal excluded).
- Surface both the cell count and the matrix row count in the UI before the user confirms.
2. Query cost estimation
- Reuse historical
QUERY_HISTORY credits-used data for prior matrix builds, keyed by (region_size_bucket, h3_resolution, profile).
- Formula:
estimated_credits = base_cost + per_cell_cost * cell_count + per_pair_cost * pair_count.
- Fit coefficients from
QUERY_HISTORY / SERVERLESS_TASK_HISTORY for matrix pipeline queries (filter by query_tag origin sf_sit-is-fleet).
3. SPCS / ORS compute cost estimation
- ORS matrix calls scale roughly with
pair_count and routing profile complexity (driving-car < cycling < foot-walking < hgv).
- Derive per-profile throughput (pairs/sec) and compute-pool credit rate from historical SPCS runs.
- Surface a separate "ORS compute" line item alongside warehouse credits.
4. UI integration
- Add an "Estimate cost" button in the Matrix Builder config panel (
ors_control_app).
- Show a summary card:
- Tessellation cells: 12,450
- Matrix rows: ~155M
- Warehouse credits: ~8.2
- ORS compute credits: ~4.1
- Estimated duration: 22 min
- Confidence: medium (based on 14 prior runs)
- Color-code thresholds (green / yellow / red) so risky configs are obvious.
- Require explicit confirmation when the estimate exceeds a configurable threshold.
5. Backend
- New stored procedure
OPENROUTESERVICE_APP.CORE.ESTIMATE_MATRIX_COST(region, resolution, profile, bbox) returning a JSON cost breakdown.
- Backing calibration table populated from
QUERY_HISTORY + SPCS usage views; refreshed via a scheduled task.
- Tag all objects per repo convention:
query_tag: {"origin":"sf_sit-is-fleet","name":"oss-matrix-cost-estimator","version":{"major":1,"minor":0},"attributes":{"is_quickstart":1,"source":"sql"}}
- Object
COMMENT with the same tag on every CREATE.
Acceptance Criteria
Out of Scope
- Real-time in-flight cost tracking (separate ticket).
- Cross-account chargeback (separate ticket).
Summary
Add a pre-flight cost estimation feature to the Matrix Builder that, given a user's configuration (region, resolution, routing profile, bounding box, etc.), predicts:
The goal is to let users make an informed choice before kicking off a potentially expensive matrix build.
Motivation
Today users configure a region + H3 resolution + routing profile and click build with no visibility into:
This leads to surprise bills, stuck long-running jobs, and unrealistic resolutions (e.g. res 9 over a metropolitan region).
Proposed Work
1. Smart row-count estimation
ST_AREA(region_geometry)divided by average H3 cell area at the chosen resolution, adjusted for coastline/boundary clipping.cells * cells(orcells * cells - cellsif diagonal excluded).2. Query cost estimation
QUERY_HISTORYcredits-used data for prior matrix builds, keyed by(region_size_bucket, h3_resolution, profile).estimated_credits = base_cost + per_cell_cost * cell_count + per_pair_cost * pair_count.QUERY_HISTORY/SERVERLESS_TASK_HISTORYfor matrix pipeline queries (filter byquery_tagoriginsf_sit-is-fleet).3. SPCS / ORS compute cost estimation
pair_countand routing profile complexity (driving-car < cycling < foot-walking < hgv).4. UI integration
ors_control_app).5. Backend
OPENROUTESERVICE_APP.CORE.ESTIMATE_MATRIX_COST(region, resolution, profile, bbox)returning a JSON cost breakdown.QUERY_HISTORY+ SPCS usage views; refreshed via a scheduled task.query_tag:{"origin":"sf_sit-is-fleet","name":"oss-matrix-cost-estimator","version":{"major":1,"minor":0},"attributes":{"is_quickstart":1,"source":"sql"}}COMMENTwith the same tag on every CREATE.Acceptance Criteria
ESTIMATE_MATRIX_COSTprocedure returns cell count, row count, WH credits, SPCS credits, duration estimate, and confidence.QUERY_HISTORY/ SPCS usage.sf_sit-is-fleet,oss-matrix-cost-estimator).build-routing-solution(or a newmatrix-builder) skill's SKILL.md and references.Out of Scope