
Routing Multiple Query Engines with Iceberg
How to route queries across Trino, Spark, DuckDB, Snowflake, Athena, and Flink on shared Iceberg tables — covering routing architecture, dialect translation, and strategies.
Query Routing
One SQL endpoint in front of Trino, DuckDB, StarRocks, Athena, Snowflake, and more. Your rules send each query to the engine that fits, with no application changes. Built on open-source QueryFlux.
LakeOps| Operation | Table | Duration | Impact | Time | Status |
|---|---|---|---|---|---|
| Compact Data Files | customer_orders orders | 4s | 1.24 TB, 16 → 1 files | 57 minutes ago | SUCCESS |
| Expire Snapshots | payment_transactions payments | 27s | 8.2 TB | 4 hours ago | SUCCESS |
| Expire Snapshots | inventory_snapshots_20250702 warehouse | 3s | 2.1 TB | 4 hours ago | SUCCESS |
| Rewrite Manifests | raw_clickstream analytics | 1.9s | 3 → 1 manifests | 5 hours ago | SUCCESS |
| Compact Data Files | product_catalog products | 6m 11.3s | 3,008 → 1,256 files | 6 hours ago | SUCCESS |
Open and runs on your stack
How it works
Clients keep the protocol they speak. Rules pick a routing group, the group's strategy picks an engine, and every query is on record.
Trino, Postgres, MySQL, Snowflake, Flight SQL, and MCP clients connect as they do today.
Put engines into routing groups with capacity limits and a balancing strategy.
Route by protocol, header, SQL pattern, client tags, or a Python function.
Each query is recorded with its routing group, engine, status, and duration.
Clients connect with
Route
Queue
Translate
<1 ms
Engines run it
01 · One endpoint
routers:
- type: header
headerName: X-Workload
headerValueToGroup:
dashboard: interactive
etl: batch
- type: queryRegex
rules:
- regex: "(?i) limit \\d+$"
targetGroup: duckdb-local
- type: tags
rules:
- tags: { team: finance }
targetGroup: finance
routingFallback: interactive02 · Routing rules
interactiveleastLoadedbatchfailoveragentsroundRobin03 · Routing groups
CPU-heavy joins and aggregations
Compute-priced
Selective scans over cold data
Scan-priced
Small lookups and filters
In-process
2–5×
Cost of a mismatched engine
Up to 56%
Lower suite cost, matched
04 · Cost and latency
Compare engines side-by-side on cost, latency, throughput, and data scanned.
| Metric | Spark | Trino | Athena | Snowflake |
|---|---|---|---|---|
| Query success rate | 99.2% | 99.5% | 99.9% | 99.8% |
| Average runtime | 3.1s | 1.8s | 2.3s | 2.1s |
| Cost per query | $0.04 | $0.03 | $0.05 | $0.08 |
| Total queries | 3,120 | 2,456 | 1,280 | 1,876 |
| Data scanned | 4.2 TB | 2.8 TB | 1.5 TB | 3.5 TB |
Lower-left is ideal
05 · Engine comparison
Client sends · dialect: snowflake
SELECT IFF(amount > 100, 'big', 'small'),
DATEADD(day, -7, CURRENT_DATE)
FROM ordersRuns on Trino
SELECT IF(amount > 100, 'big', 'small'),
DATE_ADD('day', -7, CURRENT_DATE)
FROM orders06 · SQL dialects
read_onlyBlocks writes and DDLrow_limitCaps rows returned (max_rows)require_predicateRejects full scans on big tablesopa_accessRow filters and column masks07 · AI agents
12×
Faster queries
−51%
Data scanned
−62%
S3 GETs
08 · Healthy tables
LakeOps reads your Iceberg metadata. Data stays in your storage.
Every table's health and what it needs, from the first scan.
Autopilot, on-demand runs, or your own policies.
The challenge
Query shapes differ, engines bill differently, and workloads compete. Without a routing layer, every app picks an engine once and lives with it.
Dashboards, ETL, and ad-hoc exploration all land on one engine, whatever their shape. Small lookups wait behind batch jobs.
Every engine brings its own drivers, credentials, and connection strings. Adding or swapping an engine means changing every client.
Compute-priced engines bill for CPU time; scan-priced ones bill for bytes read. A query on the wrong model can cost 2–5× more.
A batch job and an interactive dashboard on the same cluster slow each other down. Without isolation, latency is unpredictable.
Compare
Hard-coded connections can't adapt, and Trino Gateway stops at Trino. LakeOps routing spans engines and client protocols behind one endpoint.
| Capability | One engine per app | Trino Gateway | LakeOps, powered by QueryFlux |
|---|---|---|---|
| Engines | Whichever engine the app is wired to | Trino clusters | Trino, DuckDB, StarRocks, Athena, ClickHouse, plus Snowflake, Databricks, BigQuery, Redshift, and PostgreSQL via ADBC |
| Client protocols | Each engine's own driver | Trino HTTP | Trino HTTP, PostgreSQL wire, MySQL wire, Snowflake HTTP, Arrow Flight SQL, and MCP |
| How queries are routed | Hard-coded in each app | Routing rules across Trino clusters | Protocol, header, SQL pattern, client tags, Python, or compound rules, with a fallback group |
| Capacity | The engine's own queues | Health checks across clusters | Per-group concurrency limits, proxy-side queueing, and health-aware strategies |
| SQL dialects | Rewrite queries by hand | Trino SQL | Optional translation between dialects when the client asks for it |
| AI agents | Credentials per engine | Not built in | MCP endpoint with read-only, row-limit, and predicate guardrails |
| Source | — | Open source (Apache-2.0) | Open source (Apache-2.0) |
Trino Gateway details are from its public documentation, November 2026. QueryFlux overhead from its open-source proxy benchmark; cost figures from QueryFlux's routing tests.
Results
Benchmarks from production-grade tables across multiple engines and clouds.
Query speed
After compaction + layout optimization
CPU reduction
Compute hours across all engines
Storage saved
Orphans, snapshots & bloat removed
Table health
Autonomous maintenance keeps every table optimized
See it in action
Healthy tables and the right engine for each query, across your lakehouse.
FAQ
A router that sits between your clients and your query engines. Clients connect to one SQL endpoint, and rules decide which engine runs each query, for example dashboards on a low-latency engine and heavy ETL on a cheaper one, without changing application code.
Engines: Trino, DuckDB, StarRocks, Athena, and ClickHouse, plus Snowflake, Databricks, BigQuery, Redshift, and PostgreSQL through ADBC. Clients connect over Trino HTTP, PostgreSQL wire, MySQL wire, Snowflake HTTP, Arrow Flight SQL, or MCP.
Engines bill differently: compute-priced engines charge for CPU time, scan-priced engines for bytes read. Sending each query shape to the pricing model that fits it avoids the 2–5× penalty of a mismatch. In QueryFlux's routing tests, matching shapes to engines cut the cost of a representative suite by up to about 56%. You express that logic as routing rules or a Python router.
Well under a millisecond. QueryFlux is written in Rust, and its proxy overhead benchmark measures a fraction of a millisecond per query at the median.
Only the connection: point the client at the routing endpoint using the protocol it already speaks. After that, engines can be added, removed, or swapped behind the endpoint without client changes. SQL is sent as written unless the client asks for dialect translation.
Trino Gateway load-balances and routes across Trino clusters. LakeOps routing, built on QueryFlux, routes across different engines, accepts several client protocols, can translate SQL dialects, and gives AI agents a guarded MCP endpoint.
Yes. QueryFlux is an open-source (Apache-2.0) SQL proxy and router in Rust, maintained by the LakeOps team. LakeOps query routing is built on it, so your routing configuration is portable.
Related
Resources
Route across Trino, DuckDB, StarRocks, Athena, and Snowflake, with no app changes.