Kafka Topic Naming Convention Template
Template for standardizing Kafka topic names across teams: naming pattern, environment prefixes, event suffixes, partition and retention rules.
Overview
This template defines naming conventions for Kafka topics across an organization. Consistent naming makes topics discoverable, stops teams from colliding on names, simplifies ACL management, and pays off every time you’re monitoring or debugging production. Adopt it as-is or adapt the rules — what matters isn’t the exact pattern but that everyone uses the same one.
1. Naming Pattern
1.1 Standard Format
<environment>.<domain>.<entity>.<event-type>[.<version>]
Components:
environment — dev, staging, prod (required)
domain — business domain (required)
entity — entity or aggregate root (required)
event-type — event, command, snapshot, dlq (required)
version — v1, v2, v3 (optional, for schema evolution)
1.2 Examples
Once you’ve seen a handful of real names, the pattern reads itself — you know the environment, the domain, and what happened before you ever open the topic:
```text
prod.orders.order-created.v1
prod.orders.order-cancelled.v1
prod.payments.payment-processed.v1
prod.users.user-signed-up.v1
prod.inventory.stock-updated.v1
staging.orders.order-created.v1
dev.users.user-signed-up.v2
# Dead letter queues
prod.orders.order-created.dlq
# Compact topics (snapshots)
prod.users.user-profile.snapshot
prod.inventory.product-catalog.snapshot
1.3 Rules
- Use lowercase only
- Use hyphens (
-) to separate words within a component - Use dots (
.) to separate components - Maximum 249 characters (Kafka limit)
- No spaces, no
_, no other special characters - Start with environment, end with event-type or version
2. Environment Prefixes
2.1 Standard Environments
Prefix | Environment | Purpose
───────────┼─────────────┼──────────────────────────────
dev | Development | Local dev, feature branches
staging | Staging | Pre-production testing
prod | Production | Live traffic
sandbox | Sandbox | Experimentation, demos
2.2 Rules
Environment prefixes do double duty: they tell anyone reading the name where the data lives, and they map cleanly onto cluster boundaries. Keep them strict — a prod. prefix means prod, not “the topic that should eventually go to prod.”
- Every topic MUST start with an environment prefix
- No cross-environment topic sharing (use MirrorMaker for replication)
- Environment prefixes align with Kafka cluster boundaries
- Dev topics have shorter retention (24h) to save resources
3. Domain Segmentation
Domains are how the convention stays flat but organized — instead of teams inventing their own prefixes, everything hangs off a short, reviewed list. Eight to twelve domains covers most organizations; if you need thirty, your domains are probably entities.
3.1 Domain List
Domain | Description | Example entities
───────────────┼──────────────────────────┼──────────────────────
orders | Order management | order, cart, checkout
payments | Payment processing | payment, refund, invoice
users | User identity | user, profile, session
inventory | Product catalog | product, stock, sku
shipping | Fulfillment | shipment, delivery, tracking
notifications | Messaging and alerts | email, sms, push
analytics | Event analytics | click, view, conversion
audit | Compliance audit trail | action, change, access
3.2 Adding New Domains
1. Propose domain name in architecture review
2. Verify no collision with existing domains
3. Document domain ownership (team, on-call)
4. Add to domain registry (Confluence or wiki)
5. Create ACL templates for the new domain
6. Announce to #kafka-governance channel
4. Event Type Suffixes
4.1 Standard Suffixes
Suffix | Meaning | Retention | Compaction
────────────┼──────────────────────┼──────────────┼───────────
event | Domain event (fact) | 7-30 days | No
command | Command (intent) | 3-7 days | No
snapshot | Current state | Indefinite | Yes (compact)
dlq | Dead letter queue | 7 days | No
audit | Audit trail | 365 days | No
metric | Operational metric | 3 days | No
4.2 Event vs Command
The distinction matters for consumers: an event can be replayed safely and cached; a command is a request that someone must act on — and it might be refused. Mixing them under one suffix confuses both producer intent and consumer expectations.
```text
# Event — something that HAS happened (past tense, immutable)
prod.orders.order-created.v1
prod.payments.payment-processed.v1
# Command — something you WANT to happen (imperative, may fail)
prod.orders.cancel-order.v1
prod.payments.process-refund.v1
5. Partition Count
5.1 Sizing Guidelines
Expected throughput (msg/s) | Partitions | Notes
────────────────────────────┼────────────┼────────────────────────
< 100 | 1 | Single partition is fine
100 - 1,000 | 3 | Allow parallel consumers
1,000 - 10,000 | 6 | Multiple consumer groups
10,000 - 100,000 | 12 | High throughput
> 100,000 | 24+ | Consult platform team
5.2 Rules
Partition count is the one Kafka decision you can’t take back — shrinking requires a whole new topic, so teams that “start big just in case” end up paying broker overhead forever.
- Start with fewer partitions (can only increase, never decrease)
- Partition count should match consumer parallelism needs
- Each partition adds overhead to the broker (more partitions = more files)
- Maximum 100 partitions per topic without platform team approval
- Replication factor: 3 for prod, 2 for staging, 1 for dev
6. Retention Policies
Retention is where naming meets money — an audit. suffix tells you storage is a requirement, not a habit, while metric. says the data is cheap to regenerate and safe to drop fast. Get these defaults wrong and you’re either deleting data someone needed or paying to keep data nobody reads.
6.1 Standard Retention
Topic type | Retention | Size limit | Compaction
─────────────────┼───────────────┼──────────────┼───────────
event | 7 days | 1 GB | No
command | 3 days | 500 MB | No
snapshot | Infinite | No limit | Yes (compact)
dlq | 7 days | 500 MB | No
audit | 365 days | 10 GB | No
metric | 3 days | 500 MB | No
Note: retention.bytes applies per partition, not per topic —
a 12-partition topic with retention.bytes=1GB can hold up to ~12GB.
Dev topics: shorten retention.ms to 86400000 (24h) to save resources.
6.2 Custom Retention
# Set retention for a topic (modern --topic flag; --entity-type is deprecated)
kafka-configs.sh --bootstrap-server localhost:9092 \
--topic prod.orders.order-created.v1 \
--alter \
--add-config retention.ms=604800000,retention.bytes=1073741824
# Set compaction for snapshot topics
kafka-configs.sh --bootstrap-server localhost:9092 \
--topic prod.users.user-profile.snapshot \
--alter \
--add-config cleanup.policy=compact,delete.retention.ms=86400000
7. Access Control
7.1 ACL Patterns
# Producer ACL — only producing team can write
kafka-acls.sh --bootstrap-server localhost:9092 \
--add --allow-principal User:CN=orders-service \
--producer --topic "prod.orders.order-created.v1"
# Consumer ACL — consuming team can read
kafka-acls.sh --bootstrap-server localhost:9092 \
--add --allow-principal User:CN=analytics-service \
--consumer --topic "prod.orders.order-created.v1" \
--group "analytics-consumer-group"
# Prefixed ACL for a domain (all topics under prod.orders.)
kafka-acls.sh --bootstrap-server localhost:9092 \
--add --allow-principal User:CN=orders-service \
--producer --topic "prod.orders." \
--resource-pattern-type prefixed
7.2 Rules
ACLs are where the naming convention pays for itself: a prod.orders. prefix means one prefixed ACL grants the orders team access to its whole domain instead of an ACL per topic.
- Only the owning team has producer ACLs
- Consumer ACLs are granted per consumer group
- No cluster-wide wildcard ACLs in production
- Review ACLs quarterly
- Use Kafka User ACLs, not IP-based rules
8. Topic Creation Process
8.1 Request Workflow
Manual kafka-topics.sh creation is how conventions die — one engineer runs it from their laptop and suddenly there’s an OrdersCreated_Final_v2 in prod. Route every topic through a ticket plus infrastructure-as-code instead:
1. Submit topic request ticket with:
- Topic name (following convention)
- Expected throughput (msg/s)
- Expected message size (KB)
- Retention requirements
- Partition count (with justification)
- Owning team
- Consumer teams
2. Platform team reviews request
3. Topic created via Terraform/Ansible (not manual)
4. ACLs applied
5. Topic registered in catalog
6. Requester notified
8.2 Terraform Example
A kafka_topic resource makes the convention enforceable — the name is right there in code review next to the partitions and retention it ships with. Any Kafka provider works; the config map is what carries the convention’s defaults.
resource "kafka_topic" "order_created" {
name = "prod.orders.order-created.v1"
replication_factor = 3
partitions = 6
config = {
"retention.ms" = "604800000" # 7 days
"retention.bytes" = "1073741824" # 1 GB
"cleanup.policy" = "delete"
"compression.type" = "snappy"
"max.message.bytes" = "1048576" # 1 MB
}
}
9. Monitoring
Naming conventions show their worth here — prod.* lag alerts tell you instantly which environment is hurting, and domain segments let you page the right team instead of a generic “someone owns this topic” rotation.
9.1 Key Metrics
Metric | Alert threshold | Description
──────────────────────────┼────────────────────────┼──────────────────────
Under-replicated partitions| > 0 for 5 min | Broker health issue
Consumer lag | > 10,000 messages | Consumer can't keep up
Bytes in/out per second | > 80% of capacity | Throughput saturation
Partition count per broker| > 4,000 | Broker overload risk
Offline partitions | > 0 | Critical — data unavailable
Watch the ones that page people, not the ones that fill dashboards. Under-replicated and offline partitions mean you’re losing durability right now; lag and throughput thresholds tell you it’ll hurt soon.
9.2 Grafana Dashboard Queries
# Consumer lag by topic
sum by (topic) (
rate(kafka_consumergroup_lag_sum[5m])
)
# Bytes in per topic
sum by (topic) (
rate(kafka_topic_bytes_in_per_sec[5m])
)
# Under-replicated partitions
sum by (broker) (
kafka_cluster_under_replicated_partition
)
See Also
- Apache Kafka documentation — topic configurations
- Confluent: Kafka cluster and topic sizing guidance
- Complete Guide to Kafka Stream Processing
- Complete Guide to Apache Kafka in Production
- Message Queues — RabbitMQ, Kafka, and SQS detailed analysis
- Idempotent Consumer Pattern
- Sequential Convoy Pattern
- Companion files (lint script + Terraform):
resources/docs/messaging/kafka-topic-naming-convention-template
Frequently Asked Questions
What if I need to rename a topic?
There's no rename operation in Kafka — topics are immutable once created. The real migration path is: create the correctly named topic, dual-produce to old and new while consumers move over, then decommission the original. Plan for a 2-4 week window; it looks quick on a whiteboard and isn't. Use MirrorMaker 2 if you need cross-cluster replication while it runs.
How do I version topics when the schema changes?
For backward-compatible schema changes (adding optional fields), keep the same topic name and update the schema in the schema registry. For breaking changes (removing fields, changing types), create a new topic with an incremented version suffix (e.g., v1 to v2). Dual-produce during migration, switch consumers gradually, then decommission the old topic.
Can I use a single topic for multiple event types?
Avoid it. One event type per topic keeps consumers simple, retention independent, and dashboards readable. If you're forced to share a topic, carry the type in a header or payload field and write it down somewhere people will actually find it.
How many partitions should I start with?
Start with the minimum that meets your consumer parallelism needs — you can always add partitions later, but you can't remove them, and adding them breaks key-based ordering for existing keys. Three to six partitions covers most topics; for high-throughput ones (> 10K msg/s), start at 12.
What retention should I set for replay-able topics?
For topics that consumers may need to replay (e.g., for bug fixes or new consumers), set retention to 7-30 days. For snapshot topics with compaction, retention is infinite since compaction keeps only the latest value per key. For audit topics, set retention to 365 days or use Kafka's log compaction with delete to keep only recent records.
Related Resources
RabbitMQ Queue Design Template
Template for documenting RabbitMQ queue, exchange, and binding design: exchange types, queue properties, binding rules, dead letter handling, TTL policies, and capacity planning with code examples.
DocMessage Schema Evolution Policy (Avro, Protobuf, JSON)
A reusable policy for evolving message schemas safely in event-driven systems: compatibility rules, schema registry requirements, versioning, breaking change procedure, migration checklist, and CI enforcement with Avro, Protobuf, and JSON Schema examples.
DocDead Letter Queue Runbook
Operational runbook for triaging, fixing, and replaying dead letter queue messages in Kafka and RabbitMQ, with inspection commands, root cause analysis, and alert rules.
RecipeEvent Streaming with Apache Kafka and Node.js
Build event-driven microservices with Apache Kafka: typed producers, consumer groups, manual offsets, dead-letter handling, and real exactly-once semantics with KafkaJS
RecipeKafka Consumer Groups with Python for Scalable Streaming
Create Kafka consumer groups in Python with partition assignment, offset management, rebalance handling, and exactly-once semantics using confluent-kafka.