Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Kafka Operations

Operational procedures for managing Apache Kafka clusters in production environments.


Kafka operations encompass cluster management, monitoring, performance optimization, and maintenance activities required to run Kafka reliably at scale.

Kafka OperationsCluster ManagementMonitoringPerformanceMaintenanceSecurityBackup/DRhealth checksmetrics analysistuningchangesaccess controlrecovery
CategoryActivities
Cluster ManagementBroker lifecycle, partition management, configuration
MonitoringMetrics collection, alerting, dashboards
PerformanceTuning, capacity planning, benchmarking
MaintenanceUpgrades, rolling restarts, log management
SecurityAuthentication, authorization, encryption
Backup/DRReplication, disaster recovery, data migration

OperationCommand/Procedure
Start brokerkafka-server-start.sh config/server.properties
Stop brokerkafka-server-stop.sh or graceful shutdown
Check broker statuskafka-broker-api-versions.sh --bootstrap-server host:9092
List brokerskafka-metadata.sh --snapshot /path/to/metadata --command "brokers" (KRaft)
  1. Configure new broker with unique broker.id
  2. Start broker—it joins cluster automatically
  3. Reassign partitions to include new broker:
Terminal window
# Generate reassignment plan
kafka-reassign-partitions.sh --bootstrap-server kafka:9092 \
--topics-to-move-json-file topics.json \
--broker-list "1,2,3,4" \
--generate
# Execute reassignment
kafka-reassign-partitions.sh --bootstrap-server kafka:9092 \
--reassignment-json-file reassignment.json \
--execute
# Verify progress
kafka-reassign-partitions.sh --bootstrap-server kafka:9092 \
--reassignment-json-file reassignment.json \
--verify
  1. Reassign all partitions away from broker
  2. Verify no partitions remain on broker
  3. Stop broker
  4. (KRaft) Unregister broker:
Terminal window
kafka-metadata.sh --snapshot /path/to/metadata \
--command "unregister --id 4"
Identify broker to restartCheck under-replicated partitionsWait for cluster healthyesUnder-replicated > 0?noStop broker gracefullyWait for controller to detectPerform maintenanceStart brokerWait for broker to rejoin ISRVerify cluster healthNext brokeryesMore brokers?noIdentify broker to restart

Rolling restart script pattern:

Terminal window
for broker in broker1 broker2 broker3; do
echo "Restarting $broker"
# Check cluster health
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --under-replicated-partitions
# Stop broker
ssh $broker "kafka-server-stop.sh"
# Wait for controlled shutdown
sleep 30
# Start broker
ssh $broker "kafka-server-start.sh -daemon config/server.properties"
# Wait for broker to rejoin
sleep 60
# Verify ISR
until kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --under-replicated-partitions | grep -q "^$"; do
sleep 10
done
echo "$broker restarted successfully"
done

Cluster Management Guide


ToolPurpose
kafka-topics.shTopic management
kafka-configs.shConfiguration management
kafka-consumer-groups.shConsumer group management
kafka-reassign-partitions.shPartition reassignment
kafka-acls.shACL management
kafka-metadata.shKRaft metadata inspection
kafka-dump-log.shLog segment inspection
Terminal window
# List topics
kafka-topics.sh --bootstrap-server kafka:9092 --list
# Describe topic
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --topic orders
# Create topic
kafka-topics.sh --bootstrap-server kafka:9092 \
--create --topic orders \
--partitions 12 --replication-factor 3
# Delete topic
kafka-topics.sh --bootstrap-server kafka:9092 \
--delete --topic orders
# Find problematic partitions
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --under-replicated-partitions
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --unavailable-partitions
Terminal window
# List consumer groups
kafka-consumer-groups.sh --bootstrap-server kafka:9092 --list
# Describe group
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--describe --group order-processor
# Reset offsets (requires group to be inactive)
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--group order-processor \
--topic orders \
--reset-offsets --to-earliest --execute
# Reset to specific offset
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--group order-processor \
--topic orders:0 \
--reset-offsets --to-offset 1000 --execute
# Reset to timestamp
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--group order-processor \
--all-topics \
--reset-offsets --to-datetime 2024-01-15T10:00:00.000 --execute
Terminal window
# Describe broker config
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type brokers --entity-name 1 --describe
# Alter broker config
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type brokers --entity-name 1 \
--alter --add-config log.cleaner.threads=4
# Describe topic config
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type topics --entity-name orders --describe
# Alter topic config
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type topics --entity-name orders \
--alter --add-config retention.ms=86400000

CLI Tools Reference


CategoryMetrics
ThroughputMessages in/out, bytes in/out per broker/topic
LatencyRequest latency (produce, fetch, metadata)
AvailabilityUnder-replicated partitions, offline partitions
Consumer healthConsumer lag, commit rate
Resource utilizationCPU, memory, disk, network
MetricConditionSeverity
Under-replicated partitions> 0 for 5 minWarning
Offline partitions> 0Critical
Controller count≠ 1Critical
Consumer lagGrowing continuouslyWarning
Request queue time> 100msWarning
Disk usage> 80%Warning
Disk usage> 90%Critical
# Broker metrics
kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec
kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec
kafka.server:type=BrokerTopicMetrics,name=BytesOutPerSec
# Request metrics
kafka.network:type=RequestMetrics,name=TotalTimeMs,request=Produce
kafka.network:type=RequestMetrics,name=TotalTimeMs,request=FetchConsumer
# Partition metrics
kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions
kafka.controller:type=KafkaController,name=OfflinePartitionsCount
kafka.controller:type=KafkaController,name=ActiveControllerCount
# Consumer lag (via consumer group command or external tools)
kafka.server:type=FetcherLagMetrics,name=ConsumerLag,clientId=*,topic=*,partition=*

Monitoring Guide


Capacity FactorsResource RequirementsThroughput(MB/s)Retention(days)ReplicationFactorConsumerCountNetworkBandwidthDiskStorageDiskIOPSMemory(Page Cache)
Inbound = Producer throughput
Outbound = (Replication factor - 1) × Inbound # Replication
+ Consumer count × Inbound # Consumption
+ MirrorMaker × Inbound # If applicable
+ Connect × relevant throughput # If applicable
Total broker bandwidth = Inbound + Outbound

Example:

  • Ingest: 100 MB/s
  • Replication factor: 3
  • Consumer groups: 5
Outbound = (3-1) × 100 + 5 × 100 = 200 + 500 = 700 MB/s
Total per broker = 100 + 700 = 800 MB/s = 6.4 Gbps
Storage per broker = (Daily ingest × Retention days × RF) / Broker count
+ Compaction overhead (if applicable)
ComponentKey Parameters
Brokernum.io.threads, num.network.threads, socket.send.buffer.bytes
Producerbatch.size, linger.ms, compression.type, buffer.memory
Consumerfetch.min.bytes, fetch.max.wait.ms, max.poll.records
OSvm.swappiness=1, net.core.rmem_max, file descriptor limits
JVMHeap size, GC settings (G1GC recommended)

Performance Guide


TaskFrequencyPurpose
Monitor disk usageContinuousPrevent disk full
Check under-replicated partitionsContinuousDetect issues early
Review consumer lagContinuousEnsure consumers keep up
Log rotationDailyManage log files
Certificate renewalBefore expiryMaintain TLS
Configuration backupWeeklyDisaster recovery
  1. Prepare

    • Review release notes
    • Test in non-production
    • Plan rollback strategy
  2. Rolling Upgrade

    Terminal window
    # For each broker:
    # 1. Stop broker
    # 2. Upgrade binaries
    # 3. Update configuration if needed
    # 4. Start broker
    # 5. Wait for ISR recovery
    # 6. Verify cluster health
  3. Upgrade Protocol Version (after all brokers upgraded)

    inter.broker.protocol.version=3.6
    log.message.format.version=3.6
  4. Verify

    • Check cluster health
    • Verify producer/consumer functionality
    • Monitor for issues

Maintenance Guide


StrategyMethodRPORTO
MirrorMaker 2Active replication to DR siteNear-zeroMinutes
Topic backupConsume and store to object storageHoursHours
Filesystem backupSnapshot log directoriesHoursHours
Configuration backupExport configs and ACLsN/AMinutes
mm2.properties
clusters=source,target
source.bootstrap.servers=source-kafka:9092
target.bootstrap.servers=target-kafka:9092
source->target.enabled=true
source->target.topics=.*
# Replication settings
replication.factor=3
checkpoints.topic.replication.factor=3
heartbeats.topic.replication.factor=3
offset-syncs.topic.replication.factor=3
# Consumer offset sync
sync.group.offsets.enabled=true
ConsiderationRecommendation
RPO requirementDetermines replication lag tolerance
RTO requirementDetermines failover automation level
Data consistencyUnderstand potential message loss during failover
Consumer offset handlingPlan for offset translation or reset
TestingRegular DR drills

Backup/Restore Guide


IssueSymptomsInvestigation
Under-replicated partitionsISR < RFCheck broker health, network, disk I/O
Consumer lag growingLag increasingCheck consumer health, throughput, processing time
High produce latencySlow acksCheck acks setting, ISR health, disk I/O
Broker OOMBroker crashesReview heap size, page cache usage
Disk fullWrite failuresCheck retention, add storage, rebalance
Connection failuresClient errorsCheck network, authentication, quotas
Terminal window
# Check cluster health
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --under-replicated-partitions
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --unavailable-partitions
# Check consumer groups
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--describe --group my-group
# Inspect log segments
kafka-dump-log.sh --files /var/kafka-logs/orders-0/00000000000000000000.log \
--print-data-log
# Check controller
kafka-metadata.sh --snapshot /var/kafka-logs/__cluster_metadata-0/00000000000000000000.log \
--command "describe"

Troubleshooting Guide


Operating Kafka as a shared platform for multiple teams or applications requires isolation mechanisms.

StrategyMechanismIsolation Level
Topic namingHierarchical prefixesLogical
Prefix ACLs--resource-pattern-type prefixedAccess control
QuotasPer-user/client-id limitsResource
Separate clustersPhysical separationComplete

Establish hierarchical topic names for tenant isolation:

<organization>.<team>.<dataset>.<event-name>

Examples:

  • acme.payments.transactions.completed
  • acme.inventory.stock.updated
MethodImplementation
Prefix ACLsGrant produce/consume only to prefixed topics
CreateTopicPolicyCustom policy class to validate topic names
Disable auto-createauto.create.topics.enable=false
External provisioningTopics created only via automation
Terminal window
# Grant user access only to their prefix
kafka-acls.sh --bootstrap-server kafka:9092 \
--add --allow-principal User:team-payments \
--producer --consumer \
--resource-pattern-type prefixed \
--topic acme.payments. \
--group acme.payments.
Terminal window
# Set bandwidth quota for tenant
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type users --entity-name team-payments \
--alter --add-config 'producer_byte_rate=10485760,consumer_byte_rate=20971520'
# Set request rate quota (% of broker capacity)
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type users --entity-name team-payments \
--alter --add-config 'request_percentage=10'
# Set controller mutation rate (topic operations/sec)
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type users --entity-name team-payments \
--alter --add-config 'controller_mutation_rate=5'
MetricPurpose
kafka.server:type=Produce,user=XPer-user produce throttling
kafka.server:type=Fetch,user=XPer-user fetch throttling
kafka.log:type=Log,name=Size,topic=XPer-topic storage usage
kafka.server:type=BrokerTopicMetrics,topic=XPer-topic throughput

Java VersionSupport Level
Java 21Recommended (current LTS)
Java 17Fully supported
Java 11Clients and Streams only

Recommendation

Run Kafka with the most recent LTS release for performance, security patches, and support.

Recommended JVM arguments for production brokers:

Terminal window
-Xmx6g -Xms6g
-XX:MetaspaceSize=96m
-XX:+UseG1GC
-XX:MaxGCPauseMillis=20
-XX:InitiatingHeapOccupancyPercent=35
-XX:G1HeapRegionSize=16M
-XX:MinMetaspaceFreeRatio=50
-XX:MaxMetaspaceFreeRatio=80
-XX:+ExplicitGCInvokesConcurrent

Production cluster performance with above settings:

MetricValue
Brokers60
Partitions50,000 (RF=2)
Messages/sec800,000
Inbound300 MB/s
Outbound1+ GB/s
GC pause (p90)~21ms
Young GC frequency< 1/sec