F
F
FlameArt2020-12-23 19:34:19
Database
FlameArt, 2020-12-23 19:34:19

How to test Theory 6 handshakes in a database with millions of users?

There is a table with a list of people, there is a many-to-many table with "friendship" between one and the second, there are millions of people, each has up to 5k connections

How to check that one user can be a distant friend of the second in 6 connections so that it can be calculated in realtime? Brute-force search obviously will not work: the number of requests already on the second connection is greatly increasing. Caching some separate pieces of the graph for each user is just as expensive as considering it a complete enumeration.

A couple of years ago, VK rolled out such a function and everything worked there instantly (> 40 million users), it became interesting: how did they do it?
Or maybe for friends there is some more interesting database architecture in which this can be solved easier

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
Dimonchik, 2020-12-23
@dimonchik2013

graph database
neo4j - the most famous
ArangoDB - will suit you

M
mayton2019, 2020-12-24
@mayton2019

Since this is a task from graph theory, then it needs to be solved in development languages ​​and graph support libraries. 1 million graph nodes is not much for modern memory.
From java libraries there are Guava, Jung, GraphT.

A
Alexander Vorona, 2020-12-24
@AlexandrVorona

A. Downey - Learning Complex Systems with Python - 2019
Chapter 3 Small World Graphs

N
Ndochp, 2020-12-24
@Ndochp

1. You need to walk from 2 sides
2. If you don’t fit into your memory, then you should walk in “depth”, and not in width. (search starting from the most "loving") (remembering that you need to "get" not into the second, but into one of his connections, it's easier)
In addition:
Step 0: 1 person
Step 1: 5000 maximum
Step 2: 25,000,000 maximum
Step 3: 40,000,000 maximum -
3 requests came up against it, the plates are theoretically large, practically - all this is ground without problems.

D
DDwrt100, 2020-12-24
@DDwrt100

Choose the right tool. In this case, upload the data to the graph database. And in it to shortchange a similar task.

D
Developer, 2020-12-24
@samodum

In my opinion, Donald Knuth considered the solution to this problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question