This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
Hey I’ve got a question: let’s say I’ve a big monolith and I want to break apart some components out of it. What happens if I end up with AR models belonging to different components but associated one to each other? How would you tackle that particular issue?
We don’t allow AR models across boundaries - therefore we have broken associations (and foreign keys) and replaced them with service calls that return POROs (plain old ruby objects)
but what if I need to have JOIN statements for tables (AR models) that belong to different components? You put the query on the component of the “root” model for the query?
that feels to me (warning, gross generalization coming) like those things are ‘core’ kinds of concepts that should be codified into services easily accessible by all the other components
Right back at you. And indeed at Root Insurance you can imagine a Policy is a pretty common concept used in all other components - but we return a PORO policy object that hides some of the internal complexity of a true Policy AR
that is a end goal - we aren’t there yet. but eventually all components will be isolated to their own DBs - and under test a component will only create its DB to enforce this rule
One reality is that you might have a table that just happens to exist in both components with the same name, even though different (even slightly).
This is really hard to see in a Rails monolith. And hard to code too without introducing coupling.
What Scott suggests brings you there, then you can end up with (piggy backing on previous examples) “Policy” in one component and “Policy” in another component, but they are indeed different tables (and they could be not in sync, if one system is slow) with different data.
The source of truth would be the published event, so the tables are just “read data” at that point.
It’s a long trip there, but it solves the coupling problem permanently.
With HTTP APIs and introducing API interactions through queries, what usually happen is having a database replicated at the HTTP layer with similar problems as before, plus the need for HTTP Authentication and dealing with downtimes of other systems