I am trying to develop an application which replicates the tinder-like swipe based feed. The idea of the App is quite similar to tinder and also has swipe right and swipe left with match feature.
What I have done till now - I have created a swipe collection in MongoDB which stores the swipes by the user in the following schema -
swipedBy : {type:Schema.ObjectId},
swipedUser : {type:Schema.ObjectId},
status: {type:String, default:"left"}
When a user swipes right, I am making calls to DB. For each swipe insertion, I try to find whether a user has been swiped right by the other user before saying its a match or storing it in DB. There has to be a better way.
Possible Solution
I was looking to use In-Memory Database like Redis for storing similar info and finding the matches between the users based on swipes. If anyone can shed some light on how tinder does it, then also it will be helpful. My schema in Redis looks like this -
HSET for each user with
- userId as field, and
- status as swipe status
But the problem with this approach is that I will not be able to keep track whether the user has already swiped a particular person which is needed during the feed. One thing that can be done for this problem is I can update the collection and maintain a list of users already swiped.
If there is any other database/way that can help me in the process please suggest that also.
Edit:
I am not hitting any bottle-neck. I just want to confirm whether I am doing it right or not. Iterating through the list for finding out whether the user was swiped right by the other person is a linear time solution. I was wondering if I can do better than that, either through DB or something else that I should try out.