The Tale of Identity Graph and Identity Resolution
Tags: opensource, android, ios, rudderstack
Published: 2020-05-22 07:13:47

<!-- wp:paragraph -->
<p>In our&nbsp;previous article&nbsp;on <a href="https://rudderstack.com/blog/rudderstack-case-study-casino-game-analytics/">Game Analytics for Mobil</a>e, we showed how to build an open-source analytics solution using&nbsp;<a rel="noreferrer noopener" target="_blank" href="http://www.rudderstack.com">RudderStack</a>. As highlighted in the article, understanding users is crucial to every analysis. Hence, it is essential to tie the events or activities to the individual users generating those events. Analytics platforms help collect this data. Unfortunately, this is not trivial in the world where users often browse anonymously or use multiple identities (e.g., email, phone) with the same product or access from different devices and channels. The problem of ID resolution is to able to tie these different identities together whenever possible in a privacy-preserving way. An identity graph helps to understand these relationships better.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This blog is a part of a two-part series on this topic. The first part describes the problem, while the second part describes possible approaches to solve it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>A Real-Life Scenario</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To motivate the problem further, consider a sample journey of a user on an eCommerce platform.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>The user comes to the website on this laptop, browses certain products&nbsp;<em>anonymously</em>, and drops off without making a purchase.</li><li>He installs the eCommerce application on his mobile device, logs in by providing his&nbsp;<em>phone number</em>&nbsp;but leaves without making a purchase.</li><li>The user comes back on the website and makes a purchase. During this checkout process, he registers with his&nbsp;<em>email</em>&nbsp;and provides his&nbsp;<em>phone number</em>&nbsp;to receive notifications. </li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Different User Identifiers</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Let's say the eCommerce platform is using a CDP such as RudderStack to collect all the user activity data. Also, the eCommerce platform uses RudderStack dumps this data into a warehouse, such as Snowflake. Every event is associated with a&nbsp;<em>user identifier</em>. The user identifier could either be explicitly set by the application or auto-assigned by RudderStack or both. For example, in the above event sequence, the following identifiers will be used:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><strong>Step 1</strong>: Since the user hasn't provided any user identifier, RudderStack will associate an&nbsp;<code>anonymousID</code>.<em>&nbsp;</em>Let's say<em>&nbsp;</em><code>A-Web</code>: <code>A</code> stands for anonymous. After this, RudderStack will save this ID as a cookie. All events will be associated with the&nbsp;<code>A-Web</code>. RudderStack will dump the events in the data warehouse with <code>A-Web</code> as the user ID.</li><li><strong>Step 2</strong>: Similar to the above, RudderStack will create an ID in the mobile device. Let's call it&nbsp;&nbsp;<code>A-Mob</code>&nbsp;and save it in local storage. All events before the user signing up will be associated with&nbsp;<code>A-Mob</code>.&nbsp;Once the user logs in with his phone number (<code>U-Phone</code><em>)</em>, we will be able to associate the two identifiers. We will know that the ID&nbsp;<code>A-Mob</code>&nbsp;and the phone number&nbsp;<code>U-Phone</code>&nbsp;belong to the same user entity.</li></ul>
<!-- /wp:list -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p><strong>Note</strong>: RudderStack doesn't automatically capture the phone - the eCommerce application would have to explicitly set it via the&nbsp;<code>identify()</code>&nbsp;call and pass the ID&nbsp;<code>U-Phone</code>.&nbsp;The <code>identify()</code> call forms an association between the two IDs,&nbsp;<code>U-Phone</code> and <code>A-Mobile</code>.&nbsp;RudderStack can, in turn, save this association into the data warehouse.</p></blockquote>
<!-- /wp:quote -->

<!-- wp:list -->
<ul><li><strong>Step 3</strong>: Similar to Step 2, RudderStack will associate the events with the automatically assigned ID&nbsp;<code>A-Web</code>. Later, when the user provides the email (<code>U-Email</code>) and phone number (<code>U-Phone</code>), RudderStack will associate those with the ID&nbsp;<code>A-Web</code><strong>&nbsp;</strong>using the <code>identify()</code> call.</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>The Identity Graph</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The following diagram captures the association formed by the above IDs. The&nbsp;<code>identify()</code>&nbsp;call creates the edge in a graph, as explained earlier. The diagram indicates that these two IDs are known to be associated with the same end-user. The nodes represent identities, while the edges represent associations between IDs. For example, we know that <code>anonymousID</code> assigned by RudderStack (<code>A-Web</code>) and the user email address (<code>U-Email</code>) are the same when the user logs in with his email.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":27003,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://rudderstack.com/wp-content/uploads/2020/05/Image-1.png" alt="" class="wp-image-27003"/><figcaption>Identity graph at the end of steps 1-3. <br></figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>One should be able to associate all the web events (collected in steps 1 and 3) and the mobile-events (collected in step 2) as originating from the single end-user. One way to achieve that is to create a mapping between all these individual IDs (<code>A-Web</code>, <code>A-Mob</code>, <code>U-Phone</code>, and <code>U-Email</code>)<em>&nbsp;</em>into a single<em>&nbsp;</em>virtual user ID. You can associate&nbsp;all the events with this virtual user ID. You can do this by doing a JOIN between the event table (which has the individual IDs) and the ID to the virtual ID mapping table.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>The Identity Graph is not Static</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This identity association can evolve over time. Let's say the user comes to the same eCommerce site on a third device - his office desktop. If he does not sync the cookies between his laptop and office desktop, the system will associate the third ID with him. Let us call this third ID <code>A-Web2</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":27004,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://rudderstack.com/wp-content/uploads/2020/05/Image-2.png" alt="" class="wp-image-27004"/><figcaption>Identity Association with A-Web2</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>At this point, we don’t know if this ID (<code>A-Web2</code>) is associated with the same person. However, once he logs in with this email, the association will be formed, as shown in the updated graph below.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":27005,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://rudderstack.com/wp-content/uploads/2020/05/Image-3.png" alt="" class="wp-image-27005"/><figcaption>Identity Association with A-Web2</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Assigning Virtual IDs</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The goal of ID resolution is to take an identity graph as above and associate virtual user IDs with all the nodes. This association is such that nodes that are connected to each other either directly or indirectly (via intermediate nodes) are assigned the same virtual ID.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><br>You can achieve this by running the connected component algorithm on the identity graph. A connected component algorithm starts from a random node and runs a graph traversal algorithm (such as depth-first-search or breadth-first-search) to identify all the nodes reachable from the start node. Since all these nodes are connected, the system needs to assign them the same virtual user ID. The algorithm then repeats starting from another node not touched in the previous traversal and so on. This method is pretty efficient and scales linearly with the size of the graph.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In the case of most real-life applications, the graph can be huge with tens or even hundreds of millions of nodes. For example, one of RudderStack’s customers has ~80 million nodes (corresponding to ~40M users). Also, this number is scaling rapidly. At that volume, the customer typically stores the ID graph in a data-warehouse such as Snowflake/Redshift. Users can also choose to store this high-volume data on a data lake like S3 or HDFS. The preferred option, in that case, is to run the connected component algorithm using a query language. Warehouses natively support these query languages, which are usually some variant of SQL.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><br>SQL, however, is not a procedural language and does not have native support for basic abstractions such as looping and branching. The SQL dialect these warehouses support is often an even further restricted version. These dialects do not support self JOINs, cartesian products, and so on. As a result, the SQL dialects make it nonobvious to implement the connected component algorithm.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><br>That’s for now :) In the next blog post, we will discuss a solution for finding connected components using SQL.</p>
<!-- /wp:paragraph -->