Replies: 1 comment
-
To be clear here is the code: https://github.com/hallgren/wtf/tree/eventsourcing_take2 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Ben.
First thanks for your wtf dial project and all the time you spend enriching the go community.
I'm one of the maintainers of a event sourcing pkg eventsourcing. I had a go rewrite parts of this project (wtf-dial) with event sourcing in mind. The parts that is changed is the dial and dial membership. I have joined these two entities and named it ESDial.
The sqlite.DialService write part is taken over, all writes to dial are now pointing to the new es.DialService (es.DialMembershipService is yet to be implemented). Successful writes will generate events that are the base of the state of the ESDial entity. The events are also used to build the already existing database schema (that is used for reads). The database holds a new table "events" that holds the events from the ESDial model. Its an append only log holding all events that has occurred on ESDial entities in the system.
Write model
User and Auth is as is.
Dial and DialMembership -> ESDial
The two models Dial and Dialmembership is now put together in one model ESDial. The reason is that they change together making a natural join, this means that all changes made to a dial or internal dialmemberships goes throw the dial as central entry point.
Read model
The existing sqlite schema is the same and the data is build up from the event created from the write model.
The es.DialService subscribes to the events from the ESDial entity and builds the read model and also trigger the events that is sent to the clients. A nice thing is that no business rules has to be validated at this time when the events are facts and has already append.
Events on ESDial
The events that are defined in ESDial are:
// Created event happens when the dial is first created
type Created struct {
OwnerID int
Name string
InviteCode string
}
// SelfMembershipCreated event is attached when the dial is created
type SelfMembershipCreated struct {
ID int
UserID int
Value int
}
// MembershipCreated event when a user is adding a dial membership
type MembershipCreated struct {
ID int
UserID int
Value int
}
// MembershipValueUpdated event when a user updates her/his dial value
type MembershipUpdated struct {
ID int
Value int
}
// DialValueUpdated event when the aggregated dial value is updated
type DialValueUpdated struct {
Value int
}
// Renamed update the dial name
type Renamed struct {
Name string
}
// Deleted indicates that the dial is no more
type Deleted struct{}
Beta Was this translation helpful? Give feedback.
All reactions