A Data Mesh from Scratch in Rust — Part 2— Events and Actions
If you missed my ramblings in Part 1, I strongly encourage you look up my motivation there. Anyhow, in this part, I am going to explain how I define the Events and the Actions that will be the core of this data system.
So Events are the things that we will store in this database. And the core part of the events are going to be a predefined action and an optional variable length payload.

The idea of the Action
roughly follows that from REST (HTTP verbs). But I think defining Action
in this way provides an extra benefit — tombstones
(deletion events) can actually be signaled by Action::DELETE
.

The transaction_id
uniquely identifies the event — so one can build a chain in stateful cases. It’s provided by this wonderful crate. I am not entirely certain how I want to use the timestamp
on the Event
. And payload
as you can see is an optional Vec<u8>
, which is the standard serialization end result. I am using bincode for this.
Not much else is going on here except the size()
method which is a demonstration of how one might go about calculating size of structs
in Rust.

The overall idea is you calculate size of each type and adjust for alignment. Frankly, this is overkill for what we have. However, it probably works out for the payload
field.
The next part will explain the MemTable
implementation.