Skip to content

feat(spark): stage-scoped dbt-spark SQL runtime and distributed Kubernetes execution #886

Open

Description

@malon64

Goal — v0.8 Spark processing (parallel track)

Decision 2026-11-19 — ephemeral compute per run, no persistent Spark service. Spark follows the Floe model: a pipeline run launches a Kubernetes Job sized from processing.gold.size, runs dbt build, and every Spark pod is gone when the run ends. No always-on driver, Thrift Server or stage-scoped SQL service, so cluster capacity returns to the other services between runs. Rationale: a long-lived SQL server (Trino today) is built to stay up and does not add executors per run; heavy Gold builds then compete with interactive queries.

  • First choice — dbt-spark method: session: the Job's pod runs dbt build and is itself the Spark driver (Spark-on-Kubernetes client mode). The driver creates executor pods; spark.kubernetes.driver.pod.name gives them an OwnerReference to the driver pod, so Kubernetes deletes them when the Job ends. Needs a headless service so executors reach the driver (spark.driver.host/spark.driver.port) and a stage ServiceAccount allowed to create pods in the stage namespace. Risk: dbt documents session as for advanced users / experimental and not supported by dbt — the feat(dbt): make Gold dbt adapters portable across Trino and Spark with Iceberg conformance #887 conformance gate decides whether it holds.
  • Phasing (decided 2026-11-19):
    • Phase 1 — Spark local mode, one pod. The per-run Job runs a single pod: dbt build with method: session and spark.master=local[*], sized from the profile like a Floe Job (Floe runs Polars/DuckDB in its own pod the same way). Goal: prove the dbt-spark ↔ Iceberg/Polaris connection, the profile template, the per-run lifecycle and the feat(dbt): make Gold dbt adapters portable across Trino and Spark with Iceberg conformance #887 conformance tests. No executors, so no headless service and no pod-creation RBAC yet. This is also the long-term size: small (dev, small volumes).
    • Phase 2 — distributed executors for medium/large: the same Job pod becomes the client-mode driver and creates executor pods (OwnerReference, headless service, pod-creation ServiceAccount as below). Same image and same dbt profile as phase 1; only Spark settings change. Add scheduling protection before production use: PriorityClass so platform services win over runs, per-stage ResourceQuota, and evaluate all-or-nothing admission (e.g. Kueue) so concurrent runs cannot deadlock with drivers up and executors pending.
  • Fallback — method: thrift, per-run Thrift Server: the run starts a Spark Thrift Server with its executors, waits for readiness, runs dbt build, then deletes everything (including on failure/cancel). Officially supported transport, more moving parts.

Implement the Kubernetes compute runtime through which dbt-spark actually executes SQL. This is a prerequisite for #880, but independent of DuckDB query work (#547). Spark is used for dbt Gold transformations only, with no standalone non-dbt Gold writer.

Technical decision gate (prototype before choosing topology)

  • Evaluate the pinned dbt-spark supported transports (Spark Thrift Server, Livy if compatible, and any supported session mode). Document connection semantics, versions, health/readiness, driver placement, server lifetime, cancellation and concurrency.
  • Prove a real dbt build can connect, issue SQL and materialize Iceberg on Spark-on-Kubernetes. A Spark Operator SparkApplication by itself does not provide dbt-spark SQL connectivity. Don't assume Spark Thrift Server runs in Spark cluster submission mode.
  • Lifecycle is decided: per-run and ephemeral (see decision above). Prototype session first, fall back to a per-run Thrift Server only if session fails feat(dbt): make Gold dbt adapters portable across Trino and Spark with Iceberg conformance #887 conformance. Measure and document cold start (JVM + executor scheduling) instead of trading it for an always-on service.
  • Use version-pinned Spark, Java, Iceberg runtime and adapter artifacts; bake dependencies into images (no uncontrolled runtime downloads).

Implementation boundaries

  • Dedicated infra/terraform/modules/processing/spark/ (or equivalent) driven by processing.gold contracts, release/ size templates and stage/provider runtime bindings.
  • Isolated driver/executors with service accounts, per-stage Polaris OAuth/REST, S3 credentials, endpoint/path-style for SeaweedFS, Secret refs and namespace/network policies.
  • Resource caps for executor count (including dynamic allocation if supported), CPU/RAM, query/runtime timeout, retries, pod labels (stage, product, run), logs and cleanup after crashes.
  • Dagster launches the per-run Spark Job (same pattern as Floe Jobs: one Job per run, dagster/run-id label, size from the profile), runs dbt build, captures command failures/cancellation and tears down every driver/executor/service resource at the end of the run, including on failure and cancel.
  • For Trino-free combination the runtime must not call any Trino service. Multi-node K3s test on test(onprem): real multi-node K3s qualification and RKE2 smoke #804 environment; local kind smoke first.

Acceptance

  • Working connection mode with reproducible dbt build SELECT + Iceberg table write; ADR explains why other transports were rejected.
  • Zero Spark pods or services exist between runs; after success, failure and cancel, no driver, executor or Thrift Server is left in the stage namespace.
  • Phase 1: one-pod Spark local mode runs dbt build end to end on local kind, sized from the profile, and the pod is gone after the run.
  • Phase 2: two or more Spark executor pods distributed on K3s nodes during dbt execution; quotas, priorities and retry/cancel work.
  • Stage namespace and temporary credentials isolate DEV/UAT/PROD; no public SQL endpoint.
  • No runtime artifact downloads or secrets in image, manifest, log or ProjectRevision.
  • Baseline dbt-trino/Trino topology unchanged when Spark is not selected.

Related: #879 #880 #546 #802 #804. P1 optional processing backend in v0.8; not an on-prem P0 gate.

Activity

  1. added this to the milestone on Nov 5, 2026
  2. added
    roadmap
    priority: P1
    track: workloads
    on Nov 5, 2026
  3. modified the milestones: , v0.8-beta — Cloud and On-Premises Beta, v0.9-beta — Cloud Cost and Capacity on Nov 19, 2026
  4. malon64 commented on Nov 19, 2026

    @malon64
    CollaboratorAuthor

    Moved from v0.8-beta to v0.9-beta (2026-11-19): v0.8 qualifies the current stack (Trino + dbt-trino) on cloud and on-premises; separating the compute and query engines follows in v0.9, which already targets scale-to-zero and burst capacity for batch and query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: P1roadmaptrack: workloadstype: feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions