Using logs for message storage

To Nha Notes | Aug. 30, 2023, 11:20 p.m.

A log is simply an append-only sequence of records on disk. We previously discussed logs in the context of log-structured storage engines and write-ahead logs.

The same structure can be used to implement a message broker: a producer sends a message by appending it to the end of the log, and a consumer receives messages by reading the log sequentially. If a consumer reaches the end of the log, it waits for a notification that a new message has been appended. The Unix tool tail -f, which watches a file for data being appended, essentially works like this.

Apache Kafka [1718], Amazon Kinesis Streams [19], and Twitter’s DistributedLog [2021] are log-based message brokers that work like this.