Advanced Spring Boot 4: Event-Driven Architecture (Kafka) · 课时

容量规划:分区与副本

学习如何为主题确定合适的分区数量和副本因子,在吞吐量、并行度、持久性和运维成本之间取得平衡。

第 4 / 4 课13 个步骤

容量规划:分区与副本 是 CoddyKit 上的免费 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Why Sizing Matters

Partition count and replication factor are hard to change after launch and directly shape throughput, parallelism, and durability. Good capacity planning avoids painful migrations later.

Partitions Drive Parallelism

A consumer group can have at most as many active consumers as there are partitions. More partitions allow more parallel consumers and higher throughput.

Estimating Partition Count

A common heuristic: divide target throughput by per-partition throughput.

  • Measure max producer throughput per partition (p).
  • Measure max consumer throughput per partition (c).
  • partitions = max(target/p, target/c).
partitions = ceil( targetMBs / min(producerMBs, consumerMBs) )

The Cost of Too Many Partitions

More partitions are not free:

  • More open file handles and memory on brokers.
  • Longer leader-election and rebalance times.
  • Higher end-to-end latency.

Plan headroom, but do not wildly over-provision.

Replication Factor

The replication factor is how many copies of each partition exist across brokers. A factor of 3 is standard for production durability.

In-Sync Replicas

With min.insync.replicas=2 and acks=all, a write succeeds only when at least two replicas confirm. This tolerates one broker failure without data loss.

min.insync.replicas=2
replication.factor=3

Creating a Sized Topic

Specify partitions and replication when creating a topic so it starts correctly sized.

kafka-topics.sh --create --topic orders \
  --partitions 12 --replication-factor 3 \
  --bootstrap-server localhost:9092

Planning for Growth

You can increase partitions later but never decrease them, and adding partitions breaks key-based ordering. Pick a count with growth headroom from the start.

Retention and Disk Sizing

Disk need = throughput x retention x replication factor. A topic at 10 MB/s with 7-day retention and RF 3 needs roughly 17 TB. Plan storage accordingly.

Spreading Across Brokers

Ensure partitions and replicas are evenly distributed so no broker becomes a hotspot. Rack-awareness places replicas across failure domains.

Putting It Together

Capacity planning balances parallelism, durability, latency, and cost. Size partitions from throughput, use RF 3 with min ISR 2, and plan disk from retention.

Quick Check

Test your understanding of capacity planning.

Recap

You learned capacity planning.

  • Partition count drives consumer parallelism and throughput.
  • Too many partitions add latency and broker overhead.
  • RF 3 with min ISR 2 tolerates one broker failure.
  • Plan disk from throughput x retention x replication.
免费开始

用 AI 导师学习 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) — 免费

在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。

课程
12
课程
48

常见问题解答

「容量规划:分区与副本」课时是免费的吗?

是的 — 「容量规划:分区与副本」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 课程的其余内容,请升级到 CoddyKit PRO。 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 课程共包含 4 节课。

「容量规划:分区与副本」这节课中我会学到什么?

学习如何为主题确定合适的分区数量和副本因子,在吞吐量、并行度、持久性和运维成本之间取得平衡。 你通过在浏览器中直接运行的动手代码来练习 Advanced Spring Boot 4: Event-Driven Architecture (Kafka),全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「容量规划:分区与副本」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 课中编写并运行代码吗?

能。每节 Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. Kafka 性能调优技巧
  2. 幂等生产者和消费者
  3. 将 Spring Boot Kafka 应用部署到云端
  4. 容量规划:分区与副本
← 返回 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)