SlideShare a Scribd company logo
@Ramtop
CQRS with Event
Source
in Functional sauce
served by Kotlin
Uberto Barbinigithub.com/uberto/anticapizzeria
@Ramtop
CQRS + Event Source
Very powerful
but a bit
intimidating…
Can we do
better?
@Ramtop
Functional Programming
● Immutability
● Purity
● Higher order functions
● Transformations and preserving
properties
@Ramtop
Functional vs OO Programming
@Ramtop
Command
●
A Command is a request for changing the
internal state of the system
●
A Command can “fail” if is not congruent with
the current state of the System
●
Each Command is executed in an atomic
context
@Ramtop
Query
●
A query ask for a snapshot of the state
●
Queries typically need different data and
denormalization from domain model. So we separate
the models in CQRS.
●
Queries are eventually consistent with the domain
@Ramtop
Values-Entities
●
They represent the state of the domain
●
In functional programming everything is
immutable, so there is no identity
●
To keep state changes we have Algebraic Data
Types
@Ramtop
Aggregates
●
An aggregate has all the information for a
transaction unit
●
Aggregates is what Events fold to
●
They are composed by Entities
@Ramtop
Event
●
Events are the “atoms” of System state change
●
Nothing can change without an event, every
event can change only one entity
● Entity + Event => Entity
@Ramtop
Actors
●
More powerful and easy to use concurrency
model than Threads/Locks
●
They communicate asynchronously and
potentially remotely
●
Useful for Bounded Contexts and Services
@Ramtop
@Ramtop
Antica Pizzeria
●
Real application is about finance products
booking but a pizzeria has a surprising similar
domain
●
We want to do implement the backend for a
ChatBot that will assist booking and enquires
about orders.
@Ramtop
Kotlin Syntax
●
No semicolon!
●
String? Is a different type from String
●
myFun{println(it)} is equivalent to
myFun(x -> println(x))
●
val xy is declaring xy immutable
var xy is declaring xy mutable
●
User(“Joe”) is equivalent to Java
new User(“Joe”)
@Ramtop
Commands
@Ramtop
Commands
@Ramtop
Queries
@Ramtop
Actors
(where we can put all this stuff)
@Ramtop
Commands emit Events
(it’s the only way to change)
@Ramtop
Events
@Ramtop
Queries listen to Events
(to keep up with the changes)
@Ramtop
Let's fold Events
(to create Entities)
@Ramtop
Entities as EventComposable
@Ramtop
Execute Commands
@Ramtop
Logic inside Commands
@Ramtop
Application
@Ramtop
We can now process C&Q
(Fun with Kotlin ExtFun)
@Ramtop
Real
Code
Now!
@Ramtop
QAUberto Barbini
@Ramtop
github.com/uberto/anticapizzeria
@Ramtop
@Ramtop

More Related Content

PPTX
Ppt negosiasi
PPT
Las organizaciones y_la_comunicacion
PPT
Introduction to State Machines
PDF
Forward JS 2017 | SF | Write applications as State Machines
PDF
Functional web with clojure
KEY
Perl + pathfinder == <3
PDF
Reactive mistakes - ScalaDays Chicago 2017
ODP
Appstate
Ppt negosiasi
Las organizaciones y_la_comunicacion
Introduction to State Machines
Forward JS 2017 | SF | Write applications as State Machines
Functional web with clojure
Perl + pathfinder == <3
Reactive mistakes - ScalaDays Chicago 2017
Appstate

Similar to CQRS with Event Source in Functional sauce served by Kotlin (20)

PDF
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
PDF
Simplified Troubleshooting through API Scripting
PDF
Python master class 2
PDF
Advanced Android Fragments, Tom Opgenorth
PDF
Fine-Tuning Large Language Models with Declarative ML Orchestration - Shivay ...
PDF
Rubyslava slides-26.09.2013
PDF
Finite State Machine for Server Driven UI
PDF
Functional Programming in Ruby
PDF
Introduction to orchestration using Mcollective
PDF
Aljoscha Krettek - Portable stateful big data processing in Apache Beam
PDF
Unified stateful big data processing in Apache Beam (incubating)
PPTX
Distributed Transaction Management in Spring & JEE
ODP
Akka Finite State Machine
PPTX
Modern app development with Jetpack Compose.pptx
PDF
Stateful streaming data pipelines
PPTX
Life and Work of Jim Gray | Turing100@Persistent
PPTX
Deterministic behaviour and performance in trading systems
PDF
PuppetConf 2017: No Server Left Behind - Miguel Di Ciurcio Filho, Instruct
PDF
Big data Argentina meetup 2020-09: Intro to presto on docker
PPTX
Mgd finite statemachine
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
Simplified Troubleshooting through API Scripting
Python master class 2
Advanced Android Fragments, Tom Opgenorth
Fine-Tuning Large Language Models with Declarative ML Orchestration - Shivay ...
Rubyslava slides-26.09.2013
Finite State Machine for Server Driven UI
Functional Programming in Ruby
Introduction to orchestration using Mcollective
Aljoscha Krettek - Portable stateful big data processing in Apache Beam
Unified stateful big data processing in Apache Beam (incubating)
Distributed Transaction Management in Spring & JEE
Akka Finite State Machine
Modern app development with Jetpack Compose.pptx
Stateful streaming data pipelines
Life and Work of Jim Gray | Turing100@Persistent
Deterministic behaviour and performance in trading systems
PuppetConf 2017: No Server Left Behind - Miguel Di Ciurcio Filho, Instruct
Big data Argentina meetup 2020-09: Intro to presto on docker
Mgd finite statemachine
Ad

More from Uberto Barbini (9)

PDF
Go kotlin, Go!
PDF
It's All About Morphisms
PDF
Legacy is Good
PDF
The Role of Testing in DevOps
PDF
When Tdd Goes Awry (IAD 2013)
PDF
When Tdd Goes Awry
PDF
Boost your-oop-with-fp
PDF
The Effective Team
PDF
Develop Gwt application in TDD
Go kotlin, Go!
It's All About Morphisms
Legacy is Good
The Role of Testing in DevOps
When Tdd Goes Awry (IAD 2013)
When Tdd Goes Awry
Boost your-oop-with-fp
The Effective Team
Develop Gwt application in TDD
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
cuic standard and advanced reporting.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation theory and applications.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Programs and apps: productivity, graphics, security and other tools
Digital-Transformation-Roadmap-for-Companies.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
cuic standard and advanced reporting.pdf
Encapsulation_ Review paper, used for researhc scholars
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation theory and applications.pdf
MIND Revenue Release Quarter 2 2025 Press Release
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The AUB Centre for AI in Media Proposal.docx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Programs and apps: productivity, graphics, security and other tools

CQRS with Event Source in Functional sauce served by Kotlin