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.

相关推荐
jj_ccwgw17 小时前
Kafka 集群开机自启动配置指南
后端·kafka
肠畔码农18 小时前
深入分布式事务内核:从 2PC/XA 到 Seata AT 模式的架构演进与权衡
分布式·架构
ai小陈19 小时前
PyTorch多GPU分布式训练实战:从单卡脚本迁移到DDP
服务器·人工智能·pytorch·分布式·深度学习·ai·gpu算力
伟大的大威20 小时前
三台 DGX Spark 部署 DeepSeek V4 Flash NVFP4:从零到可用教程
大数据·分布式·spark
JackSparrow41420 小时前
Kafka(七)集成Apache Avro+Apicurio Schema Registry以保障生产者与消费者的消息兼容性
java·中间件·rpc·kafka·apache·avro·schema-registry
阿里云云原生20 小时前
企业级实时数据平台建设:利用存算分离 Kafka 实现低成本、高可靠入湖
分布式·阿里云·云原生·kafka
国科安芯20 小时前
星载CANFD总线通信网络中抗辐射微控制器MCU的失效机理与容错设计研究
网络·人工智能·分布式·单片机·嵌入式硬件·架构·抗辐射加固
zcmodeltech21 小时前
污水处理设备沙盘模型控制系统设计与实现:多单元协同联动方案
网络·分布式·stm32·单片机·嵌入式硬件·交互
roman_日积跬步-终至千里21 小时前
Spark 资源配置与 Shuffle 故障排查生产手册
大数据·分布式·spark
roman_日积跬步-终至千里21 小时前
常驻 Spark 引擎的稳定性风险:从一次 Linkis 任务失败说起
大数据·分布式·spark