How could we implement a friend recommendation feature on the server

Hello ,
Hope all is well.


As mentioned in the Nakama’s docs portal, Server recommends friends they should. Is this algorithm already implemented or do we have to implement it manually?

Thanks
Siddhesh

Bumping this thread as currently we are urgently in need of this

I noticed similar feature request has been open few years back

@YoursTruly These queries are available with some of the customer projects that we’ve worked on and are not yet part of the open-source code. In the meantime you can achieve the queries you want with some custom SQL functions.

User Random Suggestion

A query to achieve this use case you can take advantage of the design of the user accounts system in Nakama which uses pseudo-random distribution of users via UUIDv4 types. The SQL uses a SEEK METHOD query to optimally select a pivot on the dataset in the btree index.

SELECT id FROM users WHERE id > gen_random_uuid() LIMIT 1000

You can then use a fallback query if the results returned don’t cover the range that you want.

SELECT id FROM users LIMIT 1000

Don’t forget to filter out the system user once you’ve got the results back from your query. (i.e. "00000000-0000-0000-0000-000000000000")

NOTE: The query above is optimized for PG13 but can be adjusted to work with other databases.

2 Likes

@novabyte Thank you for a reply and input.
We have achieved the friend recommendation by following way but I am not sure if its efficient:

Create list of friends
From Above list, list down friends of each friend
From above list. check which are already in our friend list and remove those from the list
Show remaining users for People you may know / Friend Recommendation

@YoursTruly This will not scale well as you increase the player base of the game. I would suggest you use the approach I mentioned above and I will also make sure that we prioritize the introduction of the recommendation API to the server soon. The code is done but we need to organize with a customer to be able to make it part of the open-source code.

Yeah scaling would be an issue with approach I have mentioned. We will wait for you to release the code :slight_smile:
Query you have suggested would solve the problem temporary but random user suggestion would be an issue. I guess, we need to add location as well so atleast players can get recommendation within their region.