Skip to main content

Ingest data from Apache Kafka

Beta

This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Databricks previews.

This page shows how to create a managed Kafka ingestion pipeline using Databricks Lakeflow Connect.

Requirements

  • To create an ingestion pipeline, you must first meet the following requirements:

    • Your workspace must be enabled for Unity Catalog.

    • Serverless compute must be enabled for your workspace. See Serverless compute requirements.

    • If you plan to create a new connection: You must have CREATE CONNECTION privileges on the metastore. See Manage privileges in Unity Catalog.

      If the connector supports UI-based pipeline authoring, an admin can create the connection and the pipeline at the same time by completing the steps on this page. However, if the users who create pipelines use API-based pipeline authoring or are non-admin users, an admin must first create the connection in Catalog Explorer. See Connect to managed ingestion sources.

    • If you plan to use an existing connection: You must have USE CONNECTION privileges or ALL PRIVILEGES on the connection object.

    • You must have USE CATALOG privileges on the target catalog.

    • You must have USE SCHEMA and CREATE TABLE privileges on an existing schema or CREATE SCHEMA privileges on the target catalog.

  • To ingest from Kafka, you must first complete the steps in Connect to Apache Kafka for managed ingestion.

Create an ingestion pipeline

Each Kafka topic is ingested into a streaming table. For a list of supported data and limitations, see Supported data.

note

UI-based pipeline authoring is not supported for the Kafka connector in Beta. Use Declarative Automation Bundles or a Databricks notebook to create your pipeline.

Use Declarative Automation Bundles to manage Kafka pipelines as code. Bundles can contain YAML definitions of jobs and tasks, are managed using the Databricks CLI, and can be shared and run in different target workspaces (such as development, staging, and production). For more information, see What are Declarative Automation Bundles?.

  1. Create a new bundle using the Databricks CLI:

    Bash
    databricks bundle init
  2. Add a pipeline definition file to the bundle (for example, resources/kafka_pipeline.yml). See pipeline.ingestion_definition and Examples.

  3. Deploy the bundle using the Databricks CLI:

    Bash
    databricks bundle deploy

Examples

Use these examples to configure your pipeline.

Minimal pipeline — raw binary key and value

This example ingests one or more Kafka topics with key and value columns retained as BINARY:

YAML
variables:
connection_name:
default: my-kafka-connection
dest_catalog:
default: main
dest_schema:
default: kafka_ingest
resources:
pipelines:
kafka_pipeline:
name: kafka-ingestion-pipeline
serverless: true
continuous: true
channel: PREVIEW
catalog: ${var.dest_catalog}
target: ${var.dest_schema}
ingestion_definition:
connection_name: ${var.connection_name}
objects:
- table:
source_table: N/A
destination_catalog: ${var.dest_catalog}
destination_schema: ${var.dest_schema}
destination_table: user_events
connector_options:
kafka_options:
topics: [user-events, power-user-events]

Pipeline with transformers — JSON value and string key

This example deserializes message keys as STRING and values as JSON with schema evolution enabled:

YAML
variables:
connection_name:
default: my-kafka-connection
dest_catalog:
default: main
dest_schema:
default: kafka_ingest
resources:
pipelines:
kafka_pipeline:
name: kafka-ingestion-pipeline
serverless: true
continuous: true
channel: PREVIEW
catalog: ${var.dest_catalog}
target: ${var.dest_schema}
ingestion_definition:
connection_name: ${var.connection_name}
objects:
- table:
source_table: N/A
destination_catalog: ${var.dest_catalog}
destination_schema: ${var.dest_schema}
destination_table: user_events
connector_options:
kafka_options:
topics:
- user-events
starting_offset: latest
key_transformer:
format: STRING
value_transformer:
format: JSON
json_options:
schema_evolution_mode: rescue

Common patterns

For advanced pipeline configurations, see Common patterns for managed ingestion pipelines.

Next steps

Start and set alerts on your pipeline. See Common pipeline maintenance tasks.

Additional resources