Kafka Streams
Source Topic
Data Streaming
Error Troubleshooting
Apache Kafka

Kafka Streams - missing source topic

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

A Kafka Streams application depends on its input topics being present and readable before useful work can begin. When a source topic is missing, the failure is usually not in the topology code itself, but in cluster configuration, startup order, or topic provisioning.

Core Sections

What “missing source topic” usually means

Kafka Streams builds a topology from one or more input topics. At startup, the client metadata lookup must find those topics and confirm the application is allowed to read them. If the topic does not exist, is misspelled, or is hidden by the wrong cluster configuration, the stream threads cannot initialize normally.

Typical causes include:

  • the topic was never created
  • the application is pointed at the wrong bootstrap servers
  • the topic name in code does not match the deployed name
  • access control lists block metadata or read access
  • infrastructure creates topics after the Streams application already starts

A minimal topology looks harmless, but it still depends on external Kafka state.

java
1StreamsBuilder builder = new StreamsBuilder();
2builder.stream("orders")
3       .mapValues(value -> value.trim())
4       .to("orders-cleaned");

If orders is missing, the application cannot consume records regardless of how simple the transformation is.

Create or verify topics before streams.start()

The reliable fix is to provision required topics ahead of time. In development, teams sometimes rely on broker auto-creation, but that often creates the wrong partition count and replication factor. Production systems should be explicit.

Use the Admin API to verify required topics before starting Kafka Streams.

java
1import java.util.List;
2import java.util.Properties;
3import java.util.Set;
4import java.util.HashSet;
5import org.apache.kafka.clients.admin.Admin;
6import org.apache.kafka.clients.admin.AdminClientConfig;
7import org.apache.kafka.clients.admin.ListTopicsResult;
8
9public class TopicCheck {
10    public static void verifyTopics(String bootstrapServers, List<String> requiredTopics) throws Exception {
11        Properties props = new Properties();
12        props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
13
14        try (Admin admin = Admin.create(props)) {
15            ListTopicsResult result = admin.listTopics();
16            Set<String> existing = result.names().get();
17            Set<String> missing = new HashSet<>(requiredTopics);
18            missing.removeAll(existing);
19
20            if (!missing.isEmpty()) {
21                throw new IllegalStateException("Missing source topics: " + missing);
22            }
23        }
24    }
25}

This fails early with a clear message instead of leaving the application in an ambiguous state.

Provision topics with the right configuration

If the topic is legitimately absent, create it before starting the Streams process. Doing this in infrastructure code is better than creating topics ad hoc from the app, because partition count and retention are operational decisions.

java
1import java.util.Collections;
2import java.util.Properties;
3import org.apache.kafka.clients.admin.Admin;
4import org.apache.kafka.clients.admin.AdminClientConfig;
5import org.apache.kafka.clients.admin.NewTopic;
6
7public class TopicProvisioner {
8    public static void createOrdersTopic(String bootstrapServers) throws Exception {
9        Properties props = new Properties();
10        props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
11
12        try (Admin admin = Admin.create(props)) {
13            NewTopic topic = new NewTopic("orders", 6, (short) 3);
14            admin.createTopics(Collections.singleton(topic)).all().get();
15        }
16    }
17}

Six partitions and replication factor three may or may not be right for your workload, but the example shows the important point: creation should be deliberate.

Check startup order and environment wiring

A missing topic error often means the application started before infrastructure finished. This is common in local Docker setups and Kubernetes deployments. One container starts Streams immediately while another job or Terraform apply creates the topics later.

A practical startup sequence is:

  1. create the broker or connect to the target cluster
  2. provision topics and access control lists
  3. verify metadata from the same network path the application uses
  4. start Kafka Streams

If you use Kubernetes, readiness should reflect topic availability, not just JVM startup. If you use CI, add an integration step that confirms the required topics exist before deploying the consumer.

Add visibility around the failure

Logging the exact topic names and cluster target matters. Many “missing topic” incidents are actually environment mismatches. The code points to staging, while the topic exists only in development.

java
1Properties props = new Properties();
2props.put(StreamsConfig.APPLICATION_ID_CONFIG, "orders-streams");
3props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka-1:9092");
4
5System.out.println("Starting Streams with topics: orders, orders-cleaned");
6System.out.println("Bootstrap servers: " + props.getProperty(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG));

That log line is basic, but it shortens incident response because operators can compare the application configuration to the broker they expect.

Do not confuse source topics with internal topics

Kafka Streams also creates internal changelog and repartition topics when needed. Those are separate from user-managed input topics. If your logs mention an internal topic, the remediation may be different. Missing source topics are about your declared inputs. Internal topic problems often point to permissions or broker health.

Keep those categories separate while debugging or you will fix the wrong layer.

Common Pitfalls

  • Relying on broker auto-topic creation, which can hide the problem in development and produce incorrect partitioning in production.
  • Creating the topic after the Streams application starts, which causes startup failures or repeated retries that look like code bugs.
  • Debugging only the topology and ignoring cluster configuration, bootstrap server mismatches, or access control lists.
  • Misspelling topic names or changing names in infrastructure without updating the application constants that reference them.
  • Confusing missing user source topics with failures involving internal changelog or repartition topics, which usually need a different fix.

Summary

  • A missing source topic is usually an environment or provisioning problem, not a Streams API problem.
  • Verify required topics explicitly before calling streams.start().
  • Provision topics with deliberate partition and replication settings rather than relying on defaults.
  • Check startup order, access control, and cluster targeting when the error appears.
  • Separate source-topic failures from internal-topic failures so debugging stays focused.

Course illustration
Course illustration

All Rights Reserved.