Source vs Sink Connectors in Kafka: The Two Doors Into and Out of Your Data Highway

Source vs Sink Connectors in Kafka: The Two Doors Into and Out of Your Data Highway

Kafka Connect moves data between Kafka and the rest of your world without custom code. Source connectors bring data in, sink connectors send data out. This guide explains how each one works, how they differ, and how to run them reliably.

Think of a big city with a central railway station. Trains arrive carrying passengers from suburbs, villages, and other cities, and other trains leave carrying passengers to all those same places. The station itself does not care where people come from or where they are going. It simply provides platforms, schedules, and rules so that everyone moves safely and on time. Now imagine that the station has two special kinds of staff: arrival crews who greet trains from outside and bring passengers onto the platforms, and departure crews who take passengers from the platforms and put them on outbound trains.

Apache Kafka is the central station of your data. Databases, applications, files, cloud services, and search engines all live outside it. Kafka Connect is the framework that provides the arrival and departure crews, and those crews are called source connectors and sink connectors. In this tutorial we will begin with the simplest ideas and build all the way up to production-level knowledge, in plain language, with analogies and diagrams along the way.

1Kafka Basics You Need First

A short refresher on the pieces that connectors rely on every day.

Apache Kafka is a platform for storing and moving streams of events. An event is a small record that describes something that happened, such as a new order, a changed customer address, or a temperature reading. Kafka keeps these events in an ordered, durable log so that many different applications can read them at their own pace.

Term 1

Topic

A named category of events, such as “orders”. Think of it as a labelled folder where related messages are kept in order.

Term 2

Partition

A topic is divided into partitions, and each partition is an ordered log. Partitions let Kafka spread work across many servers.

Term 3

Producer

An application that writes events into Kafka topics.

Term 4

Consumer

An application that reads events from Kafka topics and remembers its position using offsets.

Term 5

Offset

The position number of an event inside a partition. It is how a reader remembers where it stopped.

Term 6

Consumer Group

A team of consumers that share the partitions of a topic, so each event is handled by only one member of the team.

The problem of the outside world

Most of a company’s data does not start life inside Kafka. It lives in relational databases, log files, cloud storage, software-as-a-service tools, mainframes, and message queues. Likewise, the results that Kafka carries must eventually land in places such as data warehouses, search indexes, and dashboards. Something has to carry data across that border, in both directions, again and again, without losing anything.

Simple Analogy

Kafka is like a well-organised warehouse with its own internal conveyor belts. Inside the warehouse, everything moves smoothly. But goods must still be brought in from suppliers and shipped out to shops. Loading docks and shipping docks are where the warehouse meets the outside world, and connectors are those docks.

Two ways to build the docks

You could write your own producer application for every system that feeds Kafka, and your own consumer application for every system that Kafka feeds. Many teams start there, and many regret it. Each custom program needs its own retry logic, error handling, monitoring, scaling, and recovery after crashes. Kafka Connect exists so that this repeated work is done once, properly, and shared by everyone.

2What Is Kafka Connect?

A ready-made framework for moving data between Kafka and everything else.

Kafka Connect is a component that ships with Apache Kafka. It is a runtime that hosts small, reusable plugins called connectors. You do not write code to move data. Instead, you pick a suitable connector, describe your setup in a configuration, and give it to Kafka Connect, which then runs the job continuously, scales it, and recovers it after failures.

1

Pick a connector plugin

Choose a connector built for your system, such as one for a relational database, a file store, a search engine, or a cloud data warehouse.

2

Describe the job in configuration

Tell it where the data is, which topics to use, how to authenticate, and how many parallel workers to allow. This is done through simple structured settings, not programming.

3

Submit it to the Connect cluster

Connect exposes a REST interface where you create, inspect, pause, resume, and delete connectors.

4

Let the framework do the hard parts

Connect distributes the work, tracks progress, retries on failure, and continues from where it stopped after a restart.

The two directions

Every connector falls into one of two families, depending on which way the data flows relative to Kafka.

Direction: In

Source Connector

Reads data from an external system and writes it into Kafka topics. The outside world is the source, and Kafka is the destination.

Direction: Out

Sink Connector

Reads data from Kafka topics and writes it into an external system. Kafka is the origin, and the outside world is the destination, the “sink” where data settles.

flowchart LR
  DB[Relational Database] --> SRC[Source Connector]
  FILES[Log Files] --> SRC
  SRC --> K[Kafka Topics]
  K --> SNK[Sink Connector]
  SNK --> DW[Data Warehouse]
  SNK --> SE[Search Index]
  SNK --> OBJ[Object Storage]
        
FIG 1 — Source connectors feed Kafka, and sink connectors drain it
“A source connector is the way in, a sink connector is the way out, and Kafka sits in the middle.”
i
Easy Way to Remember

Always judge direction from Kafka’s point of view. If data is flowing into Kafka, the connector is a source. If data is flowing out of Kafka, the connector is a sink.

3The Building Blocks of Kafka Connect

Both connector families share the same set of moving parts. Learn these words once and everything else becomes easier.

Block 1

Connector

The named job you create. It holds the settings and decides how to divide the work, but it does not move data itself.

Block 2

Task

The worker unit that actually moves data. A connector can create several tasks to work in parallel.

Block 3

Worker

A running Connect process, which is like a server that hosts connectors and tasks. Several workers form a Connect cluster.

Block 4

Converter

Translates between the format Kafka stores, which is bytes, and the structured data inside Connect. Common formats are JSON, Avro, and Protobuf.

Block 5

Single Message Transform

A tiny step that modifies each record as it passes through, such as renaming a field, masking a value, or changing the topic name.

Block 6

Plugin

The installable package that contains connector code, converters, and transforms. Workers load plugins from a configured location.

Block 7

Dead Letter Queue

A special topic where sink connectors can park records that could not be processed, so one bad record does not stop everything.

Block 8

Schema Registry

An optional companion service that stores the structure of records so producers and consumers agree on the data format as it evolves.

Connector versus task

Beginners often mix these two up, so let us make the difference crisp. The connector is the manager. It reads the configuration, looks at the job, and decides how to split it into pieces. The tasks are the employees who do the pieces. If you ask a connector to copy twenty database tables and allow four tasks, the connector will assign about five tables to each task, and the four tasks will work in parallel.

Simple Analogy

A construction manager is the connector, and the builders on site are the tasks. The manager reads the blueprint and hands out sections of the building. The builders lay the bricks. Adding more builders speeds up the work, up to the point where the building simply cannot be divided into any more sections.

Where the settings for parallelism live

The connector setting named tasks.max sets the upper limit on how many tasks the connector may create. It is a ceiling, not a promise. The connector decides how many tasks it can actually use, and it may create fewer than the ceiling if the job cannot be split further.

!
Common Misconception

“If I set tasks.max to fifty, I will get fifty tasks.” Not necessarily. A source connector that reads a single table may only ever use one task, and a sink connector cannot usefully use more tasks than the total number of partitions it reads from.

4What Is a Source Connector?

The arrival crew: it goes out into the world, finds data, and brings it into Kafka.

A source connector continuously reads data from an external system and publishes it as records into Kafka topics. The external system might be a relational database, a set of files, a message queue, a software-as-a-service application, or even another Kafka cluster. The connector turns each row, line, message, or change into a Kafka record and appends it to the right topic.

A simple story

A retail company keeps its customer orders in a relational database. The analytics team, the shipping team, and the fraud team all want to react to new orders in real time, but nobody wants to hammer the production database with dozens of separate queries. So the company deploys a source connector for the database. The connector reads new and changed orders once and writes them to an “orders” topic in Kafka. Now every team simply reads the topic, and the database is touched only by the single connector.

sequenceDiagram
  participant EXT as External System
  participant TASK as Source Task
  participant CONN as Connect Framework
  participant KAFKA as Kafka Topic
  TASK->>EXT: Ask for new data since last position
  EXT-->>TASK: Rows or changes
  TASK->>CONN: Hand over records with position info
  CONN->>KAFKA: Write records to the topic
  KAFKA-->>CONN: Acknowledge the write
  CONN->>CONN: Save the source position
        
FIG 2 — How a source task moves data from an outside system into Kafka

What a source connector must remember

Because a source connector reads from a system that Kafka knows nothing about, it needs its own way to remember how far it has read. That bookmark is called a source offset. For a file it might be a byte position. For a database table it might be the highest row number or timestamp seen so far. For a database transaction log it might be a log position. Kafka Connect saves these bookmarks safely, so that after a crash the connector resumes from the last saved position instead of starting over or skipping data.

Simple Analogy

A postal worker collects letters from a large collection of letterboxes. To avoid collecting the same letter twice or skipping one, the worker keeps a notebook noting the last box collected and the time. If the worker falls ill, a replacement reads the notebook and continues exactly where the previous person stopped.

Examples of source connectors

Database change capture sources

Connectors that read the database’s transaction log, so every insert, update, and delete becomes a Kafka event in the exact order it happened. The best-known open-source family for this is Debezium.

Database polling sources

Connectors that repeatedly run queries against tables to find new or changed rows, using an ever-increasing id or a last-modified timestamp column.

File and object sources

Connectors that watch a directory or a storage bucket and turn new files, or new lines in files, into records.

Message system and API sources

Connectors that pull from other message brokers, from IoT gateways, or from web services, and republish the data into Kafka.

Kafka-to-Kafka replication sources

MirrorMaker 2, the tool for replicating topics between Kafka clusters, is itself built on Kafka Connect, and its source connectors read from a remote cluster and write into the local one.

5What Is a Sink Connector?

The departure crew: it takes records off Kafka and delivers them to their final destination.

A sink connector continuously reads records from one or more Kafka topics and writes them into an external system. That destination might be a relational database, a search engine, an object store such as a data lake, a cloud data warehouse, a caching system, or a web service that accepts data over HTTP.

A simple story

The same retail company wants its order data to be searchable on a customer support dashboard, and also stored cheaply for long-term analysis. It deploys two sink connectors that both read the “orders” topic. The first writes each order into a search index so support agents can find orders by name or product. The second writes batches of orders as files into cloud object storage, ready for reporting tools. The two connectors work independently, at their own speeds, and neither knows the other exists.

sequenceDiagram
  participant KAFKA as Kafka Topic
  participant CONN as Connect Framework
  participant TASK as Sink Task
  participant EXT as External System
  CONN->>KAFKA: Fetch a batch of records
  KAFKA-->>CONN: Records
  CONN->>TASK: Deliver records after conversion and transforms
  TASK->>EXT: Write the batch to the destination
  EXT-->>TASK: Confirm the write
  CONN->>KAFKA: Commit the offsets of the delivered records
        
FIG 3 — How a sink task moves data from Kafka into an outside system

What a sink connector must remember

Here is a key difference from source connectors. A sink connector does not need a private bookmark system, because Kafka already has one. Under the hood, each sink connector behaves like a consumer group, and it uses the normal Kafka consumer offsets to remember how far it has read. By default that group is named after the connector with a “connect-” prefix. This means all the familiar tools for checking consumer lag work on sink connectors too.

Simple Analogy

A delivery driver picks parcels from a warehouse shelf in order and drops them at customers’ homes. The shelf has numbered slots, and the driver’s clipboard records the last slot fully delivered. If the van breaks down, the next driver looks at the clipboard and continues from the next slot.

Examples of sink connectors

Relational database sinks

Write Kafka records into database tables, either by inserting new rows or by updating existing ones based on a key, so a table always mirrors the latest state.

Search engine sinks

Index each record as a document in a search system, so the data becomes instantly searchable.

Object storage and data lake sinks

Batch records into files, often partitioned by time, and store them in cloud storage in formats suitable for analytics.

Data warehouse sinks

Load records into cloud warehouses so analysts can query fresh data with ordinary SQL.

Cache, NoSQL, and HTTP sinks

Keep caches and document stores in sync with Kafka, or call web endpoints with the contents of each record.

6Source vs Sink: The Side-by-Side View

Now that each family is clear, here is a direct comparison of the differences that matter in practice.

AspectSource ConnectorSink Connector
Direction of dataExternal system into KafkaKafka into an external system
Role of KafkaDestinationOrigin
Behaves like aProducerConsumer group
How progress is rememberedConnector-specific source offsets stored by ConnectNormal Kafka consumer offsets
What limits parallelismHow the source can be split, such as tables or partitions of the sourceNumber of partitions in the subscribed topics
Where converters actConvert records into bytes before writing to KafkaConvert bytes from Kafka into structured records
Where transforms actBefore conversion, on the way into KafkaAfter conversion, on the way to the connector
Dead letter queue supportNot provided by the frameworkSupported for problem records
Typical trouble spotsMissed changes, duplicates, load on the source system, topic namingSlow destinations, bad records, duplicate writes, schema mismatches
How to measure being behindCompare source position with what has been publishedConsumer lag on the connector’s group
Who decides topic namesThe connector or its configurationYou choose which topics or patterns to subscribe to
flowchart TD
  subgraph SOURCE PATH
    A1[External data] --> A2[Source task]
    A2 --> A3[Transforms]
    A3 --> A4[Converter to bytes]
    A4 --> A5[Kafka topic]
  end
  subgraph SINK PATH
    B1[Kafka topic] --> B2[Converter from bytes]
    B2 --> B3[Transforms]
    B3 --> B4[Sink task]
    B4 --> B5[External destination]
  end
        
FIG 4 — The order of steps is a mirror image between source and sink
i
Mirror-Image Rule

The two pipelines are mirror images of each other. On the way in, transforms come before the converter. On the way out, the converter comes before the transforms. Remembering this saves a great deal of confusion when debugging why a transform sees the wrong shape of data.

7Inside a Source Connector

A closer look at how a source task finds data, labels it, and sends it to the right place.

The polling loop

Each source task runs a simple loop. It asks the external system for whatever is new, wraps the results into records, and gives them to the framework. The framework then sends them to Kafka through an internal producer, and only after Kafka acknowledges the records does it save the matching source offset. If the task waits too long between polls, the data feels stale, and if it polls too eagerly, it can overload the source system.

Source partitions and source offsets

Every record a source task produces carries two extra pieces of information for the framework’s own bookkeeping: a source partition, which identifies which slice of the source the record came from, and a source offset, which identifies the position within that slice. For a database connector, the source partition might be a table name, and the offset might be the last row identifier. Note that these are different from Kafka’s own partitions and offsets, even though the names sound alike.

Idea 1

Source Partition

A label for a part of the outside system, such as one table, one file, or one remote topic partition.

Idea 2

Source Offset

A bookmark inside that part, such as a row identifier, file position, or log sequence number.

Idea 3

Kafka Partition

Where the resulting record is stored in the Kafka topic. It may be chosen by the record key or explicitly by the connector.

Idea 4

Kafka Offset

The position of the record in the Kafka partition, assigned by Kafka itself after the write.

Where the bookmarks are kept

In distributed mode, Kafka Connect stores source offsets in a dedicated internal Kafka topic. In simple single-process setups it uses a local file. Because the bookmarks are in Kafka, they survive worker failures, and any worker in the cluster can take over a task and continue.

Choosing topics and keys

A source connector decides which topic each record goes to, often based on the name of the source table or file, sometimes with a configurable prefix. It also chooses a record key, commonly the primary key of a database row. Choosing a good key matters, because Kafka uses the key to decide the partition, and keeping all changes for the same row in the same partition preserves their order. Connect can also create topics automatically when a connector needs them, using default settings for partition count and replication that an administrator configures.

!
Common Mistake

Letting topics be auto-created with default settings, such as a single partition. A topic created this way can later become a bottleneck for consumers, because it limits how many can read in parallel. Decide partition counts and replication deliberately before turning a connector on.

Simple Analogy

A courier company collects parcels from many shops. Each parcel gets a label showing its shop and pickup time, which is the courier’s private tracking, and a delivery address on the warehouse side, which decides which shelf it lands on. The two labels serve different purposes and should never be confused.

8Inside a Sink Connector

A closer look at how a sink task receives records, writes them, and confirms progress.

The delivery loop

Behind every sink task is an ordinary Kafka consumer. It fetches a batch of records from the subscribed topics, and the framework converts and transforms them. The framework then hands the batch to the sink task, which writes them to the destination. Only after the task confirms that the data has been safely written does the framework commit the offsets. This order of “write first, commit after” is what prevents data from being lost.

Batching for speed

Most destinations are far more efficient when they receive many records at once than when they receive them one by one. A database can insert a thousand rows in one round trip, and an object store prefers large files over thousands of tiny ones. Sink connectors therefore collect records into batches, and settings such as the maximum number of records fetched per poll influence batch size. The best batch size is a balance between speed and how much data would need to be re-sent after a failure.

Backpressure and slow destinations

If the destination becomes slow, for example a database under heavy load, the sink task cannot keep up. The connector can ask the framework to pause fetching from Kafka until it has caught up. This is a healthy behaviour: Kafka stores the backlog safely, and the consumer lag grows visibly rather than data being dropped or memory exploding. Watching that lag is how operators notice a struggling destination.

Writing safely: inserts, upserts, and deletes

1

Insert mode

Each record becomes a new row or document. This is simple, but if a batch is retried after a failure, duplicates can appear.

2

Upsert mode

Each record is written using its key: if the key exists, the row is updated, otherwise it is inserted. Retrying the same record leaves the destination unchanged, which makes the write idempotent and safe.

3

Delete handling

A record with a key and an empty value, called a tombstone, can be interpreted as “delete this key”. Many sink connectors can be configured to remove the matching row or document when they see one.

i
Idempotence Is Your Friend

Whenever the destination allows it, prefer writes that give the same result no matter how many times they run. Upserts keyed by a stable identifier are the classic example, and they make the effects of retries and restarts harmless.

Simple Analogy

Writing a delivery address into an address book is safe to repeat: if the entry already exists, you just overwrite it with the same details. Adding a new page for every delivery, however, would fill the book with duplicates if you ever repeated a step.

9Converters and Transforms: The Middle of the Pipe

Between the outside world and Kafka’s bytes, two small stages shape every record.

Converters

Kafka itself stores only bytes and has no idea what they mean. Converters give the bytes meaning. A key converter and a value converter, both chosen in the configuration, decide the format used to serialise and deserialise the record’s key and value. Common choices are plain strings, JSON, and schema-based formats such as Avro and Protobuf, which are usually paired with a Schema Registry.

FormatStrengthsWeaknesses
StringSimplest, human readableNo structure or type checking
JSONReadable, widely supported, flexibleLarger messages, and structure can drift without notice
Avro with Schema RegistryCompact, enforced structure, controlled evolutionNeeds a registry service and schema discipline
Protobuf with Schema RegistryCompact, strongly typed, good cross-language supportNeeds a registry service and schema management
!
Common Mistake

Configuring a sink connector with a different converter than the one that produced the data. If the topic holds Avro and the sink expects plain JSON, records fail immediately. The converter must match the actual format of the bytes in the topic.

Single message transforms

A single message transform, often shortened to SMT, is a small piece of logic that changes one record at a time as it flows through the pipeline. Transforms can be chained, and each one runs in order. They are intended for light, simple adjustments, not heavy processing.

Use

Rename or drop fields

Reshape records so that field names suit the destination or to remove fields you do not want to expose.

Use

Mask sensitive values

Hide personal or secret data before it is stored in Kafka or written to a destination.

Use

Route to different topics

Change the topic name using a pattern, or add a date to it to spread data across time-based topics.

Use

Extract or set keys

Promote a field from the value into the key, so that records are partitioned and upserted correctly.

Use

Flatten nested data

Turn nested structures into flat fields so that tables and files with simple columns can accept them.

Use

Add metadata

Insert fields such as an ingestion timestamp or the name of the source.

i
Know the Limits

Transforms see one record at a time and cannot join, aggregate, or look at other records. Anything that needs such abilities belongs in a stream processing application such as Kafka Streams, not in Connect.

10Two Styles of Source: Polling vs Change Data Capture

For databases especially, there are two very different ways to bring data into Kafka.

Polling

A polling source runs queries at regular intervals to look for new or changed rows. It typically relies on an always-increasing identifier column, a last-modified timestamp column, or a combination of both, and it remembers the highest value seen. It is easy to set up because it needs nothing more than read access to tables.

Change data capture

A change data capture source, often called CDC, reads the database’s own transaction log, the internal journal that the database keeps to recover from crashes. Every insert, update, and delete appears there in exact order. The connector turns these log entries into events, usually with the before and after values of each row, and typically begins with an initial snapshot of the existing data.

QuestionPolling SourceChange Data Capture Source
Captures deletesUsually notYes
Captures every intermediate updateNo, only the state at poll timeYes, every change in order
Load on the databaseRepeated queries, can be heavy on big tablesLight, reads the log
LatencyDepends on the polling intervalNear real time
Setup effortLowHigher, needs database log settings and privileges
Needs special table columnsYes, an incrementing id or timestampNo
Best forSimple, small, append-mostly tablesAccurate replication and event-driven systems
flowchart LR
  subgraph POLLING
    T1[Database table] -->|repeated queries| P1[Polling source]
    P1 --> K1[Kafka topic]
  end
  subgraph CDC
    L1[Transaction log] -->|reads every change| C1[CDC source]
    C1 --> K2[Kafka topic]
  end
        
FIG 5 — Polling asks the table repeatedly, CDC follows the database’s own journal
Simple Analogy

Polling is like walking into a shop every hour and photographing the shelves to see what changed. You may miss items that were bought and restocked between visits, and you cannot tell what was removed. CDC is like reading the shop’s till receipts and stock ledger: every sale, restock, and return is written down, in order.

!
Polling Blind Spots

Timestamp-based polling misses updates if applications forget to update the timestamp column, and it can skip rows when many rows share the same timestamp at the poll boundary. It also cannot see deleted rows at all. If any of these matter, CDC is the safer choice.

11Destinations and Their Personalities

Every kind of sink has its own quirks, and knowing them prevents surprises.

Relational databases

Good at keeping the latest state through upserts. Watch out for connection limits, table locks, and schema changes. Use the record key as the primary key, and consider automatic table creation carefully in production.

Search engines

Excellent for fast text search. Documents are typically identified by the record key so that later updates replace earlier ones. Pay attention to how field types are mapped, since a wrongly guessed type is hard to change later.

Object storage and data lakes

Cheap and durable, and best with large files. Sink connectors buffer records and write a file when a size, record count, or time threshold is reached. Small thresholds create swarms of tiny files, which slow down analytics later.

Data warehouses

Great for analysis. Loads are usually done in batches for efficiency, and delivery is often near real time rather than instantaneous. Costs depend on how often and how much data is loaded.

Caches and key-value stores

Ideal for keeping fast lookups in sync with the newest state. Deletes and expiry need thought so that stale entries do not linger.

HTTP and web services

Flexible but fragile. Web services have rate limits and can be slow or temporarily unavailable, so retry behaviour, timeouts, and idempotency of the receiving endpoint become critical.

Across all of these, the golden question is the same: how does the destination behave if it receives the same record twice? Your answer to that decides how careful the rest of your design must be.

12Delivery Guarantees

What happens to your data when machines crash halfway through? This is where connectors earn their reputation.

Guarantee 1

At-most-once

Each record is delivered zero or one time. Data can be lost, but never duplicated. This is rarely acceptable for important data.

Guarantee 2

At-least-once

Each record is delivered one or more times. Nothing is lost, but duplicates are possible after failures. This is the usual default.

Guarantee 3

Exactly-once

Each record has its effect exactly one time. This is the ideal, and it requires cooperation from both the connector and the systems it touches.

Why duplicates can happen

Consider a sink task that has written a batch to a database but crashes just before committing the offsets to Kafka. When another worker takes over, it reads from the last committed offset and delivers the same batch again. The data was written twice. On the source side, a source task that has published records to Kafka but crashes before saving its source offset will re-read and re-publish the same data after restart.

sequenceDiagram
  participant KAFKA as Kafka
  participant TASK as Sink Task
  participant DB as Destination
  KAFKA->>TASK: Batch of records 100 to 199
  TASK->>DB: Write records 100 to 199
  DB-->>TASK: Write succeeded
  TASK--xTASK: Crash before offset commit
  KAFKA->>TASK: Same batch delivered again after restart
  TASK->>DB: Write records 100 to 199 again
        
FIG 6 — A crash between writing and committing causes a repeated delivery

Living with at-least-once

For most sink connectors, the practical answer is to make the destination tolerate repeats. Upserts by key, unique identifiers for documents, and file names derived from offsets all ensure that a repeated write replaces the earlier one instead of adding to it. When the write is idempotent, at-least-once delivery behaves like exactly-once from the outside.

Exactly-once for sources

Recent versions of Kafka Connect added framework support for exactly-once delivery from source connectors, in which the records and the source offsets are committed together in a Kafka transaction. It must be enabled at the worker level, and the specific connector must declare that it supports it. Not every connector does, so check its documentation before relying on it.

Exactly-once for sinks

Connect cannot make an external system transactional on its own. Some sink connectors achieve exactly-once effects by storing progress information together with the data inside the destination, or by writing files whose names are derived deterministically from the offsets, so that repeats overwrite identical files. This depends entirely on the individual connector and destination.

!
Do Not Assume

Never assume a connector is exactly-once because the platform sounds sophisticated. Read the connector’s documented guarantees, and test failure scenarios by killing workers in the middle of a busy run, then comparing counts at both ends.

13Tasks, Parallelism, and Scaling

How Kafka Connect spreads work across machines, and what really limits speed.

How work is distributed

In a Connect cluster, several workers share the tasks of all connectors. When you create a connector, the cluster spreads its tasks across the available workers. When a worker joins or leaves, the cluster rebalances and moves tasks to keep the load even. Modern Connect uses an incremental approach to rebalancing, so unaffected tasks keep running while only the necessary ones move.

flowchart TD
  C1[Connector A with 3 tasks] --> W1[Worker 1]
  C1 --> W2[Worker 2]
  C1 --> W3[Worker 3]
  C2[Connector B with 2 tasks] --> W1
  C2 --> W3
  W1 --> KC[Kafka Cluster]
  W2 --> KC
  W3 --> KC
        
FIG 7 — Tasks of different connectors are spread across the workers

What limits parallelism for sinks

A sink connector’s tasks are members of a consumer group, and in a consumer group each partition is read by only one member at a time. So the total number of partitions across the subscribed topics is the maximum number of tasks that can do useful work. If a topic has six partitions and you configure twelve tasks, six of them will sit idle.

What limits parallelism for sources

For sources, the limit depends on how the connector can slice the external system. A database connector might create one task per group of tables, so with a single big table only one task can work on it. A file connector might assign different files to different tasks. Change data capture connectors often use a single task per database, because the transaction log is a single ordered sequence that cannot safely be split.

Connector KindTypical Parallelism LimitWays to Go Faster
SinkTotal partitions of subscribed topicsAdd partitions, raise batch sizes, scale the destination
Polling database sourceNumber of tables or query slicesSplit large tables into ranges, tune polling and batch size
CDC sourceUsually one task per logReduce captured tables, tune snapshot and batch settings
File sourceNumber of files or directoriesSplit data into more files
i
Where the Real Bottleneck Often Is

Adding Connect workers rarely helps if the true limit is the external system. A sink writing into a small database is limited by that database, and a source pulling from a rate-limited web service is limited by that service. Always find the slowest part of the chain before scaling anything.

Simple Analogy

Adding more delivery vans does not help if there is only one loading door at the destination. The van count matters only until you reach the capacity of the narrowest point in the route.

14Error Handling and Dead Letter Queues

Real data is messy. A good pipeline decides in advance what to do with a record that cannot be processed.

What can go wrong

Failure 1

Conversion failure

The bytes do not match the expected format, for example malformed JSON or an unknown schema.

Failure 2

Transformation failure

A transform expects a field that is missing or of the wrong type.

Failure 3

Destination rejection

The database refuses a record because of a constraint violation, a too-long value, or a type mismatch.

Failure 4

Temporary outage

The destination or source is briefly unreachable, and a retry a moment later would succeed.

The choices the framework offers

By default, a connector is strict: the first bad record causes the task to fail, and it stops until someone investigates. This protects data quality but can halt an entire pipeline because of a single faulty message. Alternatively, you can configure the connector to tolerate errors, logging them and continuing. For sink connectors, you can additionally route failed records to a dead letter queue, which is an ordinary Kafka topic where problem records are stored together with headers that describe what went wrong.

1

Fail fast

Stop on the first error. Best for critical data where silent loss is unacceptable and someone is watching.

2

Tolerate and log

Skip bad records and write details to the logs. Convenient, but the skipped data is gone unless you have another copy, and Kafka’s retention will eventually delete it.

3

Tolerate and use a dead letter queue

Skip bad records, but keep them in a dedicated topic with error context so they can be inspected, fixed, and replayed later.

i
Errors Inside the Connector

The framework’s automatic handling covers conversion and transformation errors. Problems that occur inside a sink connector’s own write logic are handled by the connector itself. Well-built connectors can report individual bad records back to the framework so that they too can reach the dead letter queue. Check whether your chosen connector does this.

!
A Dead Letter Queue Is Not a Bin

A dead letter queue that nobody watches is just a slower way of losing data. Alert when records arrive in it, assign someone to review it, and decide how failed records will be fixed and replayed.

Sources have fewer safety nets

The dead letter queue feature belongs to sink connectors. For sources, problems such as unreadable rows or unsupported types must be handled by the connector’s own settings, by transforms that clean the data, or by fixing the source. Good monitoring of the source task’s status is therefore even more important.

15Real-World Use Cases

Sources and sinks usually work together as two halves of a bigger design.

Database to data lake

A CDC source streams changes from operational databases into Kafka, and a sink connector writes them as files into cloud object storage. Analysts get fresh data without running heavy queries on production databases.

Keeping a search index in sync

A source captures product catalogue changes from a database, and a sink indexes each change into a search engine, so shoppers always see current prices and stock.

The outbox pattern for reliable events

An application writes business changes and an “outbox” row in the same database transaction. A CDC source reads the outbox table and publishes events into Kafka, so events are sent if and only if the business change was committed, with no risky double write.

Cache invalidation and refresh

Changes flow from the system of record into Kafka, then a sink updates or evicts entries in a cache, keeping fast lookups consistent without application code.

Cross-cluster and cross-region replication

Source connectors built on Connect copy topics from one Kafka cluster to another for disaster recovery, data locality, or migration.

Log and telemetry ingestion

Sources pick up application logs or device readings into Kafka, and multiple sinks fan the data out to monitoring tools, search systems, and long-term storage.

Legacy modernisation

A source connector exposes data from an old system as events, letting new services consume it gradually, so the legacy system can be retired step by step.

flowchart LR
  APP[Application] --> DB[Operational Database]
  DB --> CDC[CDC Source Connector]
  CDC --> T[Kafka Topic]
  T --> S1[Sink to Search Index]
  T --> S2[Sink to Data Lake]
  T --> S3[Sink to Cache]
  T --> KS[Stream Processing Application]
        
FIG 8 — One source feeding several independent sinks and a stream processor

16Running Connect: Standalone and Distributed

How you deploy the workers changes how safe and scalable your connectors are.

Standalone Mode

  • Single process, very easy to start
  • Configuration comes from files at startup
  • Progress is stored in a local file
  • Good for learning, testing, and small one-off jobs

Limits of Standalone Mode

  • No automatic failover if the process dies
  • No horizontal scaling
  • Local state is lost if the machine is lost
  • Not recommended for production workloads

Distributed Mode

  • Many workers form one cluster
  • Tasks are redistributed automatically after failures
  • Configurations, offsets, and status are stored in Kafka topics
  • Managed through a REST interface, ideal for production

Costs of Distributed Mode

  • More moving parts to install and monitor
  • Internal topics need correct replication and permissions
  • Rebalances need to be understood and tuned
  • Plugins must be installed identically on every worker

The three internal topics

In distributed mode, Connect keeps its own state in three special Kafka topics. One stores connector configurations, so every worker knows which jobs exist. Another stores source offsets, the bookmarks of source connectors. The third stores status information such as which tasks are running or failed. These topics must be replicated properly, because losing them means losing the memory of the cluster.

!
Protect the Internal Topics

Treat the internal Connect topics like a database. Give them a healthy replication factor, prevent casual deletion, and restrict who can write to them. Deleting the offsets topic would make source connectors forget their progress and potentially re-read everything.

Rolling out changes

Configuration changes go through the REST interface. You can pause a connector to stop it without losing its position, resume it later, restart individual tasks that have failed, and update settings. Because plugins are loaded from disk at startup, upgrading a connector plugin usually means a rolling restart of the workers, one by one, to avoid downtime.

Simple Analogy

Standalone mode is one person running a market stall alone: fine for a day, but if they fall ill, the stall closes. Distributed mode is a team with a shared schedule board, where if one person leaves, the others pick up their tasks and the shop stays open.

17Security and Monitoring

Connectors hold the keys to your databases and your Kafka cluster, and they run unattended. Both facts demand care.

Security essentials

Practice 1

Protect credentials

Never put passwords in plain text in connector configurations. Use the externalised secrets mechanism so that configurations reference secrets kept in a proper store.

Practice 2

Least privilege for the external system

A source needs only read access, and a sink needs only write access to specific tables or indexes. Do not reuse administrator accounts.

Practice 3

Kafka access controls

Give connectors permission only to the topics they need, plus their internal topics and consumer groups.

Practice 4

Encrypt connections

Use encrypted, authenticated connections to Kafka and to every external system.

Practice 5

Secure the REST interface

Anyone who can reach it can create, change, or delete connectors, so restrict network access and require authentication.

Practice 6

Mask sensitive data

Use transforms to mask personal fields before they spread into topics and destinations.

What to monitor

SignalApplies ToWhat It Tells You
Connector and task statusBothWhether tasks are running, paused, or failed
Consumer lag of the connector’s groupSinkHow far the sink is behind the newest data
Record poll and write ratesSourceHow fast data is read from the source and published
Record read and send ratesSinkHow fast data is consumed and delivered
Batch processing timeSinkWhether the destination is slowing down
Offset commit successBothWhether progress is being saved reliably
Dead letter queue arrivalsSinkThe rate of bad records
Rebalance frequencyBothCluster stability
Source-side freshnessSourceWhether recent changes in the source have actually appeared in Kafka
i
Green Does Not Always Mean Healthy

A connector can show a healthy running status while doing nothing useful, for example a source that keeps polling an empty result, or a sink that is far behind. Always combine status checks with end-to-end freshness checks, such as comparing the newest timestamp at the source with the newest one at the destination.

18Design Patterns and Anti-Patterns

A handful of habits separate smooth Connect deployments from fragile ones.

Helpful patterns

Pattern 1

Capture once, fan out many

Use one source connector per system and many sinks, instead of many separate pipelines pulling from the same database.

Pattern 2

Idempotent sinks

Design destinations so that repeated writes are harmless, using stable keys and upserts.

Pattern 3

Schemas as contracts

Use a schema registry with compatibility rules so that upstream changes cannot silently break downstream sinks.

Pattern 4

Configuration as code

Keep connector configurations in version control and apply them through automation, so changes are reviewed and repeatable.

Anti-patterns to avoid

ANTI-PATTERN-01 Avoid
Problem

A team uses a timestamp-polling source on a business-critical table, assuming it captures every change including deletions.

Why It’s Harmful

Deleted rows never appear, updates that do not touch the timestamp are missed, and intermediate changes between polls are lost. The downstream copy drifts silently away from the truth.

Correct Approach

Use change data capture for tables where completeness and deletes matter, and reserve polling for simple, append-only data where its limits are acceptable.

ANTI-PATTERN-02 Avoid
Problem

A sink into a database uses plain insert mode with no keys, and the team assumes there will never be duplicates.

Why It’s Harmful

Any crash between write and offset commit replays a batch, creating duplicate rows that corrupt totals and reports, often unnoticed for weeks.

Correct Approach

Use upsert mode with the record key as the primary key, or otherwise ensure the write is idempotent.

ANTI-PATTERN-03 Avoid
Problem

Setting the task limit far above the number of topic partitions for a sink, hoping for faster delivery.

Why It’s Harmful

Extra tasks sit idle and consume resources, while the actual bottleneck, whether partitions or the destination, remains untouched.

Correct Approach

Match tasks to partitions, increase partitions if more parallelism is truly required, and check whether the destination can absorb more load.

ANTI-PATTERN-04 Avoid
Problem

Tolerating all errors with no dead letter queue and no alerting, just to keep the pipeline green.

Why It’s Harmful

Bad records vanish without a trace. By the time someone notices missing data, the original records may have aged out of Kafka’s retention.

Correct Approach

Route failures to a dead letter queue, alert on its volume, and keep a replay procedure ready.

ANTI-PATTERN-05 Avoid
Problem

Cramming business logic such as lookups, aggregations, or multi-step calculations into a long chain of transforms.

Why It’s Harmful

Transforms handle one record at a time and are hard to test and debug. Complex chains become fragile, slow, and impossible to reason about.

Correct Approach

Keep transforms simple. Do real processing in a stream processing application between two topics, with Connect handling only the movement of data.

ANTI-PATTERN-06 Avoid
Problem

Storing database passwords in plain text within connector configurations that are visible through the REST interface and stored in version control.

Why It’s Harmful

Anyone with access to the configuration, the interface, or the repository can read production credentials.

Correct Approach

Use externalised secrets so that configurations contain only references, and restrict access to the REST interface.

19Choosing Between Connect and Custom Code

Kafka Connect is powerful, but it is not always the right tool.

QuestionKafka ConnectCustom Producer or Consumer Application
Effort for common systemsLow, ready-made connectors existHigh, everything must be built and maintained
Scaling and recoveryBuilt inYou must build it
Offset and progress trackingHandled by the frameworkHandled by your code
Complex business logicLimited to simple transformsUnlimited
Unusual or proprietary systemsMay need a custom connectorDirect control
Operational consistencySame tools for every integrationEvery application is different

A useful rule of thumb: if the job is “move data between Kafka and a well-known system with little change”, use Connect. If the job is “compute something new from the data”, use a stream processing application, and let Connect handle the movement on either side. If your system is unusual and no connector exists, you can either write a custom connector using the Connect framework, which keeps the operational benefits, or write a standalone application when the logic is too specific.

i
The Three-Layer Picture

Many mature platforms use three layers: source connectors bring data in, stream processing applications enrich and compute, and sink connectors deliver the results. Each layer does what it is best at, and each can be scaled and replaced independently.

20A Troubleshooting Journey

Let us follow a realistic incident from first complaint to lasting fix.

A logistics company uses a CDC source connector to stream shipment changes into Kafka, and a sink connector that writes them into a reporting database. One morning, the operations team complains that the dashboard shows shipments that were cancelled yesterday as still active.

1

Check the connector status

Both connectors show as running, with all tasks healthy. So the problem is not an obvious crash, and the team must look further.

2

Measure freshness at each stage

Comparing the newest change in the source database, the newest record in the Kafka topic, and the newest row in the reporting database shows that Kafka is current, but the reporting database is missing recent changes. The sink is the suspect.

3

Look at the sink’s lag and dead letter queue

Consumer lag is small, but the dead letter queue contains many records. The sink has been skipping records because of an error tolerance setting.

4

Read the error details in the headers

The failed records are the cancellation updates. A recent release added a new value to the status field, and the destination table has a constraint that rejects the unfamiliar value.

5

Fix the cause and replay

The team updates the destination constraint to accept the new status, then replays the records from the dead letter queue into the original topic path, and confirms that dashboard counts match the source.

6

Prevent a repeat

They add an alert on dead letter queue volume, a schema compatibility check for status changes, and an end-to-end freshness monitor comparing source and destination.

The lesson is that a “green” connector status proves very little. The real evidence comes from comparing data at each stage of the pipeline, and from watching the places where problem records are parked.

21Frequently Asked Questions

Q1What is the simplest way to tell a source from a sink?

Look at the direction of data relative to Kafka. A source brings data into Kafka from an external system. A sink sends data out of Kafka into an external system.

Q2Is Kafka Connect a separate product from Kafka?

It is a component that ships with Apache Kafka, but it runs as its own set of processes called workers, separate from the Kafka brokers. It talks to Kafka through normal client connections.

Q3How does a source connector avoid re-reading the same data after a restart?

It stores source offsets, which are bookmarks about its position in the external system. Connect saves them in a Kafka topic in distributed mode, and on restart the connector resumes from the last saved position.

Q4How does a sink connector remember its position?

It uses ordinary Kafka consumer offsets. Each sink connector acts as a consumer group, so standard tools for viewing consumer lag apply to it.

Q5Can I have several sinks reading the same topic?

Yes. Each sink connector has its own consumer group and its own progress, so many sinks can read the same topic independently, each at its own speed.

Q6Why did my sink connector create fewer active tasks than I configured?

The task setting is only a maximum. The number of useful sink tasks cannot exceed the total partitions of the subscribed topics, and connectors may choose to create fewer tasks than the limit.

Q7Will I get duplicates?

Possibly, because the default delivery guarantee is at-least-once. A crash between writing data and saving progress leads to a repeated delivery. Idempotent writes such as upserts by key make duplicates harmless, and some connectors support exactly-once behaviour, which you must confirm individually.

Q8Are there dead letter queues for source connectors?

The framework’s dead letter queue feature is provided for sink connectors. For sources, you handle problems through connector settings, transforms, and monitoring of task status and the source data itself.

Q9What is the difference between CDC and polling sources?

Polling repeatedly queries tables for new or changed rows and cannot see deletes or intermediate changes. CDC reads the database’s transaction log, capturing every insert, update, and delete in order with low load and low delay.

Q10Where do transforms run relative to converters?

In a source pipeline, transforms run before the converter serialises records into Kafka. In a sink pipeline, the converter first deserialises the records, and then transforms run before the sink task receives them.

Q11Can I do joins or aggregations in Kafka Connect?

No. Transforms operate on one record at a time. Joins, aggregations, and windowing belong in a stream processing application, with Connect moving data in and out.

Q12What happens if a worker in the cluster dies?

In distributed mode, the remaining workers rebalance and take over the failed worker’s tasks, resuming from the saved offsets. In standalone mode, there is no failover, and the job stops until the process is restarted.

Q13How do I pause a connector without losing its place?

Use the REST interface to pause it. Its position is preserved, and when you resume it, work continues from where it stopped. For sinks, remember that lag grows during the pause and that Kafka’s retention must be long enough to keep the backlog.

Q14Should I let connectors create topics automatically?

It is convenient, but defaults may not suit your needs. In production, create important topics deliberately with the right partition counts and replication, or configure sensible defaults for automatic creation.

Q15When should I write a custom connector?

When no suitable connector exists for your system and you still want the framework’s scaling, recovery, and management benefits. If the logic is complex or highly specific, a standalone producer or consumer application may be simpler.

22Summary and Key Takeaways

Kafka Connect gives you a standard, scalable, and recoverable way to connect Kafka with the rest of your systems. Source connectors read from external systems and publish into Kafka, tracking their own bookmarks called source offsets. Sink connectors read from Kafka and write to external systems, using normal consumer offsets. Both run as tasks on workers, both use converters and transforms in mirrored order, and both must be designed with failure in mind.

The best results come from choosing the right style of source, such as change data capture for accurate database replication, designing sinks so that repeated writes are harmless, sizing parallelism according to real limits, and watching for silent failures with end-to-end freshness checks and dead letter queues. Keep transforms simple, keep secrets safe, and let stream processing applications do the heavy thinking between the two ends.

Key Takeaways

  • Direction defines the type — a source brings data into Kafka from outside, and a sink sends data from Kafka to the outside.
  • Connectors manage, tasks work — the connector splits the job, the tasks move the data, and workers host them; the task limit is only a ceiling.
  • Progress is tracked differently — sources keep connector-specific source offsets stored by Connect, while sinks use ordinary Kafka consumer offsets and consumer lag.
  • Pipelines mirror each other — on the way in, transforms come before the converter, and on the way out, the converter comes before the transforms.
  • Expect at-least-once, design for it — make sink writes idempotent with upserts, and verify any exactly-once claim for the specific connector and destination.
  • Choose CDC when completeness matters — polling misses deletes and intermediate changes, while log-based capture records every change in order.
  • Operate with care — use distributed mode in production, protect internal topics and secrets, watch lag and dead letter queues, and check freshness end to end rather than trusting a green status.