distributedsystem/microservice systemdesign

How Kafka Works

  • Kafka is a distributed log-based streaming platform.
  • Data is written to topics.
  • Each topic is divided into n partitions.
  • A hash key (or round-robin) determines which partition a message goes to.
  • Within a partition, messages are strictly ordered.
  • No global ordering across partitions.

Key Kafka Concepts

ConceptDescription
TopicLogical stream/category of messages.
PartitionUnit of parallelism and storage; messages are appended in order.
ProducerSends data to Kafka topic (partitioned via key).
ConsumerReads messages from partitions (via consumer groups).
OffsetUnique ID for message position within a partition.

Limitation of Kafka

No. of consumers = No. of partitions (within a consumer group)

  • Each partition can be read by only one consumer in a consumer group.
  • This limits horizontal scalability of consumers:
    • E.g., 5 partitions → max 5 consumers in one group.
  • More consumers than partitions? → Some consumers sit idle.