
π― #Big picture of how Kafka works in production systems.#
Read top-to-bottom β each layer builds on the previous one.
The One Rule That Makes Kafka Click
Kafka is a distributed event streaming system.
Instead of services directly calling each other:
Service A β Service B
Kafka sits in the middle:
Producer β Kafka β Consumer
This creates:
- decoupling
- scalability
- retry handling
- parallel processing
- fault tolerance
If you remember only one thing:
Kafka stores events and lets consumers process them independently.
Layer 0 β Kafka Cluster
A Kafka Cluster is the complete Kafka system.
KAFKA CLUSTER
βββ Broker 1
βββ Broker 2
βββ Broker 3
βββ Broker N
Why multiple brokers?
- high availability
- replication
- horizontal scaling
- fault tolerance
If one broker crashes, Kafka still works.
Layer 1 β Brokers
A Broker is an actual Kafka server.
Its job:
- store messages
- manage partitions
- handle producers
- handle consumers
- replicate data
Producer β Broker β Consumer
Production systems usually have:
- 3 brokers
- 5 brokers
- 10+ brokers
depending on scale.
Layer 2 β Topics
A Topic is a category of messages.
Examples:
payments
orders
notifications
emails
ledger-events
Producers send messages into topics.
Consumers read messages from topics.
Layer 3 β Partitions (The Real Scaling Unit)
Topics are divided into partitions.
payments
βββ Partition 0
βββ Partition 1
βββ Partition 2
βββ Partition 3
Partitions solve:
- parallel processing
- scaling
- load distribution
The Most Important Kafka Rule
Kafka guarantees ordering only inside a partition.
Partition 0
Offset 0 β Payment Created
Offset 1 β Payment Success
Offset 2 β Ledger Updated
This order is guaranteed.
Layer 4 β Producers
Producers send events into Kafka.
Example:
Payment Service
β
Kafka Producer
β
payments topic
Production producers usually use:
- retries
- acks=all
- idempotence
- compression
- batching
to avoid data loss.
Layer 5 β Consumers
Consumers read messages from Kafka.
payments topic
β
Consumer
β
Process Payment
Consumers usually:
- save DB data
- call APIs
- send notifications
- update ledgers
- trigger workflows
Layer 6 β Consumer Groups
A Consumer Group is a team of consumers working together.
payment-group
βββ Consumer 1
βββ Consumer 2
βββ Consumer 3
Kafka distributes partitions among consumers.
Partition 0 β Consumer 1
Partition 1 β Consumer 2
Partition 2 β Consumer 3
This enables parallel processing.
Important Kafka Rule
One partition
β only one consumer in same group
This prevents duplicate processing.
Layer 7 β Offsets
Every message inside a partition has an offset.
Offset 0
Offset 1
Offset 2
Offsets are basically:
- message positions
- progress trackers
Consumers commit offsets after successful processing.
Layer 8 β Replication
Kafka replicates partitions across brokers.
Partition 0
βββ Leader β Broker 1
βββ Replica β Broker 2
βββ Replica β Broker 3
If Broker 1 crashes:
- replica becomes leader
- system continues running
This provides fault tolerance.
Layer 9 β Retry + DLQ
Production systems always use retries.
Main Topic
β fail
Retry Topic
β fail again
DLQ (Dead Letter Queue)
Used for:
- temporary API failures
- DB issues
- payment gateway failures
- webhook failures
Layer 10 β Idempotency
Kafka retries can create duplicate processing.
Real systems solve this using:
transactionId
Example:
UNIQUE(transaction_id)
This prevents:
- duplicate payments
- duplicate ledger entries
- double processing
Layer 11 β Scaling Model
Kafka scales using:
#Partitions#
NOT by endlessly increasing threads.
Production scaling usually looks like:
More traffic
β
Increase partitions
β
Add more consumers
β
Add more machines
Layer 12 β Admin Role
Kafka Admin usually manages:
- brokers
- topics
- partitions
- ACLs
- security
- monitoring
- retention policies
Admin controls the Kafka infrastructure.
Layer 13 β Production Flow
Client/API
β
Producer
β
Kafka Topic
β
Partitions
β
Kafka Brokers
β
Consumer Group
β
Consumers
β
Database / APIs / Notifications
Real Production Mental Model
Think of Kafka as:
A distributed event pipeline where producers continuously send events and consumers process them independently at their own speed.
Kafka handles:
- replication
- failover
- ordering within partitions
- message storage
- consumer coordination
Applications handle:
- business logic
- retries
- idempotency
- validations
- database updates
Final Takeaway
Donβt memorize definitions.
Memorize the flow:
Producer
β
Topic
β
Partitions
β
Broker
β
Consumer Group
β
Consumers
β
Business Logic
That is the real Kafka mental model.