-1

I want make a social app like Tinder. I will use firebase Auth & firestore.

My match mechanism is:

  1. Every user data will saved in a individual firestore doc.
  2. In user data, will save "like" and "dontLike" field, both type are array.
  3. Each array will save user ID in it.
  4. When user A click like user B, My server will get the user B data.
  5. Check is user A's ID in user B's like array? If true, then A and B will be friend.

Problem:

I predict when user click more like or dontLike. The like array and dontLike array in firestore will grow bigger and bigger. This may cause the fee of firestore bigger and bigger.

The ideal result I want:

  1. The way to prevent the like array and dontLike array in firestore grow bigger and bigger.
  2. Or any smarter way to match A and B user.
Kody Liou
  • 113
  • 2
  • 12
  • The edit to my match mechanism's step 3: When user A click user B's like or don't like button ,server will add user B's ID to user A's like or dontLike array. – Kody Liou Oct 14 '21 at 21:53
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Oct 17 '21 at 14:09

1 Answers1

0

It looks like you are thinking too far ahead, I don't think this is a realistic problem to worry about. Spend more time implementing new features. One of the main advantages of serverless approach is that you don't have to worry about performance or costs untill you reach a really big scale.

Having said that, I would consider dropping the dontLike array since you probably won't need it anyway. If you want to keep track of number of likes or dislikes, just keep a counter as an int in document. But if you can think of a legitimate usecase for this data, keep it. Also, instead of an array you could use a hash map instead. This is because in order to find a match you would potentially need to iterate over the entire array. However you most likely won't reach the scale when it would actually matter, so keeping it as an array would be just fine.

bendzi
  • 13
  • 2
  • I think dontLike array will necessary because if user A click don't like button to user B, user B will never show up to user A again. – Kody Liou Oct 14 '21 at 22:05