3

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.

  • Why does there have to be a better way? What issue are you having with it? (Making too many calls to the DB? Why does that matter to you?) – Cody G Jan 29 '18 at 13:59
  • Yes I am concerned about too many calls to the DB @CodyG. – vijaykrishnavanshi Jan 29 '18 at 17:07
  • Okay, so why does that matter to you? I.e., Are you hitting a bottleneck? What kind of performance requirement are you trying to hit? What have you tested --- I.e. how many transactions have you proven you can write with Mongodb? Why isn't that enough? – Cody G Jan 29 '18 at 18:34
  • @CodyG. I am not hitting any bottle-neck. I just wanted 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. For this reason only, I have also mentioned what solution I have thought for the task. – vijaykrishnavanshi Jan 30 '18 at 04:37
  • Did you find a better solution? – fsljfke Aug 02 '20 at 08:28

1 Answers1

1

I don't know if this really solves your query but you could give it a try

  • Have a separate bloom filter to check if it is a match ... there can be false positives but since the majority will be 'not matched yet' this will save a lot of database queries
  • If it is not a match yet and you need to store the swiped up data entry, keep multiple such entries in memory/redis for a while and then bulk insert in the database
  • update bloom filter real-time (Note: there could be a momentary mismatch between bloom and database till the bulk insert is done.)
Vidur Khanna
  • 138
  • 7