Kafka broker 写消息的过程

text 复制代码
Producer → Kafka Broker → Replication → Consumer
               |
          Partition chosen (by key or round-robin)
               |
          Message appended to end of log (commit log)

上面的流程是kafka 写操作的大体流程。

kafka 不会特意保留message 在内存中,而是直接写入了disk。

那么消费的时候,如果是最近 produced 的message,即使写入了disk,还是会保留在OS的page cache中。 OS page cache 即使是flush 到了disk,也不会被立刻清除,这个是OS 自己的机制。 所以consumer 读最近生产的消息的时候,还是可以从page cache中读取出来的,而不用从disk 中读取。

  1. Kafka Broker Receives the Message

    决定partition

  2. Message is Appended to a Partition Log

    The selected broker appends the message to the end of the partition log (a sequential write).

    Kafka writes messages to disk efficiently using write-ahead logs (WAL).

  3. Replication (for Fault Tolerance)

    Kafka waits for acknowledgments based on the producer's acks setting:

    acks=0: Producer doesn't wait.

    acks=1: Wait for leader only.

    acks=all: Wait for all replicas to acknowledge.

  4. Message is Made Available to Consumers

    Once the acks is fulfilled, it becomes available for consumers.

    Consumers read sequentially using offsets.

    Kafka keeps messages for a retention period (e.g., 7 days), regardless of whether they've been consumed.

相关推荐
RobinXYuan4 小时前
【Kafka 源码手记】05 Broker 网络层与请求处理(中):Processor 事件循环与线上的字节
kafka·源码阅读
NiceZack5 小时前
Hadoop 部署全流程教程:从新装 CentOS 到伪分布式与完全分布式
hadoop·分布式·centos
傻啦嘿哟5 小时前
分布式爬虫架构:Redis+Scrapy打造企业级爬虫系统
分布式·爬虫·架构
坐吃山猪7 小时前
Kafka13-自定义分区器
kafka
starzy19907 小时前
Kafka请求进门口:Processor是怎么把请求读上来的
分布式·kafka
骑着蜗牛撵大象3271 天前
558 万美元训出 671B 模型:DeepSeek-V3 算法与系统的协同拆解
分布式·算法·moe·deepseek-v3·mla·fp8训练
德迅云安全-上官1 天前
德迅游戏盾:面向 TCP 业务的分布式云安全防护方案
分布式·tcp/ip·游戏
麻瓜code1 天前
分布式锁演进:从一个用户下两单,到 Redisson,我改了四版
分布式·wpf
starzy19901 天前
Kafka网络层第一道门:Acceptor线程是怎么启动的
大数据·kafka
skywalk81631 天前
hive —— 多机 AI Agent 协同的任务总线:分布式,多节点同时运行,保障不会宕机
人工智能·hive·分布式