Skip to main content
Version: v0.12

Kafka Engine Configuration

Apache Kafka is a streaming data platform that serves as the log engine in DataSQRL pipelines for handling data streams and event logs.

Configuration Optionsโ€‹

KeyTypeDefaultDescription
retentionstring or nullnullTopic retention time (e.g., "7d", "24h"); null or "-1" retains data indefinitely
watermarkstring"0 ms"Watermark delay for event time processing
transaction-watermarkstring"0 ms"Watermark delay for event time processing when transactions are enabled
use-source-watermarkbooleanfalseUse Flink's SOURCE_WATERMARK() for non-transactional Kafka tables
use-transaction-source-watermarkbooleanfalseUse Flink's SOURCE_WATERMARK() for transactional Kafka tables
num-partitionsinteger1Number of partitions for generated Kafka topics
replication-factorinteger3Replication factor for generated Kafka topics

Example Configurationโ€‹

{
"engines": {
"kafka": {
"retention": "14d",
"watermark": "2 sec",
"transaction-watermark": "10 sec",
"use-source-watermark": true,
"use-transaction-source-watermark": true,
"num-partitions": 4,
"replication-factor": 3
}
}
}

Usage Notesโ€‹

  • Kafka topics are automatically created based on your SQRL table definitions
  • Topic configurations are generated during the compilation process
  • kafka.json lists the topics that a standalone included project writes and the current project uses under includedTopics, with only their names, because that project owns them and decides their settings: the topics of its internal Kafka tables and of the subscriptions that its deployment exposes. Flink does not write those subscription topics, and the include's EXPORT and INSERT statements into the log, its internal Kafka tables and external tables don't run, because the included project's deployment runs them
  • Only the mutation table writes its Kafka topic. Another writer mixes its rows into the mutation, and a writer that reads the mutation reads its own output in an endless loop. When the kafka connector template gives a Kafka table that the compiler creates for Flink the topic of a mutation table, the compiler puts <table-name>-subscription in place of ${sqrl:table-name} in the template's topic instead, so acme-${sqrl:table-name} gives acme-Events-subscription. If the template gives a mutation topic again, for example with a fixed topic without ${sqrl:table-name}, the compile fails with an error. For example, a script defines the mutation table Events with CREATE TABLE and the engine(kafka) hint, and a SUBSCRIBE function reads Events directly. Flink then copies Events into a Kafka table for the subscription. With the default templates, the mutation topic is Events and the copy gets the topic Events-subscription. An EXPORT statement to log.<name> or logger.<name> that gets the topic of a mutation table fails with an error, for example EXPORT Orders TO log.Events when Events is a mutation table. Use a different name in the EXPORT statement. All other topics keep the name from the template. The compiler does not check an EXPORT statement that writes directly into a mutation table, such as EXPORT _Echo TO Events. When the exported query reads that mutation table, the export loops
  • Retention settings control how long data is stored in Kafka topics
  • Ensure replication-factor does not exceed the number of brokers in the target Kafka cluster
  • Watermarks are used for handling late-arriving events in stream processing
  • Source watermarks apply only to mutation tables with a timestamp metadata column. When enabled, they generate WATERMARK FOR <timestamp-column> AS SOURCE_WATERMARK() instead of using the corresponding watermark delay. It is only supported by our kafka-safe and upsert-kafka-safe connectors.
  • Kafka serves as the messaging backbone between different engines in the pipeline

Key and Value Formatsโ€‹

The kafka and kafka-mutation connector templates set one format (flexible-json by default) for the message key and value. To use separate formats, set key.format and value.format in the template, or in the WITH options of an internal table:

{
"connectors": {
"kafka-mutation": {
"key.format": "json",
"value.format": "flexible-json"
}
}
}
  • key.format and value.format take precedence over format, which the default template always contains.
  • Tables with a message key (PARTITIONED BY or a primary key) use key.format for the key, otherwise format, otherwise value.format. Tables without a message key drop key.format.
  • Options of format, such as flexible-json.timestamp-format.standard, apply only to the key or value that uses that format. Set an option for one side with a key. or value. prefix, for example value.flexible-json.timestamp-format.standard.
  • When key.format and value.format are the same, the compiler notes that format is enough.
  • The server writes mutations as JSON, so the compiler warns when a mutation table uses a format other than json or flexible-json.

Internal Environment Variablesโ€‹

When running pipelines with the DataSQRL run command, the following environment variables are used in the configuration:

  • KAFKA_BOOTSTRAP_SERVERS
  • KAFKA_GROUP_ID