Home / Data Platform / Streaming & CDC

Data PlatformChecklistBeginner

Kafka new topic production checklist: partitions, replication, retention, cleanup policy and ACLs

Before a new Kafka topic goes to production, settle partitions, replication, min.insync.replicas, retention, cleanup policy and ACLs. Commands to create it and to check it afterwards.

Deepak Bhardwaj7 min read

Applies toApache Kafka 3.x and 4.x (KRaft), Confluent Platform, Amazon MSK. Script names and some flags vary by distribution.

The goal

A team asks for a new topic "by this afternoon". Most of what you choose at creation time is either awkward to change later (partition count, cleanup policy) or turns into an incident when it is wrong (replication factor 1, retention too short, a missing ACL). Go through this list before running --create, then verify the topic with the commands at the end.

The examples use the Apache Kafka scripts (kafka-topics.sh, kafka-configs.sh, kafka-acls.sh). On Confluent Platform the same tools drop the .sh suffix. admin.properties holds the security settings for your admin client.

1. Requirements from the requesting team

  • Owner: a team and an on-call contact, recorded wherever you track topics.
  • Producers and consumers: service principals or users, and consumer group names.
  • Throughput: expected peak messages per second and average message size.
  • Ordering: does order matter, and per which key?
  • Retention: how far back must a consumer be able to replay? Is the topic a log of events (delete) or a latest-value table (compact)?
  • Largest message: anything above your broker's message.max.bytes needs a decision now.
  • Data classification: does it carry personal or regulated data? That affects ACLs, retention and whether it may be mirrored to another region.

2. Name

  • Follow your convention, for example <domain>.<dataset>.<version> such as orders.payment-events.v1.
  • Use either dots or underscores, not both. Kafka warns because . and _ collide in metric names, so orders.events and orders_events can't coexist cleanly.
  • Put a version in the name if the schema may ever change incompatibly. A new topic is the clean way to ship a breaking change.

Tip

Keep auto.create.topics.enable=false on production brokers. Otherwise a typo in a producer's topic name silently creates a topic with broker defaults, and the real topic gets no data.

3. Partitions

  • Size for consumer parallelism: a consumer group can't have more active consumers than the topic has partitions.
  • Size for throughput: measure what one partition sustains on your cluster with your message size, then divide peak throughput by that and add headroom.
  • If ordering matters per key, set the count you'll need for the next year or two now. Adding partitions later changes which partition a key hashes to, which breaks per-key ordering across the change and upsets compacted topics and Kafka Streams state.
  • Don't over-partition. Every partition costs open files, memory and controller metadata, and makes failover slower. Check your cluster's total partition count and your provider's guidance (for MSK, check the current per-broker limits for your instance size).

You can increase partitions later. You can't decrease them without creating a new topic.

4. Replication and durability

Setting Production value Why
Replication factor 3 Survives one broker loss while still allowing writes with min.insync.replicas=2
min.insync.replicas (topic) 2 With acks=all, a write needs two replicas, so one failure loses no data
unclean.leader.election.enable false Stops an out-of-sync replica becoming leader and discarding messages
Producer acks all Tell the producing team. acks=1 ignores min.insync.replicas
  • Replication factor isn't greater than the number of brokers, and with rack awareness (broker.rack) there are at least as many racks or AZs as replicas.
  • Producers that need no duplicates use enable.idempotence=true (the default in recent clients when settings don't conflict).

Warning

Replication factor 1 on a production topic means one disk failure loses data and one broker restart takes the partitions offline. Don't accept it "temporarily". It rarely gets fixed.

5. Retention and cleanup policy

  • cleanup.policy=delete for event streams. Set retention.ms from the replay requirement, not the broker default.
  • cleanup.policy=compact for latest-state-per-key topics (reference data, changelogs). Every message needs a non-null key. Consider min.compaction.lag.ms and delete.retention.ms (how long tombstones remain visible).
  • compact,delete if you need compaction with an upper age limit.
  • retention.bytes applies per partition, not per topic. Multiply by partitions × replication factor to get the disk impact.
  • Check the disk impact: peak bytes/sec × retention seconds × replication factor, spread across brokers. Confirm there's room for it.
  • If tiered storage is enabled on your cluster, decide whether this topic uses it (remote.storage.enable=true) and set local.retention.ms.

Caution

Too short a retention.ms deletes messages that consumers haven't read yet, with no error on the producer side. When in doubt, start longer and reduce it once consumer lag is understood.

6. Message size and format

  • max.message.bytes on the topic only if this topic needs more than the broker default. Producers (max.request.size) and consumers (max.partition.fetch.bytes) must match.
  • Schema registered in Schema Registry (if used) with the compatibility mode agreed with consumers.
  • compression.type: leave it as producer unless you want the broker to recompress.

7. Create the topic

kafka-topics.sh --bootstrap-server broker1:9092 --command-config admin.properties \
  --create --if-not-exists \
  --topic orders.payment-events.v1 \
  --partitions 12 \
  --replication-factor 3 \
  --config min.insync.replicas=2 \
  --config cleanup.policy=delete \
  --config retention.ms=604800000 \
  --config unclean.leader.election.enable=false

604800000 ms is 7 days. If your topics are managed as code (Terraform, Strimzi KafkaTopic resources, a GitOps repo), put the same values there instead. Don't create the topic by hand and let the tool drift.

8. ACLs

Grant least privilege per service. The --producer and --consumer shortcuts add the usual set of operations:

# Producer: Write, Describe and Create on the topic (plus idempotent write where required)
kafka-acls.sh --bootstrap-server broker1:9092 --command-config admin.properties \
  --add --allow-principal User:payments-svc \
  --producer --topic orders.payment-events.v1

# Consumer: Read and Describe on the topic, Read on the group
kafka-acls.sh --bootstrap-server broker1:9092 --command-config admin.properties \
  --add --allow-principal User:ledger-svc \
  --consumer --topic orders.payment-events.v1 --group ledger-consumer

# Review
kafka-acls.sh --bootstrap-server broker1:9092 --command-config admin.properties \
  --list --topic orders.payment-events.v1
  • No wildcard (--topic '*') grants for application principals.
  • Transactional producers also need ACLs on their transactional.id (--transactional-id).
  • On MSK with IAM auth or Confluent Cloud, use the provider's IAM policies or role bindings instead of kafka-acls.sh.

9. Verify before you hand it over

# Partitions, leaders, replicas and ISR
kafka-topics.sh --bootstrap-server broker1:9092 --command-config admin.properties \
  --describe --topic orders.payment-events.v1

# Effective config, including defaults inherited from the broker
kafka-configs.sh --bootstrap-server broker1:9092 --command-config admin.properties \
  --entity-type topics --entity-name orders.payment-events.v1 --describe --all

# Nothing under-replicated or below min ISR
kafka-topics.sh --bootstrap-server broker1:9092 --command-config admin.properties \
  --describe --under-replicated-partitions --topic orders.payment-events.v1
kafka-topics.sh --bootstrap-server broker1:9092 --command-config admin.properties \
  --describe --under-min-isr-partitions --topic orders.payment-events.v1
  • Leaders are spread across brokers, and every partition has 3 replicas in ISR.
  • --describe --all shows the retention and min.insync.replicas you meant, not broker defaults.
  • A smoke test using the application's credentials, not admin, produces and consumes one message. Console tool flags for client config vary by version (--producer.config / --consumer.config, or --command-config in newer releases). Check --help on your build.

10. Operational hooks

  • Consumer lag alert for each consumer group (Burrow, Prometheus kafka_consumergroup_lag-style exporters, CloudWatch for MSK, or Confluent metrics).
  • Disk usage alert on brokers covers the added retention.
  • If the topic is in DR scope, add it to the MirrorMaker 2 or replication config.
  • Topic, owner, retention and classification recorded in the catalog or topic registry.

Prevent it next time

  • Turn this list into a request template, so teams provide throughput, ordering key and retention before they ask.
  • Manage topics and ACLs as code with review, and run a weekly diff between the repo and kafka-topics.sh --describe output to catch hand-made changes.
  • Set safe broker defaults (default.replication.factor=3, min.insync.replicas=2, auto.create.topics.enable=false) so a topic someone forgets to configure still isn't dangerous.