Understanding Replication
1. Understanding Replication Concept
| Concept | Description | Detail |
|---|---|---|
| Replication | Copy partitions across brokers | Fault tolerance |
| RF=N | Survives N-1 failures | Durability |
| Per Partition | Each has own replica set | Independent |
Example: Topic with RF=3
kafka-topics.sh --create --topic critical --partitions 6 \
--replication-factor 3 --bootstrap-server localhost:9092
2. Understanding Leader and Followers
| Role | Responsibility | Detail |
|---|---|---|
| Leader | Handles all reads/writes | One per partition |
| Follower | Replicates from leader | Passive |
| Fetch | Followers pull from leader | Like consumers |
Example: Identify leader
kafka-topics.sh --describe --topic critical --bootstrap-server localhost:9092 \
| grep "Leader:"
3. Configuring Replication Factor
| Config | Description | Default |
|---|---|---|
| default.replication.factor | Auto-created topics RF | 1 |
| --replication-factor | Per-topic at create | Explicit |
| Constraint | RF ≤ broker count | Hard limit |
4. Understanding In-Sync Replicas
| Concept | Description | Detail |
|---|---|---|
| ISR | Replicas caught up to leader | Election eligible |
| Shrink | Lagging replica removed | Falls behind |
| Expand | Caught-up replica re-added | Recovered |
Example: Check ISR
kafka-topics.sh --describe --topic critical --bootstrap-server localhost:9092
# ... Isr: 1,2,3 (all in sync)
5. Configuring Replica Lag
| Config | Description | Default |
|---|---|---|
| replica.lag. time.max.ms |
Max follower lag before ISR removal | 30000 |
| replica.fetch. max.bytes |
Bytes per fetch | 1048576 |
| num.replica.fetchers | Fetcher threads | 1 |
6. Understanding Leader Election
| Type | Description | Risk |
|---|---|---|
| Clean | New leader from ISR | No data loss |
| Unclean | Out-of-sync replica promoted | Possible loss |
| Preferred | Restore first replica | Load balance |
7. Understanding Replica High Watermark
| Concept | Description | Detail |
|---|---|---|
| High Watermark | Highest offset replicated to all ISR | HW |
| Consumer Visibility | Reads only up to HW | Committed data |
| Advance | Moves as ISR catch up | Min of LEOs |
8. Understanding Log End Offset
| Concept | Description | Detail |
|---|---|---|
| LEO | Offset of next record to append | Per replica |
| Leader LEO | Tip of the partition | Latest |
| Follower LEO | How far follower copied | ≤ leader LEO |
9. Configuring Preferred Leader
| Aspect | Description | Detail |
|---|---|---|
| Preferred | First replica in list | Default leader |
| Rebalance | Restore for even load | Auto or manual |
| Tool | kafka-leader-election.sh | PREFERRED type |
Example: Run preferred election
kafka-leader-election.sh --election-type PREFERRED \
--all-topic-partitions --bootstrap-server localhost:9092
10. Understanding Replica Fetcher
| Aspect | Description | Detail |
|---|---|---|
| ReplicaFetcherThread | Pulls data from leaders | Per broker pair |
| num.replica.fetchers | Parallel fetcher count | Scale with load |
| Throttling | Limit during reassignment | replica.alter.log.dirs |
11. Manual Replica Reassignment
| Step | Command | Detail |
|---|---|---|
| Plan | JSON with new replicas | Per partition |
| Execute | --execute |
Apply + throttle |
| Verify | --verify |
Confirm complete |