Skip to content

Kafka Connect — running a source and a sink connector in production

Standing up a Kafka Connect cluster, deploying a source connector and a sink connector, and the operational pieces — offsets, status, restarts — an MSP wires from day one.

Kafka Connect is the bridge that gets data into and out of Kafka without you writing a producer or consumer. This article is the install we run for clients moving data between a JDBC database and Kafka, and from Kafka into an object store: deploy a Connect cluster in distributed mode, install a source and a sink connector, configure them via the REST API, and wire the monitoring and restart story before the first production incident. The objective is a Connect cluster that an application team can submit configs to and an MSP can operate without surprises.

How to verify

Kafka Connect runs as its own JVM process and uses Kafka topics for state. Before installing, confirm broker reachability and Java version on the candidate Connect node:

java -version
ss -ltnp | grep ':8083\b' || echo "8083 free"
/opt/kafka/bin/kafka-topics.sh --bootstrap-server kafka:9092 --list \
  | grep -E '^(connect-configs|connect-offsets|connect-status)$' || echo "internal topics missing"
curl -fsSL https://packages.confluent.io/clients/maven/io/confluent/kafka-connect-jdbc/ 2>/dev/null \
  | head -c 200 || true

Connect needs its three internal topics (connect-configs, connect-offsets, connect-status) with replication factor matching your cluster — distributed mode auto-creates them if you grant the user the right ACLs.

What’s happening

Kafka Connect has two halves. The framework provides distributed execution, REST API, offset management, dead-letter queues, and metrics. The connector plugins are the format-specific code — JDBC, Debezium, S3, Elasticsearch, MongoDB, and dozens more. Each connector is a JAR (often many JARs) you drop into the Connect plugin path.

Source connectors pull data from an external system and produce to Kafka topics. Sink connectors consume from Kafka topics and write to an external system. A single Connect cluster can run many connectors, each with one or more tasks (a task is the unit of parallelism — for the JDBC source, typically one task per table; for the S3 sink, one task per N partitions).

Distributed mode means several Connect workers share the work; if a worker dies, its tasks are rebalanced onto the survivors. Standalone mode is single-process, stores state in a local file, and is fine for development only. We always deploy distributed mode in production, even on a single host — it makes adding capacity later a config change, not a rewrite.

Offsets and config live in Kafka topics, not on the Connect worker disk. This is what makes the cluster stateless from the worker’s perspective and is the property you want when a worker is replaced or scaled out.

The procedure

  1. Install Java 17 and the Kafka distribution on the Connect host. Connect ships with the Kafka tarball — no separate download:

    sudo apt install -y openjdk-17-jre-headless
    # Kafka tarball already in /opt/kafka — see kafka-install-ubuntu
    ls /opt/kafka/bin/connect-distributed.sh
  2. Create a plugin directory and drop connectors in:

    sudo mkdir -p /opt/kafka-connect/plugins
    cd /opt/kafka-connect/plugins
    # JDBC source/sink connector (Confluent Hub component, Apache 2.0)
    sudo curl -fsSL "https://packages.confluent.io/api/clients/maven/io/confluent/kafka-connect-jdbc/10.7.4/kafka-connect-jdbc-10.7.4.jar" -O
    # Postgres JDBC driver into the same directory
    sudo curl -fsSL "https://jdbc.postgresql.org/download/postgresql-42.7.3.jar" -O
    # S3 sink (Apache 2.0 build from upstream)
    sudo curl -fsSL "{/* TODO-VERIFY-DO2: pin to a current Confluent Hub or community S3 sink URL */}" -O 2>/dev/null || true
    sudo chown -R kafka:kafka /opt/kafka-connect
  3. Write the distributed worker config at /etc/kafka/connect-distributed.properties:

    bootstrap.servers=kafka-01.example.net:9092
    group.id=connect-cluster-1
    plugin.path=/opt/kafka-connect/plugins
    
    key.converter=org.apache.kafka.connect.json.JsonConverter
    key.converter.schemas.enable=false
    value.converter=org.apache.kafka.connect.json.JsonConverter
    value.converter.schemas.enable=false
    
    offset.storage.topic=connect-offsets
    offset.storage.replication.factor=3
    offset.storage.partitions=25
    
    config.storage.topic=connect-configs
    config.storage.replication.factor=3
    config.storage.partitions=1
    
    status.storage.topic=connect-status
    status.storage.replication.factor=3
    status.storage.partitions=5
    
    rest.advertised.host.name=connect-01.example.net
    rest.port=8083

    The replication factor of the internal topics must be <= the number of brokers; lower it to 1 in a single-broker dev environment.

  4. Write the systemd unit at /etc/systemd/system/kafka-connect.service:

    [Unit]
    Description=Kafka Connect (distributed)
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    Type=simple
    User=kafka
    Group=kafka
    Environment="KAFKA_HEAP_OPTS=-Xms1G -Xmx2G"
    Environment="LOG_DIR=/var/log/kafka-connect"
    ExecStart=/opt/kafka/bin/connect-distributed.sh /etc/kafka/connect-distributed.properties
    Restart=on-failure
    RestartSec=10s
    LimitNOFILE=65536
    
    [Install]
    WantedBy=multi-user.target
  5. Start and confirm the REST API answers:

    sudo systemctl daemon-reload
    sudo systemctl enable --now kafka-connect
    sleep 10
    curl -s http://localhost:8083/ | python3 -m json.tool
    curl -s http://localhost:8083/connector-plugins | python3 -m json.tool | head -40
  6. Deploy a JDBC source connector. POST the config to /connectors:

    curl -X POST -H "Content-Type: application/json" \
      http://localhost:8083/connectors -d '{
        "name": "orders-source",
        "config": {
          "connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
          "connection.url": "jdbc:postgresql://db.internal:5432/orders",
          "connection.user": "connect_reader",
          "connection.password": "REPLACE_ME",
          "mode": "timestamp+incrementing",
          "timestamp.column.name": "updated_at",
          "incrementing.column.name": "id",
          "table.whitelist": "public.orders,public.order_items",
          "topic.prefix": "db.orders.",
          "poll.interval.ms": 5000,
          "tasks.max": "2"
        }
      }'

    Two topics — db.orders.orders and db.orders.order_items — appear in Kafka. The connector tracks each table’s max updated_at and id in connect-offsets; on restart, it resumes from there with no duplicates as long as both columns advance monotonically.

  7. Deploy an S3 sink connector for the same topics:

    curl -X POST -H "Content-Type: application/json" \
      http://localhost:8083/connectors -d '{
        "name": "orders-s3-sink",
        "config": {
          "connector.class": "io.confluent.connect.s3.S3SinkConnector",
          "topics.regex": "db\\.orders\\..*",
          "s3.bucket.name": "orders-archive",
          "s3.region": "us-east-1",
          "flush.size": "10000",
          "rotate.interval.ms": "300000",
          "format.class": "io.confluent.connect.s3.format.json.JsonFormat",
          "storage.class": "io.confluent.connect.s3.storage.S3Storage",
          "partitioner.class": "io.confluent.connect.storage.partitioner.TimeBasedPartitioner",
          "partition.duration.ms": "3600000",
          "path.format": "yyyy/MM/dd/HH",
          "tasks.max": "3"
        }
      }'

    Files appear in S3 under topics/db.orders.orders/yyyy/MM/dd/HH/. The connector commits offsets to Kafka only after the S3 upload succeeds — exactly-once semantics within the partition.

  8. Check status and trigger restarts:

    curl -s http://localhost:8083/connectors/orders-source/status | python3 -m json.tool
    curl -s http://localhost:8083/connectors/orders-s3-sink/status | python3 -m json.tool
    
    # restart a failed task
    curl -X POST http://localhost:8083/connectors/orders-source/tasks/0/restart
    
    # pause a connector for maintenance
    curl -X PUT http://localhost:8083/connectors/orders-source/pause
    curl -X PUT http://localhost:8083/connectors/orders-source/resume

Operational notes

  • Plugin path conflicts are common — each connector’s directory should isolate its JARs from sibling connectors. Use one subdirectory per connector under plugin.path.
  • Connect’s internal topics (connect-configs especially) are compacted; a config delete via DELETE /connectors/<name> is final. Snapshot the configs nightly by GET /connectors?expand=info if you want history.
  • The REST API has no auth in the default config; bind it to localhost or front it with an auth proxy in production. Anyone reaching 8083 can deploy or delete connectors.
  • A poison message on a sink connector stops the task; configure errors.tolerance=all and errors.deadletterqueue.topic.name=<dlq> to route bad records to a DLQ topic instead of halting (see dead-letter queues).
  • Scaling out is “add another worker, give it the same group.id, point it at the same brokers” — tasks rebalance automatically on join.

Stack Harbor stands up Kafka Connect clusters as the integration layer for clients moving data between operational databases, object stores, and analytics warehouses — connectors under config management, REST API behind a VPN, status alerting wired to PagerDuty, and a DLQ topic per sink with a triage runbook. This is the work covered by our Managed Operations practice.