One Read Core, and the Code That Proves It
A generic core is easy to describe and hard to show. So here it is, with the parts I would not put in a talk. ๐ I'm Anton - a software engineer working mostly in PHP/Symfony and Go, carving a live PHP monolith into Go services. The previous piece was about why my code ended up on type parameters at all. This one is the code itself: the core, one instantiation of it, and a consumer that uses itโฆ
The core of the system is a single, generic type that encapsulates the concept of a bitemporal entity with history. This core is designed to handle any data type through a type parameter. It consists of six methods and a Spec struct, which defines the structure of the data columns for identity, payload, and version. The Spec struct is shared across the entire system and contains three column groups: the identity group, the payload group, and the version group.
These groups are fixed and do not change; they are simply positions within the Spec. The core's main methods are Current, AsOf, KnownAsOf, Append, Correct, and Close, each performing a specific function in managing the history of the entity. The Append method, in particular, ensures that every change is a new version row, with no destructive updates or physical deletes allowed.
This design ensures that every historical fact is preserved, and there is never a situation where data needs to be rewritten in the past. The system is implemented as a single, unified core that handles all entities uniformly, regardless of the domain they belong to.
Written by urgent.news from Dev.to's reporting โ not their text. Machine-written โ may contain errors; check the original before relying on it.