Well-designed topic naming conventions improve system organization, maintainability, and team productivity while preventing naming conflicts and confusion.
Importance of naming conventions
Good topic naming conventions provide multiple benefits:
- Organizational clarity: Instantly understand topic purpose and ownership
- Conflict prevention: Avoid naming collisions between teams and applications
- Operational efficiency: Easier monitoring, alerting, and troubleshooting
- Automation support: Enable automated tooling and deployment processes
- Scalability: Support growth from small to large organizations
Establish earlyDefine naming conventions before your first production deployment. Changing topic names later requires data migration and application updates.
Character restrictions and limitations
Kafka topic names have specific character and length restrictions.
Allowed characters
Topic names can contain:
- Lowercase letters (a-z)
- Uppercase letters (A-Z)
- Numbers (0-9)
- Periods (.)
- Underscores (_)
- Hyphens (-)
Restricted characters
Topic names cannot contain:
- Spaces ( )
- Forward slashes (/)
- Backslashes ()
- Commas (,)
- Control characters (ASCII 0-31)
- Characters above ASCII 127
Length limitations
- Maximum length: 255 characters
- Practical limit: Keep under 100 characters for readability
- Minimum length: 1 character (though not recommended)
Special restrictions
Reserved names to avoid:
- Names starting with double underscores (
__
) - reserved for internal topics
- Names containing only dots (
.
or ..
) - filesystem conflicts
- Case-sensitive duplicates - avoid
Topic
and topic
simultaneously
Examples:
# Valid topic names
user-events
order.processing.queue
CustomerData_v2
analytics-2024
# Invalid topic names
user events # Contains space
order/processing # Contains slash
__internal_topic # Reserved prefix
user,events # Contains comma
Basic naming patterns
Kebab case (recommended)
Use lowercase with hyphens for separators:
user-events
order-processing
payment-transactions
inventory-updates
Benefits:
- Easy to read and type
- Consistent with URL patterns
- Works well with command-line tools
Snake case
Use lowercase with underscores for separators:
user_events
order_processing
payment_transactions
inventory_updates
Benefits:
- Familiar to developers
- Compatible with variable naming
- Clear word separation
Dot notation
Use dots to create hierarchical names:
analytics.user.events
commerce.order.created
system.health.metrics
audit.security.events
Benefits:
- Creates natural hierarchy
- Supports grouping and filtering
- Good for enterprise organizations
Organizational naming strategies
Domain-based naming
Organize topics by business domain:
# User domain
users.registration
users.profile-updates
users.authentication
# Order domain
orders.created
orders.updated
orders.cancelled
# Payment domain
payments.processed
payments.failed
payments.refunded
Service-based naming
Organize topics by owning service:
# User service
user-service.events
user-service.commands
user-service.replies
# Order service
order-service.events
order-service.commands
order-service.replies
# Payment service
payment-service.events
payment-service.commands
payment-service.replies
Data type-based naming
Organize topics by data characteristics:
# Events (immutable facts)
events.user-registered
events.order-placed
events.payment-completed
# Commands (requests for action)
commands.process-payment
commands.update-inventory
commands.send-notification
# Snapshots (current state)
snapshots.user-profiles
snapshots.product-catalog
snapshots.inventory-levels
Environment-specific naming
Environment prefixes
Include environment in topic names:
# Development environment
dev.user-events
dev.order-processing
dev.analytics-events
# Staging environment
staging.user-events
staging.order-processing
staging.analytics-events
# Production environment
prod.user-events
prod.order-processing
prod.analytics-events
Environment suffixes
Place environment at the end:
# Different environments
user-events.dev
user-events.staging
user-events.prod
order-processing.dev
order-processing.staging
order-processing.prod
Cluster separation (recommended)
Use separate Kafka clusters for environments:
# Development cluster
user-events
order-processing
analytics-events
# Production cluster (same names, different cluster)
user-events
order-processing
analytics-events
Benefits:
- Complete environment isolation
- Simpler topic names
- No cross-environment data leakage risk
Versioning strategies
Version suffixes
Include version in topic names:
user-events-v1
user-events-v2
user-events-v3
order-schema-v1_0
order-schema-v1_1
order-schema-v2_0
Schema evolution (preferred)
Use schema registries for versioning instead of topic names:
# Topic names remain stable
user-events
order-events
payment-events
# Schema versions managed separately
# user-events: schema v1, v2, v3
# order-events: schema v1, v2
Benefits:
- Stable topic names
- Backward compatibility support
- Consumer flexibility in version handling
Team and ownership patterns
Team prefixes
Include team or department identifiers:
# Marketing team
marketing.campaign-events
marketing.user-segments
marketing.conversion-tracking
# Engineering team
engineering.deployment-events
engineering.error-logs
engineering.performance-metrics
# Data team
data.pipeline-status
data.quality-metrics
data.lineage-events
Application prefixes
Identify owning applications:
# E-commerce application
ecommerce.user-sessions
ecommerce.cart-events
ecommerce.checkout-flow
# Analytics platform
analytics.page-views
analytics.user-behavior
analytics.conversion-funnel
# Notification service
notifications.email-queue
notifications.sms-queue
notifications.push-notifications
Content and purpose indicators
Event type indicators
Specify the type of events:
# Domain events
events.user-registered
events.order-completed
events.payment-processed
# System events
system.server-started
system.connection-failed
system.backup-completed
# Business events
business.revenue-target-met
business.customer-milestone
business.campaign-launched
Data lifecycle indicators
Indicate data retention and lifecycle:
# Short-term data
temp.session-data
cache.user-preferences
short.click-streams
# Long-term data
archive.historical-orders
permanent.audit-logs
long.customer-profiles
# Real-time data
realtime.stock-prices
live.user-activity
streaming.sensor-data
Examples by use case
# User lifecycle
users.registered
users.profile-updated
users.account-deleted
# Product catalog
products.created
products.updated
products.discontinued
# Orders and checkout
orders.cart-created
orders.item-added
orders.checkout-started
orders.payment-completed
orders.order-fulfilled
# Analytics and tracking
analytics.page-viewed
analytics.product-clicked
analytics.conversion-tracked
Financial services
# Account management
accounts.opened
accounts.closed
accounts.balance-updated
# Transactions
transactions.initiated
transactions.authorized
transactions.settled
transactions.failed
# Risk and compliance
risk.fraud-detected
compliance.kyc-completed
audit.access-logged
# Market data
market.price-updated
market.trade-executed
market.order-book-changed
# Device management
devices.registered
devices.status-updated
devices.firmware-upgraded
# Sensor data by type
sensors.temperature
sensors.humidity
sensors.pressure
sensors.vibration
# Alerts and monitoring
alerts.threshold-exceeded
alerts.device-offline
alerts.battery-low
# Data processing
processed.hourly-aggregates
processed.daily-summaries
processed.anomaly-detection
Anti-patterns to avoid
Poor naming examples
Too generic:
data # What kind of data?
events # What events?
messages # What messages?
queue # What queue purpose?
Too long:
user-account-profile-management-service-events-for-customer-lifecycle-tracking
Inconsistent casing:
UserEvents # Mixed with user-events
ORDER_QUEUE # Mixed with order-queue
Payment.Events # Mixed with payment.events
Environment mixing:
prod-user-events-dev # Confusing environment indicators
staging.prod.orders # Contradictory environments
Version confusion:
user-events-old
user-events-new
user-events-latest
user-events-backup
Common mistakes
- No consistent pattern: Each team uses different conventions
- Too many hierarchies: Complex nested naming that’s hard to remember
- Abbreviations: Cryptic shorthand that’s not immediately clear
- Technical implementation details: Including partition counts or replication in names
- Temporary names: Using “temp” or “test” in production topic names
Implementation guidelines
Documentation
Document your naming convention:
# Topic Naming Convention
## Pattern
{domain}.{event-type}.{version}
## Examples
- users.registered.v1
- orders.completed.v1
- payments.failed.v2
## Environments
- Development: Use dev cluster
- Staging: Use staging cluster
- Production: Use prod cluster
## Ownership
- Format: {team-name}.{topic-name}
- Example: platform.user-events
Create tooling to validate topic names:
#!/bin/bash
# validate-topic-name.sh
TOPIC_NAME=$1
PATTERN="^[a-z][a-z0-9\-\.]*[a-z0-9]$"
if [[ $TOPIC_NAME =~ $PATTERN ]]; then
echo "Valid topic name: $TOPIC_NAME"
exit 0
else
echo "Invalid topic name: $TOPIC_NAME"
echo "Must match pattern: $PATTERN"
exit 1
fi
Automation integration
Integrate naming validation into CI/CD:
# Example GitLab CI
validate-topic-names:
script:
- find . -name "topics.yaml" -exec validate-topics.sh {} \;
rules:
- if: $CI_MERGE_REQUEST_ID
Migration strategy
For existing systems:
- Document current state: Inventory all existing topic names
- Define target convention: Establish new naming standards
- Create migration plan: Plan topic renames and data migration
- Gradual migration: Migrate topics incrementally
- Update applications: Modify producer and consumer applications
- Monitor transition: Ensure no data loss during migration
Best practices summary
Recommended approach
- Choose one pattern: Stick to kebab-case, snake_case, or dot.notation consistently
- Use meaningful names: Names should be self-documenting
- Include context: Domain, purpose, and data type should be clear
- Separate environments: Use different clusters rather than name prefixes
- Avoid versioning in names: Use schema registries for version management
- Keep reasonable length: Under 50 characters when possible
- Document conventions: Make naming rules explicit and accessible
- Validate consistently: Use tooling to enforce naming standards
Organization-specific considerations
Small teams (< 10 people):
# Simple pattern
user-events
order-events
payment-events
Medium teams (10-50 people):
# Add domain context
users.events
orders.events
payments.events
Large organizations (50+ people):
# Include team ownership
platform.users.events
commerce.orders.events
finance.payments.events
Migration complexityChanging topic names in production requires careful coordination. Plan naming conventions early and consider the migration cost when evaluating changes.
Start simple, evolve graduallyBegin with simple naming conventions and add complexity only as your organization grows. It’s easier to add structure than to remove it.