From ccf7d3175d1105ce97b80ef697d10f261654207a Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 26 Sep 2025 09:11:05 +0200 Subject: [PATCH] Add a simple spec --- Spec.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Spec.md diff --git a/Spec.md b/Spec.md new file mode 100644 index 0000000..d806cc0 --- /dev/null +++ b/Spec.md @@ -0,0 +1,36 @@ +Event log based store + +The data rows of our table are to be recreated from an event log +All interactions with the rows is to happen exclusively via events from/in the log +For performance reasons we are to cache these data rows as well for quick lookup + +Events in the log are to take form of: +type Event struct { + Seq int + Type "create"|"update"|"delete" + Hash string + ItemID string // uuid-v4 + EventID string // uuid-v4 + Data map[string]interface{} + Timestamp datetime +} +Events are divided into 3 types, create update and delete events +Create events simply create the object as given in Data +Delete events simply mark an object as deleted (not actually delete!) via its ItemID +Update events are to modify a field of a row and never more than one field +Therefore its data is only the diff in the form of "age = 3" + +When creating an event only the Type and ItemID must be provided +Data is optional (delete events have no data) +Hash, EventID and Seq are to be computed server side + +On the server side with an incoming event: +Grab the latest event +Assign the event a sequence number that is incremented from the latest +Create its EventID (generate a uuid-v4) +Assign it a Timestamp +Compute the hash from the dump of the current event PLUS the previous event's hash +And only then apply the patch +For create events that is insert objects +For delete events that is mark objects as deleted +For update events get the object, apply the diff and sav the object \ No newline at end of file