Identify natural persons with graph algorithms
This article explains how to use offline processing on traditional user login data to build a complex graph of relationships between users and devices. You can then run an offline graph algorithm on this graph to quickly and accurately identify a single natural person using multiple devices and accounts.
Background
Nearly every internet company needs to identify and track its users. Accurately identifying users allows you to collect personalized behavioral and identity data, such as which products they browse, videos they watch, or restaurants they visit. This data enables precise, personalized experiences in search, advertising, and recommendation systems.
First, you must identify your core data: user IDs, device IDs, and the data that links them. Start by extracting and reviewing your existing tracking data. During this process, you may encounter issues like incomplete data, weak relationships, or a lack of direct connections that require you to link and discover relationships across multiple data types. Thoroughly review your data source and document table names, data descriptions, extraction rules, data volume, and ID selection criteria. Most businesses use a single database table that contains various types of device IDs, internal account information, and other key details that can identify a user.
The following solution uses an example table named table_orgin:
trusted_id | app_id | oa_id | imei | ... |
Trusted device ID | Login/registration ID | Advertising identifier | Mobile device | ... |
Key characteristics:
1) The table has no unique primary key. Each ID can appear in multiple contexts, and device information may be duplicated.
2) Data storage is simple, but queries are complex.
Prepare relational data for graph analysis
To reliably aggregate device ID information, you need to transform the simple, wide table table_orgin into a device relationship table structured for graph analysis.
(1) Flatten multi-dimensional data
Create a new data table named table_create_device_id from table_orgin. This process flattens the multi-dimensional device types into a single device_id column and generates a primary key for each unique device. For this example, we will build the graph using four core device identifiers: trusted_id, app_id, oa_id, and imei.
INSERT overwrite table table_create_device_id PARTITION (ds='2023-11-11')
select device_id
from
(
select DISTINCT(trusted_id) as device_id from table_orgin
where dt = '2023-11-11' and trusted_id is not null
UNION
select DISTINCT(imei) as device_id from table_orgin
where dt = '2023-11-11' and imei is not null
UNION
select DISTINCT(oa_id) as device_id from table_orgin
where dt = '2023-11-11' and oa_id is not null
UNION
select DISTINCT(app_id) as device_id from table_orgin
where dt = '2023-11-11' and app_id is not null
);(2) Assign temporary IDs and create device_temp_id
INSERT overwrite table device_temp_id PARTITION (ds='2023-11-11')
select ROW_NUMBER() OVER(PARTITION BY ds ORDER BY device_id) AS id, device_id from table_create_device_id
where ds = '2023-11-11';(3) Create table_orgin_device_id
Map the various IDs in table_orgin to the primary key fields in the device table. For example, you map the trusted_id to its corresponding primary key id from the device_temp_id table.
trusted_id | app_id | oa_id | imei | trusted_id_key | app_id_key | oa_id_key | imei_key |
Trusted device ID | Login/registration ID | Advertising identifier | Mobile device |
INSERT overwrite table table_orgin_device_id PARTITION (ds='2023-01-02')
select trusted_id_key, oa_id_key, imei_key, app_id_key
from
(
select trusted_id, oa_id, imei, app_id from
table_orgin
where dt = '2023-11-11'
) A
left outer join
(
select id as imei_int, device_id from
device_temp_id
where ds = '2023-11-11'
) B
on A.imei = B.device_id
left outer join
(
select id as oa_id_int, device_id from
device_temp_id
where ds = '2023-11-11'
) C
on A.oa_id = C.device_id
left outer join
(
select id as trusted_id_int, device_id from
device_temp_id
where ds = '2023-11-11'
) D
on A.trusted_id = D.device_id
left outer join
(
select id as app_id_int, device_id from
device_temp_id
where ds = '2023-11-11'
) F
on A.app_id = F.device_id;(4) Data cleansing
This stage focuses on fundamental Extract, Transform, and Load (ETL) processes like data extraction, data cleansing, and fusion. The accuracy of this stage is critical and determines the success of the project.
1) ID cleansing: consider the following two points during ID cleansing to avoid significant issues:
Accuracy: Test repeatedly during the ID cleansing process to ensure high quality. Incorrect ID cleansing can compromise the completeness and accuracy of identity resolution, which has a major impact on downstream applications.
Consistency: Encapsulate the ID cleansing logic in a UDF to ensure consistency. You can implement this using a factory pattern to improve usability and reduce maintenance costs. For example, use the same function to cleanse both IMEI and IDFA by passing different parameters: udf_id_is_valid(imei, 'IMEI') and udf_id_is_valid(idfa, 'IDFA').
2) ID repair: Use expert rules and strategies to repair IDs. This process can salvage useful information and reduce the amount of dirty data. For example, you can remove trailing characters from an IMEI string.
(5) Establish vertex-edge relationships
Establish one-to-one relationships between the four core device identifiers to create a simple relationship table.
Aggregate device information with a graph algorithm
For this type of device information discovery, you can use a community detection graph algorithm called Weakly Connected Components. The Weakly Connected Components (WCC) algorithm finds sets of connected nodes in both directed and undirected graphs. If a path exists between two nodes, they are considered connected. A component is a set of all mutually connected nodes. Unlike a strongly connected component (SCC), the WCC algorithm does not consider the direction of relationships in the path between two nodes. For example, in a directed graph where (a)→(b), nodes a and b are in the same component even if the relationship (b)→(a) does not exist. This algorithm computes the component membership for each vertex. In the final output, each component is identified by the smallest vertex ID in that component. This ID is then propagated to all other vertices in the same component.
Prerequisites
Before you perform a full graph analysis, you need to create a Graph Compute instance and a graph configuration, and then import graph data by using either batch import or an API.
1) Click the link to create a Graph Compute service instance. During the early testing phase, you can select the Exclusive-Analytics specification to verify the features.
2. Create a graph configuration and ingest business data and configurations. For instructions, see the best practice Quickly Build a Friend Recommendation Graph Application Based on GraphCompute.
Graph algorithm configuration
1) Feature operations:
In the Graph Compute service, you can perform algorithm analysis by selecting an edge table in the graph for which Index Optimization is disabled. You do not need to configure a weight field.
2) Task execution:
Click the Run button in the graph algorithm configuration. A pop-up window appears to confirm the charges. Click OK to run the task. You can view the task run history by clicking Historical Tasks. This feature is currently in public beta and is free of charge.
3) Output:
After you click Save Configuration and successfully create a graph algorithm configuration, a new vertex is automatically created in the graph. The name of the new vertex is the export result that you specified at the bottom of the form. When a graph algorithm task runs successfully, its results are automatically written back to this result vertex. After the write-back process is complete, you can query the results online.
4. Online Query Results
Graph Compute provides an industry-leading, integrated process that allows you to easily query the analysis results of offline graph algorithms. You only need to enable a Graph Compute service instance to obtain a high-performance, integrated engine for querying and analyzing graph data. Compared to other industry solutions, the Graph Compute service is more convenient because it eliminates the need for you to manage your own data pipelines, making data flow more efficient.

The algorithm returns results in an inverted format, where the componentId field represents the connected component ID:
Use the inverted query syntax to query all vertices for a specified componentId: g("user_***_graph").V().hasLabel("your_result_table_name").indexQuery("{\"match\":{\"component_id\":\"2001\"}}")