1mg’s Data Stack Explained: How They Harness and Activate Unlimited, Real-time Data
Tags: android, ios, aws, rudderstack
Published: 2020-10-08 03:17:01

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zo3aeh4kkkbp9hkoxgyn.png)
<!-- wp:heading -->
<h2>Overview</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In this post we break down the data stack built by 1mg that allows them to harness unlimited, real-time data securely. We will also look at the tools they use to activate this data for their downstream analytics and personalization use-cases.</p>
<!-- /wp:paragraph -->

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

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

<!-- wp:heading -->
<h2>Who is 1mg?</h2>
<!-- /wp:heading -->

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

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

<!-- wp:paragraph -->
<p>1mg is an online platform that provides services for medical diagnostics, consultation, lab tests, and general healthcare. Every day, millions of users visit the 1mg website or use their apps to buy medicine, schedule time with doctors, or simply find helpful medical information.</p>
<!-- /wp:paragraph -->

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

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

<!-- wp:heading -->
<h2>1mg’s Customer Data Stack</h2>
<!-- /wp:heading -->

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

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

<!-- wp:list -->
<ul><li><strong>Data Collection and Synchronization</strong><ul><li><a href="http://www.rudderstack.com">RudderStack</a> SDKs, custom scripts</li></ul></li><li><strong>Data Transformation and Enrichment</strong><ul><li>SQL, RudderStack Transformations, AWS Athena</li></ul></li><li><strong>Data Lake and Downstream Databases&nbsp;</strong><ul><li>Amazon S3, Amazon Redshift, Apache Cassandra</li></ul></li><li><strong>BI and Cloud Toolset</strong><ul><li>Google Analytics, Lotame</li></ul></li><li><strong>Job Orchestration</strong><ul><li>Apache Kafka</li></ul></li></ul>
<!-- /wp:list -->

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

<!-- wp:heading -->
<h2>Data Challenges Faced by 1mg</h2>
<!-- /wp:heading -->

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

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

<!-- wp:paragraph -->
<p>1mg is completely data-driven. They use data for making decisions in every aspect of their business - including supply chain, marketing, and product development. With millions of daily users, 1mg collects an enormous amount of data. With such high volume and so many different data needs around the company, Utkarsh Gupta - Senior Engineer of the Data Science team at 1mg -&nbsp; and his data engineering team must manage a complex, technically demanding data pipeline.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>1mg faced two key challenges with respect to their overall data infrastructure:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li><strong>Secure, real-time collection of unstructured data</strong>:&nbsp;Most of the data collected by 1mg was unstructured, such as medical reports, emails, customer chats, etc. Collecting and storing this data without worrying about the data volume and pricing, while adhering to the data security regulations, was a major challenge for the data engineering team.</li><li><strong>Effective data activation</strong>: 1mg wanted to build a data workflow that utilized the unstructured data to gain critical insights into their customer journeys and for other product personalization use-cases.</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Let’s look at how the data engineering team at 1mg's data stack to address these concerns.</p>
<!-- /wp:paragraph -->

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

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

<!-- wp:heading -->
<h2>1mg’s Data Stack Explained</h2>
<!-- /wp:heading -->

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

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

<!-- wp:paragraph -->
<p>At a high level, here’s the flow of 1mg’s data stack:&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Event collection and routing happens via <strong>RudderStack</strong> Enterprise, leveraging the JavaScript and mobile SDKs. Note that RudderStack Enterprise is hosted in 1mg’s VPC to achieve maximum security and compliance, which is mandatory for healthcare companies.</li><li>1mg dumps all of the data into their <strong>Amazon S3 </strong>data lake. The events flowing through RudderStack, as well as data from the other sources, are routed to S3 for transformation and orchestration.</li><li><strong>AWS Athena</strong> is used to transform and enrich the data. This normalized data is then also batched to <strong>Redshift</strong> and <strong>Cassandra</strong> for 1mg’s downstream use-cases.</li><li>The events flowing through RudderStack are also sent to Firebase and Google Analytics directly for analytics and business intelligence, and <strong>Lotame</strong> for marketing activation.&nbsp;</li><li>The real-time events are also routed to <strong>Apache Kafka</strong>, which is used by 1mg’s data science team to optimize their product recommendation engine.</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Here’s a visualization of their data flow:&nbsp;</p>
<!-- /wp:paragraph -->

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

<!-- wp:image {"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://lh3.googleusercontent.com/sHyThUjeY0CUojKka3qczJbZu2xeo6-RCPysq_8esqIrYjigmOT0t58qjeYXTaLQCc5e2xDvA8h97FGOh8mM7_W1BsxlR4OOrOHYUF4QnrlvhTmZSqnOW3085dmh7CI08fuwH_jx" alt="1mg Data Flow Through RudderStack"/><figcaption>1mg Data Flow Through RudderStack</figcaption></figure></div>
<!-- /wp:image -->

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

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

<!-- wp:paragraph -->
<p>In the following sections, we delve into each aspect of the data flow in more detail, from collection to enrichment and analytics.</p>
<!-- /wp:paragraph -->

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

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

<!-- wp:heading -->
<h2>Data Collection and Storage</h2>
<!-- /wp:heading -->

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

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

<!-- wp:paragraph -->
<p>For data collection, 1mg deployed RudderStack in their own VPC, allowing them to:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Comply with the existing regulations around their healthcare data collection and storage</li><li>Overcome any limitations on the volume or type of data collection, without worrying about the pricing</li><li>Route any data to any team through their warehouse infrastructure, or directly to an end-destination for their downstream use-cases</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Most of 1mg’s data comes from their customers behavior, so the website and the mobile app are their primary data sources.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>1mg use RudderStack’s <a href="https://docs.rudderstack.com/rudderstack-sdk-integration-guides/rudderstack-javascript-sdk">JavaScript SDK</a> to collect real-time customer event data from their website. Through this SDK, they track all kinds of user behaviors, from pageviews to product views, clicks, checkout flows and more. They also leverage RudderStack’s identify() method to track new VS returning customers and drive personalization use cases.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For their mobile apps, 1mg used RudderStack’s <a href="https://docs.rudderstack.com/rudderstack-sdk-integration-guides/rudderstack-ios-sdk">iOS</a> and <a href="https://docs.rudderstack.com/rudderstack-sdk-integration-guides/rudderstack-android-sdk">Android</a> native SDKs to track and collect app events, and send them directly to Firebase and Lotame for the analytics and marketing use-cases. RudderStack sends the event data to these destinations via the <a href="https://docs.rudderstack.com/get-started/rudderstack-connection-modes#device-mode">device mode</a>. In other words, the RudderStack native SDK within the app automatically calls the destination APIs directly.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>1mg also collects data from various other sources. This data is mostly transactional,but also includes data from their API logs, microservices, CRM systems, and so on. 1mg have built a dedicated ETL pipeline to extract data from all of these data sources and push it to their <strong>Amazon S3</strong> data lake.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To move the transactional data from databases like MongoDB, PostgreSQL and MySQL, 1mg use AWS’s data migration service. Their data engineering team has also written custom scripts to pull data from clickstream sources such as Google BigQuery on a daily basis. Also, they've built a custom data pipeline that pushes data from various microservices and API logs to their S3 data lake.</p>
<!-- /wp:paragraph -->

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

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

<!-- wp:heading -->
<h2>Data Transformation, Enrichment, and Routing</h2>
<!-- /wp:heading -->

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

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

<!-- wp:paragraph -->
<p>The next step is to convert the raw data extracted from various sources into a usable format. For this transformation, 1mg uses <strong>AWS Athena</strong> - an interactive, serverless query service that allows them to normalize the raw data into usable, optimized data tables.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>All the major data transformations within the data lake happen in Athena. These include converting the data from JSON to a readable tabular format or joining different data lake tables. 1mg also uses Athena to store all the relevant metadata and schema information related to the tables residing in the data lake.</p>
<!-- /wp:paragraph -->

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

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

<!-- wp:heading -->
<h2>1mg’s Toolset for Downstream Use-cases</h2>
<!-- /wp:heading -->

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

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

<!-- wp:paragraph -->
<p>After the raw data is normalized, it is again pushed into the S3 data lake and also batched to other databases such as <strong>Amazon Redshift</strong> and <strong>Apache Cassandra</strong> for 1mg’s downstream use-cases.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>While all the data tables related to the business and product analytics use-cases reside in Redshift, Cassandra is used for storing the user and product personalization data. 1mg sends this data to third-party analytics tools such as <strong>Google Analytics</strong> for real-time insights and reports, which can be acted upon by their product and marketing teams for effective decision-making.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In addition to these tools, 1mg also leverages <strong>Apache Kafka</strong>'s real-time data processing capabilities for their recommendation use-cases. RudderStack supports Apache Kafka as a destination to which it sends real-time events from the 1mg web and mobile apps. Their data science team leverages this data to build and optimize 1mg's product recommendation engine, which recommends relevant product offerings to its customers.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The clickstream data sent to <strong>Lotame</strong> allows the 1mg teams to segment their users and get a 360-degree view on their customers' product and purchase journey. They can A/B test new product features and use the insights to revamp their website and drive more efficient customer acquisition programs. The product marketing teams also use the data to build more effective marketing campaigns that improve overall customer engagement and retention rates.</p>
<!-- /wp:paragraph -->

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

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

<!-- wp:heading -->
<h2>Summing it all up...</h2>
<!-- /wp:heading -->

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

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

<!-- wp:paragraph -->
<p>1mg has built a modern customer data stack capable of reliably handling immense scale. Not only have their real-time data products created better customer experiences, but Utkarsh’s team has helped build significant competitive advantage by enabling teams to move fast and optimize every part of the company.</p>
<!-- /wp:paragraph -->