I have a grid of values, something like
[
[0,3,1],
[0,2,5],
[1,0,3],
]
I have objects that move on that grid, so they have positions
{
x: 1.87,
y: 1.21
}
If we check the upper grid, then the nearest grid point to that position is {x:2,y:1}
, so with the simplest algorithm the value for that position is 5
on the grid. Another algorithm would be using distance based weighted average for the nearest 4 grid points.
I update the positions and the grid regularly with 12min and 30min intervals. I get the positions from the clients and I get the grid from an external service. In both cases the values can change for an object. Each object has a different threshold for the value, and when the value reaches the threshold a notification should happen. In reality the condition for the notification is a lot more complex, but I'd like to keep it simple.
The moving objects have other aspects, that don't depend on the grid like the values do.
I thought that having a Grid
aggregate root and Grid.update(values)
, Grid.move(objectId, position)
would be a nice solution, but I am a little bit confused. As far as I remember the aggregate root has a consistency boundary, so every time I update an object or I update the grid, I have to lock all grid data and object data for updating instead of just locking the grid or the object data separately. Not sure where I read that, it was many years ago. In this case only the object values are dependent on the grid and when a position changes for a single object, then that does not affect the grid or the other objects, just the value for the actual object. So if I remember well about what an aggregate root means, this design would not be a good one. Doing the other way around and making the Object
aggregate root does not seem good either, because I update the grid data independently from the object positions, values and other properties and it does not feel right to cover it with the Object
. Should I make both Grid
and Object
aggregate roots, or what is the proper domain model for this? Should the model contain the intervals I use for updating the grid and/or the positions, or should those exist outside of the model?