How to match users randomly based on multiple preferences

Viewed 43

I am designing a backend that matches users randomly based on preferences.

There are four different types of preferences.

  1. All - Can match with any user
  2. Seven - Can only match with either "All" or "Seven"
  3. Eight - Can only match with either "All" or "Eight"
  4. Nine - Can only match with either "All" or "Nine".

I currently use the REDIS list data type to store users in a queue and match them.

My approach:

I am creating 4 lists for the preferences and then looking up each list and matching the users as per their needs.

queue:all
queue:seven
queue:eight
queue:nine

if user.pref == all

search - all
search - seven
search - eight
search - nine

if user.pref != all

search - all
search - pref

if queue is empty

queue:${pref}.push(user)  

The Problem:

The above approach looks pretty inefficient as I have to do multiple lookups for every user.

Is there a better way to do it? So that all of this can be done with a single lookup?

0 Answers
Related