Hey, thanks for your responses, they've helped me to come up with a solution that might work but still hopeful for a better one.
Imagine it's an entire event/meetup solution with the ability to sort by date of event, namu, and creation time of the event. We'll be implementing sorting by distance from you but that'll be using Firbase geo examples.
Events also have attendees and which users will see the event in their list (we determine whether the event is likely to be suited to you and show it only if it is)
These indexes allow us to create a two-way relationship between events and the users who we determine will find the event relevant and should be shown it:
/event/index/userToEvent/{user_uid}/{event_uid}/ (value = true)
/event/index/eventToUser/{event_uid}/{user_uid}/ (value = true)
These indexes create a two-way relationship between events and the users that are attending:
/event/index/usersAttendingEvent/{user_uid}/{event_uid}/ (value = true)
/event/index/eventAttendees/{event_uid}/{user_uid}/ (value = true)
At the moment the priority of userToEvent is set to the creationTime so the user can see the events in order they were created.
As per the first post, we're wanting to sort by the startDate, and potentially some other keys so it seems likely I'll need to make the following amend:
/event/index/userToEvent/{user_uid}/{event_uid}/{startTime}
/event/index/userToEvent/{user_uid}/{event_uid}/{creationTime}
/event/index/userToEvent/{user_uid}/{event_uid}/{name}
I'm not overly concerned at the moment with how things will update in the iOS app at the moment - it's easy enough to resolve so we can leave how the user observes the events for changes.
My main concern is with how the data in Firebase will be updated.
It seems likely that we'll need to do the following:
- Given that titles and start dates are unlikely to change very often we could iterating through each user and updating the startTime/name...we'd use multiple workers to speed things up...thousands of users would take a large amount of time.
- In order to make sure each users index is actually updated (in case of a server crash) we need to keep a qyeye of pending updates
- We could make this very generic so that it could be applied to similar case.
e.g.
/updateQueue/events/{event_uid}/{user_uid}/startDate/ (value = true)
- The example tree structure would allow us to quickly replace an existing change of date with a new change of date.
- If a user opens the event before their index was updated, and we detect a change in the startDate/name we can update the index within the app and remove the item in the updateQueue.
The above will work pretty well but my concern is that this doesn't scale very well and any scaling will start costing a lot of money (all the additional workers).
So my question comes down to - is this the most optimal way to do something like this?
Thanks again!
Luke