elm-broker
Data stream buffer for Elm application, inspired by Apache Kafka.
What is this?
-
Brokeris essentially a circular buffer, internally usingArray - Read pointers (
Offset) are exposed to clients, allowing "pull"-style data consumption, just as in Kafka - Insert(
append),read, andupdateall take O(1) - A buffer is made of multiple
Segments. Buffer size (= number ofSegments and size of eachSegment) can be configured - When the whole buffer is filled up, a new "cycle" begins and old
Segments are evicted one by one
Expected Usage
- A
Brokeraccepts incoming data stream. † - Several consumers reads ("pulls") data from the
Brokerindividually, while maintaining eachOffsetas their internal states. - Consumers perform arbitrary operations against acquired data, then read
Brokeragain after previousOffset. Rinse and repeat.
†
It is possible to have multiple Brokers in your application for different purposes,
however you must be careful so that you do not mix up Offsets produced from one Broker to ones from others.
Since Offsets are only valid for their generating Broker.
Wrapping Offsets in phantom types is a possible technique to enforce this restriction.
Remarks
- Technically, it can also perform O(1)
delete, but it is still unclear whether we wantdeleteAPI- Original Kafka now supports this as an admin command
- There are several major features I am interested in:
- More sophisticated/efficient dump and reload. Current implementation is plain old
encodeanddecoderpair, which is potentially inefficient for big-capacityBrokers. - Bulk append and bulk read
- Callback mechanism around
Segmenteviction
- More sophisticated/efficient dump and reload. Current implementation is plain old
Development
Install Elm Platform.
$ elm make
$ elm-test # full test
$ elm-test tests/MainTest.elm # only light-weight testsLicense
Copyright © 2018, Yu Matsuzawa
BSD-3-Clause