Software Architecture
Event-Driven Architecture with Apache Kafka: Designing High-Throughput Event Streaming Systems
technology.efektifpro.com – Apache Kafka processes over 7 trillion messages per day at LinkedIn, handles 4.5 million events per second at Netflix, and powers real-time fraud detection across every major financial institution. Understanding Kafka’s core design — a distributed, immutable, ordered log — is the prerequisite for designing systems that remain performant and maintainable at scale.
Topic Design: Partitioning Strategy Is Everything
# Kafka Admin Client — Create topic with optimal partitioning
from kafka.admin import KafkaAdminClient, NewTopic
admin = KafkaAdminClient(bootstrap_servers="kafka-broker:9092")
payment_events_topic = NewTopic(
name="payment-events",
num_partitions=20,
replication_factor=3,
topic_configs={
"retention.ms": str(7 * 24 * 60 * 60 * 1000),
"cleanup.policy": "delete",
"min.insync.replicas": "2",
"compression.type": "snappy",
}
)
admin.create_topics([payment_events_topic])
Message Key Design: Guaranteed Ordering Within Partitions
# Python — Produce payment events with entity-based key routing
producer.send(
topic="payment-events",
key=f"account:{event['account_id']}",
value={
"event_type": "PAYMENT_PROCESSED",
"account_id": event["account_id"],
"amount": event["amount"],
"timestamp": event["timestamp"],
}
)
Schema Registry: Enforcing Contract Compatibility
Schema Registry enforces backward compatibility and forward compatibility by validating schema changes before they are accepted. Adding an optional field with a default is compatible; removing a required field is not — preventing downstream consumer breakage.
Kafka Architecture Checklist
- ✅ Partition count = (target_tps / per_partition_tps) x 2 headroom factor
- ✅ Replication factor >= 3 with min.insync.replicas = 2
- ✅ Entity-based message keys for ordering guarantees
- ✅ Idempotent producer + transactional consumers for exactly-once
- ✅ Schema Registry with backward/forward compatibility enforcement
- ✅ Consumer lag monitoring with Prometheus + Kafka Exporter alerts
- ✅ Dead Letter Queue (DLQ) topic for unprocessable messages
