# Control plane and runners (https://docs.openetl.io/docs/next/internals/architecture)

This page describes the main components for contributors. [Self-host](../self-host/index.md) covers installation.

## The parts [#the-parts]

```mermaid
flowchart LR
  cli[openetl CLI] --> api
  console[Console] --> api
  subgraph control[Control plane]
    api[API server] --> pg[(Postgres)]
    orch[Orchestrators] --> pg
  end
  subgraph data[Data plane]
    runner[Runner] --> src[Source connector]
    runner --> engine[openetl-engine]
    runner --> dst[Destination connector]
  end
  runner -- long-polls for work --> api
  runner --> store[(Object storage)]
```

[`internal/daemon`](../../internal/daemon) runs the roles of the `openetld` program. `server` serves the API and console. `orchestrator` executes workflows and assigns jobs. `runner` executes attempts. `dev` combines all three roles in one process.

## The API [#the-api]

[`internal/api`](../../internal/api) serves the API defined in [`proto/openetl/api/v1`](../../proto/openetl/api/v1) over Connect, gRPC, gRPC-Web and REST. Vanguard transcodes the REST routes from `google.api.http` rules. These rules also generate `internal/api/openapi.yaml`.

The CLI and console use this API. [`internal/webui`](../../internal/webui) serves the built console from the same origin.

Runners call `DataPlaneService`, defined in [`proto/openetl/dataplane/v1`](../../proto/openetl/dataplane/v1). A runner token limits each runner to its data plane's work. [`internal/auth`](../../internal/auth) manages API keys, runner tokens and roles.

## The metadata store [#the-metadata-store]

[`internal/store`](../../internal/store) is the metadata database, on Postgres: its goose migrations, and the queries from which sqlc generates `internal/store/db`. Every query outside the `orgs` table is scoped by `org_id`, which `TestQueriesAreOrgScoped` checks.

The database has a format, `store.Format`, which goes up only with a change that older binaries cannot work with. Before it migrates, `Migrate` refuses a database whose format is higher than its own, and then records its own format and release in the `install` table. The DBOS backend's `openetl` schema has a format of its own, and its changes are an ordered list of steps.

[`internal/secrets`](../../internal/secrets) encrypts secret values before storage. Each organization has data keys. Its active key encrypts new values with AES-256-GCM, and each value starts with a version byte and the ID of the key that encrypted it. The installation's local or KMS key wraps those data keys.

Secrets can also reference AWS Secrets Manager, GCP Secret Manager or Azure Key Vault. Runners resolve these references with their cloud identity through [`internal/secretstore`](../../internal/secretstore).

## Orchestration [#orchestration]

Workflows manage schedules, continuous-pipeline supervisors, syncs and operations such as source discovery. They use the interface in [`internal/orchestration`](../../internal/orchestration). The default DBOS backend stores workflow state in Postgres. Temporal is the other supported backend.

Steps perform I/O; workflow code does not. After a failure, workflow replay returns the recorded results of previous calls. Workflow code therefore cannot use its own clocks, randomness or goroutines. Changes that alter an existing workflow's execution path require `Context.Version`.

[`internal/orchestration/dispatch`](../../internal/orchestration/dispatch) sends work to data planes through the API. It uses Postgres dispatch records, leases and long polling to deliver results to waiting workflows. `sizing` selects the resources for the next attempt. `scaling` adjusts continuous jobs when their lanes need more or fewer resources.

## Runners [#runners]

A runner ([`internal/runner/worker`](../../internal/runner/worker)) registers with the API, polls for work, executes it and reports results. Each attempt goes to a runner in the pipeline's data plane and pool with sufficient capacity. A [pod launcher](../../internal/runner/pods) can instead create a Kubernetes pod for one attempt. That pod runs `openetld runner` and obtains the attempt from the API. [Install on Kubernetes](../self-host/kubernetes.md) explains sizes, pools and placement.

An attempt ([`internal/runner`](../../internal/runner)) hosts connectors, drives dataflow and coordinates checkpoints. Built-in connectors run inside the runner. External connectors run as separate processes and serve the connector protocol on Unix sockets. [`internal/connectorhost`](../../internal/connectorhost) supplies host services, including HTTP retries and secrets.

## What a component does not know [#what-a-component-does-not-know]

The control plane, a runner, the coordinator and workers of an attempt, and the engine are separate processes. A component can receive a message that a newer release wrote. The internal protocols, [`openetl.dataplane.v1`](../../proto/openetl/dataplane/v1), [`openetl.attempt.v1`](../../proto/openetl/attempt/v1) and [`openetl.engine.v1`](../../proto/openetl/engine/v1), follow these rules:

- **A field the receiver does not know** is ignored. So is a member of a work's JSON input. `openetl-engine plan` is the exception: it refuses a request with a member it does not know.
- **An enum number the receiver does not know** fails the work, the attempt or the job with `CONFIG_INVALID`. The error names the field and says that a newer version wrote it. The receiver does not use a default in its place. An error's code is the exception: an error with a code the receiver does not know is not retried.
- **A oneof that must be set** and holds no case the receiver knows fails the job in the same way. In the attempt protocol, it is out of the protocol and fails the attempt.
- **A requirement the receiver does not know** fails in the same way, and the error names it. `requires` in `Work`, `Assignment`, `StartJobRequest` and the request of `openetl-engine plan` names behaviors the receiver must implement. A sender names one when an older receiver would ignore a new field and give a different result. A runner reports such a failure of work as not retried. No names are in use.

Each component sends its release in its first exchange with another: a runner in `ReportRunnerRequest`, the control plane in `ReportRunnerResponse` and `PollWorkResponse`, a worker in `Join`, the runner in `StartJobRequest`, the engine in `StartJobResponse`, and each engine of an attempt in `MeshHello`. The receiver logs it. No component refuses another because of its release.

[`internal/platform/known`](../../internal/platform/known) checks what Go components receive, at the point where they receive it: the sync spec, a work's requirements, the attempt protocol's messages and the engine's events. A spec that a component reads from the metadata store goes through [`internal/store/stored`](../../internal/store/stored), which fails the read on an enum value whose name it does not know. `TestReceivedEnumsAreChecked` fails when a message that a runner receives carries an enum and nothing checks it. In the engine, [`known.rs`](../../crates/engine/src/known.rs) reads each enum field's raw number. `clippy.toml` disallows prost's accessors, which give the default for a number they do not know, on every message the engine receives, and a test fails when one is not listed.

## Around the data path [#around-the-data-path]

- **Incidents** ([`internal/heal`](../../internal/heal)) are opened and resolved, and their playbooks run, in the same transaction as the report that shows them.
- **Platform events** ([`internal/events`](../../internal/events)) enter an outbox in the transaction that changes the reported resource. [`internal/webhooks`](../../internal/webhooks) delivers them with Standard Webhooks signatures.
- **Outbound connections** go through [`internal/netguard`](../../internal/netguard), which checks every address after DNS resolution, against server-side request forgery.
- **Transforms** run on the user's clusters. [`internal/spark`](../../internal/spark) runs Spark applications. [`internal/flink`](../../internal/flink) runs a continuous pipeline's Flink job. [`libs/`](../../libs) contains the cluster-side libraries.
