Video in progress

Explain topics and partitions with a simple example.

A topic is a named stream of messages, for example payments. A partition is a slice of a topic; each partition is a separate ordered log that can live on a different broker and be read in parallel.

📖 Answer

Say the payments topic was created with 3 partitions:

payments-0: [m0, m1, m2, m3 ...]
payments-1: [m0, m1 ...]
payments-2: [m0, m1, m2 ...]

Each partition is an append-only list. The order inside a partition is strict, but there is no global order across partitions.

Why do you need partitions? Parallelism. Within one group, only one consumer reads a given partition, so with 3 partitions, 3 consumers can work at the same time. The other reason is size: partitions are spread across brokers, so one server's disk doesn't have to hold everything.

Pick the partition count carefully when you create a topic: you can increase it later, but you can't decrease it.