Professional Documents
Culture Documents
Kotlin in Microservices Using DDD, Event Sourcing & CQRS
Kotlin in Microservices Using DDD, Event Sourcing & CQRS
Kotlin in Microservices Using DDD, Event Sourcing & CQRS
Marketing Frontend
Integration
Sales
Backend
Care
Payments
Insights Information
Integration
2. Kotlin
Designed by Jetbrains
Kotlin in production: Google, Pivotal, Uber, Atlassian, Coursera, etc
Statically typed
Modern
Drastically reduce the boilerplate
Java, Android
Javascript
Native
2. Kotlin
Data Class
toString
equals
hashCode
copy
properties - get/set
2. Kotlin
Lambda
🤢
Java
😎
Kotlin
2. Kotlin
High order function Tacit programming: let, also, apply, run, with
Infix Tailrec
Internal …
3. Event Sourcing & CQRS
all operations on the system are stream event-oriented: nothing happens before the
event being committed
CQRS
Command (accept/reject)
Change state
Events
Query (views)
Are free of side effects
3. Event Sourcing & CQRS
Motivation
ES, CQRS
Clients: Bank, Telecom
Audit Log (query the past)
Insights
Multiple views (Multi-Tenant)
Catalog Catalog
Manager Search
Catalog
Search
Low write High read
latency latency
Catalog
Manager
Catalog
Processor
3. Event Sourcing & CQRS
Code
3. Event Sourcing & CQRS
3. Event Sourcing & CQRS
DDD
Command Bus
3. Event Sourcing & CQRS
Command Bus ✔ ❌
Bounded Context
3. Event Sourcing & CQRS
Command Bus
First Command
DDD
3. Event Sourcing & CQRS
3. Event Sourcing & CQRS
Command Bus ❌
Not here yet!!!
3. Event Sourcing & CQRS
Command Bus
⚠ Replay for all past events will start for this ID before
this Command executes
3. Event Sourcing & CQRS
1 - Replay
3. Event Sourcing & CQRS
1 - Replay
2 - Accepts/Rejects
3. Event Sourcing & CQRS
1 - Replay
2 - Accepts/Rejects
3 - Accepted
3. Event Sourcing & CQRS
Catalog
Processor
3. Event Sourcing & CQRS
3. Event Sourcing & CQRS
3. Event Sourcing & CQRS
3. Event Sourcing & CQRS
Catalog
Search
3. Event Sourcing & CQRS
B F Catalog
Search
C
D
E
Catalog 1
Catalog 2
Micro Services Catalog 3
Catalog n
3. Event Sourcing & CQRS
Conclusion
😌
3. Event Sourcing & CQRS
🔥
Burn down
Conclusion
😌
3. Event Sourcing & CQRS
TODO
snapshots
🏗
sagas
Replay
Conclusion
😌 recovery
fix inconsistency
build a new view
4. Kotlin, DDD, ES & CQRS
Motivation
Kotlin
Events (immutable) (Axon)
Catalog v1
Data class (boilerplate)
Event Stream
lambda
Modern
Easy to learn
…
4. Kotlin, DDD, ES & CQRS
Final
4. Kotlin, DDD, ES & CQRS
Events (Event Store Database)
4. Kotlin, DDD, ES & CQRS
Events (Event Store Database)
4. Kotlin, DDD, ES & CQRS
Value Objects - data class
Typesafe
Primitive Obsession
Invalid Objects
Immutability
4. Kotlin, DDD, ES & CQRS
Anemic Domain Model - kotlin extensions
Only Getters / Setters
Services Layers are OVER ABUSED!!!
😎
5. Kotlin 102
Tests
5. Kotlin 102
Coroutines
asynchronous programming
experimental != unsecurity
5. Kotlin 102
Coroutines
Coroutines
😱
5. Kotlin 102
Coroutines - async/await
5. Kotlin 102
FOLD HELL
5. Kotlin 102
Either foldCompose
5. Kotlin 102
Either foldCompose
ping-pong effect
E.g. Payments Retry
😞
5. Kotlin 102
Either foldCompose
ping-pong effect
😇
5. Kotlin 102
Either foldCompose
ping-pong effect
😎
5. Kotlin 102
Remote I/O
✔
❌
❌
5. Kotlin 102
sync {}
async {}
5. Kotlin 102
runBlocking
5. Kotlin 102
zkotlin
Couroutines/Ext. Methods
5. Kotlin 102
Conclusion
Higher-order functions
Sugar syntax (it, ƛ as last parameter)
Less boilerplate
😌
a nicer syntax to compose Either pattern
Spock Mockito
6. Kotlin, Java & Legacy
SpringBoot - allopen
final
6. Kotlin, Java & Legacy
JPA
6. Kotlin, Java & Legacy
540+ Zuppers.
BH MG
UI / UX / R&D / Uberlândia MG
DEV UI / UX / R&D / DEV / SUPPORT
Lisboa, Portugal
SALES / CONSULTING /
Ribeirão Preto SP R&D
UI/UX/DESIGN
São José do Rio
Preto SP São Paulo SP
DEV SALES / CONSULTING /
PMO / REQUIREMENTS
Joinville SC UI/UX
R&D