Common connectors (JDBC, S3, Elasticsearch) in Kafka - Time & Space Complexity
When Kafka connects to systems like JDBC databases, S3 storage, or Elasticsearch, it runs tasks to move data.
We want to know how the time taken grows as the data or requests increase.
Analyze the time complexity of this Kafka connector polling and processing loop.
while (true) {
records = pollFromSource();
for (record of records) {
processRecord(record);
sendToKafka(record);
}
commitOffsets();
}
This code polls data from a source like JDBC, S3, or Elasticsearch, processes each record, sends it to Kafka, and commits progress.
Look at what repeats as data grows.
- Primary operation: Loop over all records fetched in each poll.
- How many times: Once per record in the batch each poll cycle.
More records mean more processing steps.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 process and send steps |
| 100 | About 100 process and send steps |
| 1000 | About 1000 process and send steps |
Pattern observation: The work grows directly with the number of records.
Time Complexity: O(n)
This means the time to process grows in a straight line with the number of records.
[X] Wrong: "The connector time stays the same no matter how many records come in."
[OK] Correct: Each record needs processing, so more records mean more time.
Understanding how connectors scale with data size helps you design systems that handle growth smoothly.
What if the connector batches records differently, fetching larger chunks less often? How would the time complexity change?
Practice
Solution
Step 1: Understand JDBC connector role
JDBC connectors are designed to connect Kafka with relational databases using JDBC protocol.Step 2: Match purpose with options
To move data between Kafka and relational databases correctly states moving data between Kafka and databases, which is the JDBC connector's main use.Final Answer:
To move data between Kafka and relational databases -> Option DQuick Check:
JDBC connector = database integration [OK]
- Confusing JDBC with S3 or Elasticsearch connectors
- Thinking JDBC stores data in cloud storage
- Assuming JDBC is for search functionality
Solution
Step 1: Recall S3 connector config syntax
The standard property to specify the bucket iss3.bucket.name.Step 2: Compare options with standard property
Only s3.bucket.name matches the correct property name exactly.Final Answer:
s3.bucket.name -> Option AQuick Check:
Bucket name property = s3.bucket.name [OK]
- Swapping order of words in property name
- Using incorrect prefixes like 'bucket.s3'
- Missing the '.name' suffix
{
"connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
"topics": "orders",
"connection.url": "http://localhost:9200",
"type.name": "_doc",
"key.ignore": "false"
}What will happen when a message with key 'order123' and value '{"item":"book"}' is sent to topic 'orders'?
Solution
Step 1: Analyze key.ignore setting
Since "key.ignore" is set to "false", the connector uses the Kafka message key as the Elasticsearch document ID.Step 2: Understand indexing behavior
The message with key 'order123' will be indexed in Elasticsearch with that key as the document ID.Final Answer:
The document will be indexed in Elasticsearch with ID 'order123' -> Option CQuick Check:
key.ignore=false means use key as ID [OK]
- Assuming key is ignored by default
- Thinking connector fails without auth (not always true)
- Confusing Kafka storage with Elasticsearch indexing
Solution
Step 1: Check connectivity issues
If the JDBC URL is wrong or unreachable, the connector cannot read data from the database.Step 2: Evaluate other options
The Kafka topic name is missing in the connector config would cause errors but usually the connector won't start; The connector class is set to ElasticsearchSinkConnector is wrong connector type; The S3 bucket name is not specified is unrelated to JDBC source.Final Answer:
The JDBC URL is incorrect or unreachable -> Option BQuick Check:
Bad JDBC URL = no data import [OK]
- Confusing connector class for source vs sink
- Ignoring missing topic config errors
- Checking unrelated S3 settings for JDBC issues
Solution
Step 1: Understand connector roles
S3 sink connector archives data to cloud storage; Elasticsearch sink connector indexes data for search.Step 2: Choose correct architecture
Using both sink connectors on the same Kafka topic allows parallel archiving and search capabilities efficiently.Final Answer:
Use an S3 sink connector for archiving and an Elasticsearch sink connector for search, both consuming from the same Kafka topic -> Option AQuick Check:
Separate sinks for archive and search = best practice [OK]
- Trying to search data directly in S3 without indexing
- Using JDBC sink unnecessarily for this use case
- Confusing source and sink connector roles
Ready to prove it?
Pass the test and this pattern moves unknown
