Kafkaの運用には、モニタリング(特にコンシューマーラグ(コンシューマーがどれだけ遅れているか))、ブローカーヘルス、スループット、パーティションのステータスなどの主要メトリクスの監視が必要です。モニタリングとコンシューマーラグの理解はKafkaを確実に運用するために重要です。
コンシューマーラグ(主要なメトリクス)
CONSUMER LAG → how far BEHIND a consumer is = (latest offset) − (consumer's committed offset):
→ high/growing lag → the consumer can't keep up with the production rate (a problem!)
→ indicates: slow processing, too few consumers, a stuck/failed consumer, or a traffic spike
→ monitor lag → detect when consumers fall behind (a primary Kafka health signal)
コンシューマーラグへの対処
✓ ADD CONSUMERS (scale the group, up to partition count) → more parallel processing
✓ ADD PARTITIONS → enable more consumer parallelism (if at the consumer limit)
✓ OPTIMIZE consumer processing → make it faster (batch, async, efficient code)
✓ Investigate stuck/failing consumers; check for rebalancing issues
✓ Scale based on lag (auto-scaling consumers on lag is common)
