Functional Kotlin - Simple Event Sourcing

Опубликовано: 21 Март 2026
на канале: Pairing with Duncan
2,498
58

Up until now we have been reading our stock list from a file that is managed by another system - Excel to be precise. We would like to bring that data into a database that we own, and at the same time make us more attractive to future employers if this startup fails. Enter Event Sourcing.

With Event Sourcing, instead of maintaining a database table of our stock, we store a list of the StockEvents - StockAdded, StockModified, StockRemoved. We then process the list of events to deduce the current list of items when we need to show it. This gives us a built-in audit trail, and allows us to correct mistakes or fix bugs more easily than if we modified entries in a table. As you'll see, it also gives us a place to process the complicated rules of magical item degradation rather than having to arrange a process to run once a day.

This episode is inspired by my reading of Uberto Barbini's upcoming book, From Objects to Functions - https://pragprog.com/titles/uboop/fro...

This is part 60 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist
   • All Gilded Rose Episodes  
and the code on GitHub
https://github.com/dmcg/gilded-rose-tdd

If you like this, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook
(http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.

I have some free time between producing videos and working for team Gilded Rose. If you like these videos I'd like to work with you - please get in touch - [email protected]