I want make a Tinder alternative. I think my match mechanism will cost too many database space. How to improve it?

259 Views Asked by At

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.
1

There are 1 best solutions below

1
bendzi On

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.