Skip to main content

dfe-loader architecture

dfe-loader is the last hop of the DFE data path: it takes records from Kafka or a gRPC push and inserts them into ClickHouse tables in batches. It needs no mapping first, because it reads each table's columns from ClickHouse and keeps whatever doesn't fit in _json.

Figure 1. L3 Components -- dfe-loader. The dotted arrow is the dead-letter path. Up: L2 Services -- DFE deployment. Down: L4 Detail -- Transport, L4 Detail -- Pipeline, L4 Detail -- ClickHouse insert layer.

How data flows​

  1. The transport is scalo's. On Kafka it consumes the configured topics. With transport: grpc it serves a gRPC listener on port 6000 that dfe-receiver and the transforms push to directly. Both hand the pipeline the same message, so nothing after them knows which one a record came on.
  2. The pipeline refuses anything not JSON, parses it once with SIMD and routes it to a db.table from its routing fields. It promotes the fields that match the table's columns, adds the enrichment columns and puts the row in that table's buffer.
  3. The ClickHouse insert layer flushes each table's buffer as a batched INSERT, RowBinary by default, so ClickHouse parses no row text. Rows ClickHouse refuses for good go to the DLQ.
  4. With kafka.acknowledgements.enabled (the default) Kafka offsets commit once per flush cycle, never past a row not yet placed. Delivery is at-least-once.

Components​

PartRolePage
Transportscalo's Kafka and gRPC transports, adapted to one message typetransport/README.md
PipelineThe per-message pass and the per-table bufferspipeline/README.md
ClickHouse insert layerThe dynamic insert, insert formats, the schema cache, retries and salvageclickhouse/README.md

External dependencies​

DependencyWhen it's neededWhat can stand in
Kafkatransport: kafka (the default), and the default DLQAny broker scalo's Kafka transport reaches
gRPC senderstransport: grpcdfe-receiver and the transforms, over scalo's Push
ClickHouseAlwaysA server in the cluster over HTTP or the native protocol, or ClickHouse Cloud, where a host under clickhouse.cloud turns TLS on
The DFE tablesAlwaysdfe-engine creates them from the dfe-schemas manifest. The loader never runs DDL
GeoIP databasesgeoip.enabledMaxMind GeoLite2 or DB-IP files, downloaded at startup or mounted

A missing GeoIP database leaves enrichment off and never stops the loader. A missing table holds its records until the schema arrives, up to schema.pending_max_age_secs, and then dead-letters them.

Deployment variants​

Kafka is the default transport. With transport: grpc there are no broker offsets: a held batch is answered UNAVAILABLE to its sender instead of holding a partition's commit, and the DLQ is file only.

kafka.acknowledgements.enabled: false commits offsets at receipt. The buffered rows are then their only copy, so a kill loses them.

The released chart scales on CPU, with its Kafka lag trigger off, because raw consumer lag rises when a stage downstream breaks. In a DFE deployment, dfe-infra's values set the CPU target to 70% and add the scaling-pressure trigger. The slim profile clears that trigger, so slim scales on CPU alone. operations.md has the numbers.

Design considerations​

Reliability. The insert tail degrades rather than stalls. A data error splits the batch down to the bad rows, which go to the DLQ, and the rest land. A failed insert never sends its batch to the DLQ: it holds the batch and its partition's commit, and retries with jittered backoff. A cycle in which every insert failed opens the circuit gate on the scaling signal, since more pods can't help a dead ClickHouse. operations.md has every case.

Performance. Everything on the hot path follows one rule: do the cheap thing per message, and defer the expensive thing to flush. The payload is parsed once and kept as a reference-counted Arc<[u8]>. Only schema columns are promoted, and the payload is spliced in as _json only when the batch is serialised. performance/overview.md has the rest.

Operations. /readyz stays 503 until ClickHouse accepts the configured user and answers reads of the database's tables and columns. Until then the loader joins no consumer group and opens no gRPC listener, so a pod with a wrong password takes no partitions from the pods that can write. An outage after that doesn't flip readiness, which would pull every loader out of its Service at once. clickhouse_connected reports it instead.

Security. The loader has no listener an outsider can reach: its gRPC port takes pushes from dfe-receiver and the transforms. TLS to ClickHouse is clickhouse.tls.enabled with the CA in the trust store, and clickhouse/tls.md has the private-CA case.

Why it's built this way​

The insert is dynamic. The clickhouse crate keeps insertion typed, with a compile-time schema, and that is the right upstream default. A loader that takes any table can't know its columns at compile time. So rows are Map<String,Value>, encoded against the schema read from system.columns at runtime by dfe-clickhouse's dynamic module.

RowBinary is the default. The rows go to ClickHouse already typed, so the server parses no row text. JSONEachRow stays as an HTTP fallback.

A rejection is read by its code, never its words. A parse rejection echoes the offending row back, so the message text can carry anything. The loader reads the server's exception code and keeps at most 1 MiB of any error text.

The engine owns the schema. The loader never creates or alters a table. A record for a table that isn't there yet waits for it, so a schema change has one owner.

The payload is stored once. Under the default capture_mode: full a JSON record lands in _json, beside the promoted columns, and nowhere else. pipeline/capture-modes.md has the four modes.

Diagram map​

What's next​