Mick Gow
 · UX Designer armed with a swiss army knife of skills

Best Database Design for Favorites

I've been going back and forth on which model will scale best for a likes/favorites section in my app.

I have narrowed it down to these options. Which would you choose and why?

MODEL 1 - favorites is it's own collection
3 x collections

Users
Photos
Favorites (each doc in this collection has a reference to the User and Photo that favorited)

Cons: Requires a separate query every time to call favorites, doesn't play well with built in icon-toggle components so will require using some custom conditional visibility and create/delete records for every favorite update

MODEL 2 - favorites are an array in photos collection
2 x collections
Users
Photos > Favorites is a list of user refernebces in the Photos document

Cons: Just not sure how well this will scale. What if 2000 users favorite one photo (Yes this will be common in my use case).
Pros: Simple just because it's already data easily accessed via a query to a photo. Plays well with the icon-toggle component.

MODEL 3 - favorites are a sub collection in the photos collection
2 x collections, 1 x sub collection
Users
Photos > Favorites is a sub collection in the Photos document

Cons: I'm not sure yes as I have not worked with sub-collections too much
Pros: probably more scalable than Model 2. Allows me to add extra data like the date it was favorited, etc. I've not tried this yet so don't know how well it works from other perspectives.

Let me know if anyone wants a visual to understand easier :)

1
7 replies