Skip to main content

Question 14 of 50

What is a Partition?

Mid-levelSenior

Question

"What is a Partition in Kafka?"

What the interviewer wants to assess

Whether you understand partition as the real unit of storage, ordering, and parallelism — the piece cited most often in practically every subsequent Kafka question.

Resposta rápida

Partition is an ordered, immutable subdivision of a topic — the actual physical log. Each partition is a sequence of records identified by an increasing offset, stored on a broker (with replicas on other brokers, when the replication factor is greater than 1).

Resposta nível Sênior

A partition is an append-only log: new records are always added at the end, never modified in place, each identified by an offset local to that partition. It's the unit that enables consumption parallelism (each partition is read by a single consumer within a Consumer Group) and write scalability (partitions of the same topic can live on different brokers). A message's key (Chapter 4) determines, via hash, which partition it's stored in — and it's that decision that defines which events stay ordered relative to each other.

In-depth explanation

See "Partition" in Chapter 3 and the deep dive on ordering in Chapter 4.

Exemplo financeiro

On the pix.recebido topic, each event's destination partition is determined by the hash of contaId — every event for the same account lands on the same partition, preserving their relative order.

"More partitions is always better"

More partitions increase maximum parallelism, but also the cluster's metadata overhead, rebalance time, and the number of file handles per broker. The right number is sized by target throughput and the number of consumers the team plans to scale to — not an arbitrary "just to be safe" value.

Pode vir a seguir

Likely follow-ups: "why do Partitions exist?" and "how does Kafka choose a Partition for a message?".