36 lines
1.4 KiB
Markdown
36 lines
1.4 KiB
Markdown
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 |