beyond crud: patterns that never forget
TRANSCRIPT
· R&D Software Manager @ Bizpills Group
· Now making a new platform
easy, fast, collaborative & scalable
Rise your hand if you have
· heard about CQRS/Event Sourcing
· used it in production
· heard about Redux
Big data trees
Our need: Make fast & scalable
reads, writes and copies
Problem: read fast or write fast
but not both
Challenge
backend
frontend
CQRS:Command Query
Responsibility Segregation
sync orasync
deriveddata
Commandlogic
Querylogic
CQRS: Derived data
◼ Application-level
▼ Race conditions
▼ Cold start
▼ Cache miss ratio
▼ Invalidation
Cache
CQRS: Derived data
◼ Application-level
▼ Race conditions
▼ Cold start
▼ Cache miss ratio
▼ Invalidation
◼ Database-level
▲ Autosync
▼ Additional load on database
▼ Limited to SQL logic
▼ Code testing/maintenance
Cache Materialized Views
backend
frontend
CQRS:Command Query
Responsibility Segregation
sync orasync
deriveddata
Commandlogic
Querylogic
CQRS: Pros & Cons
▲ Separation of concerns
▲ Optimize reads & writes
▲ No cold cache
▲ No race conditions
▲ Agile development
▲ Scale reads & writesindependently
CQRS: Pros & Cons
▲ Separation of concerns
▲ Optimize reads & writes
▲ No cold cache
▲ No race conditions
▲ Agile development
▲ Scale reads & writesindependently
▼ Complexity
▼ UX impact
Don’t save current state
Save the events that lead to current state
A
1 32
node parent
1 A
2 A
event node parent
ADD_CHILD 1 A
ADD_CHILD 2 A
ADD_CHILD 3 A
REMOVE_CHILD 3 A
Event Sourcing
ES: Pros & Cons
▲ Fast-write
▲ Deal with immutable data
▲ Easy audit
▲ Recovery from human error
▲ Users can undo actions
▲ Better analytics
ES: Pros & Cons
▲ Fast-write
▲ Deal with immutable data
▲ Easy audit
▲ Recovery from human error
▲ Users can undo actions
▲ Better analytics
▼ Complexity
▼ Event backward compatibility
▼ No current state
▼ Slow-read
Redux
REDUCERS STATE
actions subscribe
change State container written in Javascript
UI dispatch actions
Only reducers change state
backend
views
frontend
view generator
a
Redux + ES + CQRS
action log
a
Commandlogic
Querylogic
Re
Sta
Commandlogic
Querylogic
Re
St
Re St
backend
action log
views
frontend
a
a
a
view generator
Redux + ES + CQRS
Redux: Pros & Cons
▲ Predictable state changes
▲ Optimistic UI
▲ Desktop app performance
▲ “undo” UI
Redux: Pros & Cons
▲ Predictable state changes
▲ Optimistic UI
▲ Desktop app performance
▲ “undo” UI
▼ Learning curve
Commandlogic
Querylogic
Re
St
Re St
backend
action log
views
frontend
a
a
a
view generator
Redux + ES + CQRS
Commandlogic
Querylogic
Re
St
Re St
backend
action log
views
frontend
a
a
a
a
view generator
Redux + ES + CQRSreal time collaboration
web socket
ReferencesMartin Kleppmann @ Strange Loop 2014: Turning the database inside-out with Apache Samzahttps://www.confluent.io/blog/turning-the-database-inside-out-with-apache-samza/
Kevin Robinson @ React Europe 2015: Simplifying the data layer at react-europe 2015https://www.youtube.com/watch?v=EOz4D_714R8
Martin Fowler: CQRShttp://martinfowler.com/bliki/CQRS.htm