I'm trying to decide on the best way to structure data for the following scenario. I have 10000 sheep on a farm with 50 interconnected fields. I track each sheep when they enter and leave a field. I want to be able to:
- retrospectively analyse each sheep's movement over a given time period
- I also want to analyse each field's use over time
- instantly know which field any given sheep is currently in
- instantly know which sheep are in a given field
I've read the documentation about de-normalising the data and I appreciate that I can do anything using queries etc.
My question is: Should I duplicate the entry/exit data to sheep & field nodes like this?:
{
sightings: {
uniqueSheepId: {
FirebaseAutoId: {
type: enter
fieldId: uniqueFieldId
timestamp: xxxxxxxx.xxxxx
}
}
}
}
AND
{
sightings: {
uniqueFieldId: {
FirebaseAutoId: {
type: enter
sheepId: uniqueSheepId
timestamp: xxxxxxxx.xxxxx
}
}
}
}
This seems like a good way for getting a realtime snapshot of how many sheep are in any given field. It also allows us to easily see where a sheep is right now and where its been without doing any querying. Obviously the size of the dataset will grow twice the size than if I used queries but does the simplicity of getting the data outweigh the cost of storing the data?
I've seen (and understand) the chatroom/members examples on SO but I think my desire to retrospectively analyse membership/usage from both the sheep and field perspectives makes my question slightly different to those answers. Any advice would be great.