3 ms·
> a potential confusion between event-sourcing and CQRS IMO this comes up a lot in HN/Reddit discussions about either term. Event-sourcing implies CQRS, but th
by Terr_ 10y ago
> a potential confusion between event-sourcing and CQRS
IMO this comes up a lot in HN/Reddit discussions about either term. Event-sourcing implies CQRS, but the reverse is not true.
> I'd love to write some definitive treatise [...] Sadly I don't have the time to do it.
The "Fermat's Last Theorem" approach to computer architecture :P
- to3m 10y agoI'm not sure... sounds like CQRS (though it's a term I don't think I've ever seen before...) is independent. Like, you can have one data structure for read/write, and you just don't get public access to the write interface directly, only through functions that add to the event list and then do the event. Along the lines of something vaguely like this, perhaps: void Stuff::AddThing(Thing *thing) { this->AddEvent(new AddThingEvent(thing)); } void Stuff::AddEvent(Event *event) { m_events.push_back(event); event->Execute(this); } void AddThingEvent::Execute(Stuff *stuff) { stuff->m_things.push_back(m_thing); } and maybe AddThingEvent is a friend of Stuff, or it's an inner class, or whatever you like. Maybe this is what he meant though.
- Terr_ 10y agoI think that most of the time event-sourcing will impact your model/business-logic layer, because you often want to capture the intent of changes, rather than calculating a naive combined delta of all changes that occurred in memory. If so, that means that instead of a CRUD interface like: if(customer.getApprovalLevel() < 5){ customer.setApprovalLevel(5); customer.setApprover(currentUser); } saveChangesSomehow(customer); So you'll end up with an API that's a bit more CQS (no 'R' yet) with: if(customer.getApprovalLevel() < 5){ customer.promoteApprovalLevel(5, currentUser); } saveChangesSomehow(customer); That way you capture each change-event at the right granularity with the necessary data. Finally, CQRS comes into play because you want to do something with that rich event data, such as eagerly populating a table: recentApprovals = getRecentApprovals(); if(recentApprovals.length() > 0){ sendApprovalAuditReport(recentApprovals); }
- pc86 10y agoIsn't it the eventual consistency model that implies CQRS? If you have synchronous event-sourcing you can have a single model/service for reads and writes.