<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sanjay T on Medium]]></title>
        <description><![CDATA[Stories by Sanjay T on Medium]]></description>
        <link>https://medium.com/@sanjaythillaivasan?source=rss-c630153ff6a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eLeEzqjvV1DPCUh_UqJ_aA.jpeg</url>
            <title>Stories by Sanjay T on Medium</title>
            <link>https://medium.com/@sanjaythillaivasan?source=rss-c630153ff6a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:02:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanjaythillaivasan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scaling Apache Spark Pipelines from 2TB/day to 100TB/day]]></title>
            <link>https://medium.com/@sanjaythillaivasan/scaling-apache-spark-pipelines-from-2tb-day-to-100tb-day-f842f243f8ec?source=rss-c630153ff6a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f842f243f8ec</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[scale]]></category>
            <dc:creator><![CDATA[Sanjay T]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 12:06:41 GMT</pubDate>
            <atom:updated>2023-01-17T12:06:41.914Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog post, we will discuss some of the key things which we did in Microsoft for scaling Spark pipelines from 2 TB/day to 100 TB/day and solving the “small file problem”, a common issue in distributed systems where a large number of small files are stored in a single directory. This can lead to poor performance and scalability, as the system may have to process a large number of small files individually, resulting in a high overhead. In our old flow, we had 33,000 partition files created in uneven size for total volume 2TB, which caused us high overhead and read latency. In Microsoft, we had Spark pipelines ingesting around 2 TB/day and we had to find a way to handle the large scale data processing effectively.</p><p><strong>High Level Design</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*g3IQrWImH8QGviTVGsV-UQ.png" /><figcaption>High Level Design</figcaption></figure><ol><li><strong>Data Skew/Volume Controller</strong></li></ol><p>A volume controller is a mechanism used to control the amount of data that is processed by a distributed system at a given time. In this process, we first crawl the input data from file system. We then split the data based on Spark’s maximum processing capacity, which is set at 3TB. The split data is then written to file system, along with its metadata. For instance, if the input data is 60 TB and the Spark maximum capacity is 3 TB, the data will be split into twenty parts, with the corresponding metadata being written to file system for each part. This approach ensures that we are utilizing Spark’s processing capacity to the fullest while also effectively managing the input data.</p><pre>+------+-----------+--------------------+----------+-------------+-------------+<br>|job_id|file_length|file_length_in_bytes|job_status| job_duration|file_name<br>+------+-----------+--------------------+----------+-------------+-------------+<br>|     0|     3.0 TB|       3300060593918|   SUCCESS|0d 0h 34m 34s|xyz://...<br>|     1|     3.0 TB|       3299862386914|   SUCCESS|0d 0h 36m 35s|xyz://...<br>|     2|     3.0 TB|       3299215839486|   SUCCESS|0d 0h 33m 34s|xyz://...<br>|     3|    3.01 TB|       3304962001028|   SUCCESS|0d 0h 34m 35s|xyz://...<br>|     4|     3.0 TB|       3302443003370|   SUCCESS| 0d 0h 31m 3s|xyz://...<br>|     5|     3.0 TB|       3302632732504|   SUCCESS|0d 0h 30m 36s|xyz://...<br>|     6|    3.01 TB|       3312421117235|   SUCCESS|0d 0h 31m 34s|xyz://...<br>|     7|    3.01 TB|       3306441620772|   SUCCESS|0d 0h 30m 34s|xyz://...<br>|     8|     3.0 TB|       3299173569442|   SUCCESS|0d 0h 29m 33s|xyz://...<br>|     9|    3.01 TB|       3311540162160|   SUCCESS|0d 0h 41m 34s|xyz://...<br>|    10|    3.01 TB|       3306861953539|   SUCCESS| 0d 0h 32m 3s|xyz://...<br>|    11|    3.01 TB|       3305611970026|   SUCCESS|0d 0h 38m 35s|xyz://...<br>|    12|    3.01 TB|       3307169323492|   SUCCESS|0d 0h 33m 35s|xyz://...<br>|    13|     3.0 TB|       3298818008584|      null|         null|xyz://...<br>|    14|    3.01 TB|       3308904479951|      null|         null|xyz://...<br>|    15|     3.0 TB|       3303525154572|      null|         null|xyz://...<br>|    16|    1.44 TB|       1578852616190|      null|         null|xyz://...</pre><p><strong>2. Orchestrator</strong></p><p>In this process, Orchestrator first retrieve the metadata from file system. For each entry in the metadata file, a Spark activity is initiated by the orchestrator. The progress of the activity is tracked and the status is updated in the metadata as either Success or Failed, along with the duration of the activity. This approach allows us to efficiently process the data by utilizing the metadata and also keep track of the progress and outcome of each Spark activity.</p><p>The rerun scenarios for our pipeline are designed to be efficient and intelligent. The orchestrator is programmed to only trigger processing from the last checkpoint, which allows for faster and more efficient processing. Additionally, jobs that have already been marked as successful will not be retriggered, ensuring that resources are used effectively. Furthermore, once a job that previously failed is now successful, the status in the metadata file will be updated accordingly, keeping track of the progress and outcome of each job.</p><p><strong>3. Capacity Planning</strong></p><p>Capacity planning is a crucial aspect of scaling our system. Initially, we had x worker nodes that were able to handle data ingestion of 2 TB/day. Instead of increasing the number of nodes, which would have added to our operational costs, we developed a design that allows us to reutilize the existing resources. This approach enabled us to scale our system effectively while keeping operational costs to a minimum.</p><p><strong>4. Small file Problem</strong></p><p>Repartitioning by range using the repartitionByRange method helped us to solve the small file problem by merging a large number of small files into a smaller number of larger files. This is done by redistributing the data in a DataFrame or RDD across a specified number of partitions based on the range of values in a specified column.</p><p>For example, if you have a directory with 100 small files and you want to merge them into 10 larger files, you can use repartitionByRange to redistribute the data across 10 partitions based on a specified column. Each partition will then contain a portion of the data from the original small files, resulting in 10 larger files. This can greatly improve the performance and scalability of the system, as it reduces the number of small files that need to be processed individually.</p><p>It’s also important to note that this method is also useful when working with a dataset that has a skewed distribution, by redistributing the data evenly across the partitions, it can also help to solve this problem.</p><p><strong>5.</strong> <strong>Compression</strong></p><p>Compression is an effective technique for reducing the amount of disk I/O required when reading and writing data. By using a compression codec like GZIP or Snappy, we can greatly reduce the amount of storage space needed to handle large amounts of data. Spark supports reading and writing data in compressed format, which can be done on-the-fly during the reading or writing process. In our Spark pipelines, we already had GZIP compression in our old/existing flow when writing data to the file system, which resulted in a 60% reduction in storage when handling 100 TB/day input data. This not only saved us on storage costs but also improved the performance of our pipeline.</p><p><strong>6. Monitoring and Alerts</strong></p><p>As our pipeline scales up, monitoring the performance of the application and cluster becomes increasingly important to ensure smooth operation. To achieve this, we have implemented dashboards and alerts to monitor the daily runs and detect any discrepancies. This allows us to quickly identify and address any issues that may arise, ensuring that the pipeline is running at optimal performance.</p><p><strong>7. Results/Outcome</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ccVVKJnSLUu2p-owbMjhaA.png" /></figure><ul><li>We successfully scaled up our data ingestion in the Spark pipeline, increasing the processing capacity from 2 TB/day per region to 110 TB/day.</li><li>The number of partition files created in old flow was 33k whereas new flow created 6k files in file system.</li><li>The overall data reading capacity also increased, reaching 231 TB uncompressed and 120 TB compressed where we reduced latency to 60%</li><li>“Reduced Failure blast radius” refers to the idea of limiting the impact of a failure in the pipeline. Instead of having the entire pipeline fail if one part of it fails, the pipeline is designed to only re-run the specific chunks that have failed to process. This way, the pipeline can continue to process the rest of the data and reduce the overall impact of the failure.</li><li>“Checkpointing” is a technique that can be used in conjunction with “Reduced Failure blast radius” to improve the recoverability of the pipeline. With checkpointing, the pipeline can keep track of its progress and save the state of the pipeline at specific points, called checkpoints. In case of a failure, the pipeline can be restarted from the last checkpoint, and only the chunks of data that have not been processed yet will need to be re-run. This helped us to reduce the overall impact of the failure and improve the recoverability of the pipeline.</li></ul><p>In this blog post, we delved into the challenges and solutions we implemented at Microsoft to scale our Spark pipelines from 2 TB/day to 100 TB/day. This effort was a collaboration between engineers Sanjay Thillaivasan, Abhijit Dutta, Isha Waghulde and Rachit Kumar, and project managers Shivam Gupta and Tarunima Tripathi.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f842f243f8ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design ML Model & Code Deployment System]]></title>
            <link>https://medium.com/walmartglobaltech/design-ml-model-code-deployment-system-e1f2f8404786?source=rss-c630153ff6a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1f2f8404786</guid>
            <category><![CDATA[rest]]></category>
            <category><![CDATA[system-design-project]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[blob-storage]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Sanjay T]]></dc:creator>
            <pubDate>Thu, 03 Jun 2021 05:08:58 GMT</pubDate>
            <atom:updated>2021-06-03T05:08:58.037Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we will talk about the design of ML Model and Code Deployment system in multi-regional data center with archival, disaster recovery, less latency and multi instance deployment. We have created this product as One-Click Deployment System to accelerate the ML models &amp; code deployment to production faster in Walmart Search.</p><blockquote><strong>Functional Requirements:</strong><br> User should be able to deploy code and ML model from UI.</blockquote><blockquote>Different models can be deployed to multi instance in single environment. Say, for environment dev, there can be different models in every instance.</blockquote><blockquote>Model Storage should be archived in blob store.</blockquote><blockquote>Disaster discovery should be enabled in case of any distributed blob store going down.</blockquote><blockquote><strong>Non-Functional Requirements:</strong></blockquote><blockquote>Upload and Download latency of model and package to distributed blob store should be very low. Should be within 1 min approx.</blockquote><blockquote>Number of daily deployments will be 100.</blockquote><blockquote>Deployment Service should be highly available.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*x7xzao-Y_x0rea5sprrntw.png" /></figure><h4>User Flow:</h4><p>As per the below image, the developer can select the endpoint/instance which he/she prefers to deploy in dev/stage/prod environment. This will in turn will pushes the model and package to blob storage (blob store).</p><h4><strong>Capacity Estimation:</strong></h4><p>Normally Machine Learnt model binary files are huge in size.</p><p>ML Model and package file size : <strong>4 GB</strong></p><p>No of deployments handled by search services daily : <strong>100</strong></p><p>No of environments (dev, stage and prod) : <strong>3</strong></p><p>Blob Store Storage for one month : <strong>4 GB * 100 * 30 * 3=~ 36 TB</strong></p><p>Storage for three DataCenters for west, south, east (disaster recovery)=~ <strong>36 TB * 3 = 108 TB</strong></p><p>Storage for one year =<strong> 108 TB * 12 = 1296 TB =~ 1.2 PB </strong>(we will revisit this again in Archival process)</p><h4><strong>High Level Design:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*lDDua4k82L79bYLN_A03Gw.png" /><figcaption>High Level Design — 10000 feet overview</figcaption></figure><h4>API Design:</h4><p>Deploy API: POST /deploy/:modelName/:modelVersion?dataCenter=dc-all&amp;endpoint=variant-2</p><p>UnDeploy API: POST<strong> /</strong>undeploy/:modelName/:modelVersion?dataCenter=dc-all&amp;endpoint=variant-2</p><h4><strong>Database Design:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*pRzKth1zangqQgRVlELZRA.png" /></figure><p>We use CloudSql to store the metadata of the deployments. On Deploy/Undeploy API call, we will create an entry to store the deployments. This will help us to track the history, status, failure, workflow failure, user details of the deployments.</p><p>We use blob storage for ML model and package storage. To make it as highly available and avoid Single point of failure, we have blob store replicas in three regions (south, west and east blob store).</p><h4><strong>Algo Design:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ujpvp7Uh6Pxt_9dNOAjm0A.jpeg" /></figure><p><strong>Deploy API Flow:</strong></p><p>When the user clicks on Deploy in client UI with environments and instance, then we will use our Deploy API to trigger workflow (airflow DAG) asynchronously which pushes the models and package to blob storage of all three regions. If model and package failed to store in any of the region blob store, then the deployment will be stopped/failed.We will store the metadata of that deployment into application.properties in blob store. In this case, the file will have model name and version of that deployment in the below path of blob store of all three regions. We will update the deployment status in the Metadata DB to <strong>LIVE / DEPLOYED </strong>after the deployment workflow completed successfully</p><p><strong>Directory path : </strong>Container / data/ model_name/env / application.properties</p><p>Example: <a href="https://portal.azure.com/">s</a>earch / <a href="https://portal.azure.com/">data</a> / reranking_model / <a href="https://portal.azure.com/">dev</a> / application.properties</p><p>At runtime, on daily restart or manual deployment, we will read the application.properties from the above path and download the models and package from region specific blob storage and load it on system startup. This will reduce the download latency during system startup since we are connecting to region specific blob storage.</p><p><strong>UnDeploy API flow:</strong></p><p>When the user clicks on UnDeploy in client UI with environments and instance, then we will use our UnDeploy API to trigger workflow (airflow DAG) asynchronously which remove the models and package from blob storage of all three regions. We will update the deployment status in Metadata DB to <strong>UNDEPLOYED </strong>after the undeployment workflow completed successfully. Similarly the application.properties file also will be updated with empty data record and it will wait for the next deployment to takes place.</p><h4>WorkFlow Design:</h4><p>We will follow the below directory structure to store the models and package into blob storage of all three regions.</p><p><strong>Directory path : </strong>Container / data/ model_name/env / endpoint / version</p><p>Example : <a href="https://portal.azure.com/">s</a>earch / <a href="https://portal.azure.com/">data</a> / reranking_model / <a href="https://portal.azure.com/">dev</a> / <strong>variant-1</strong> / 1.0.32</p><h4>Multi-Instance Deployment per Environment</h4><p>From Client UI, the user selects DataCenter (blob-store-all) and Endpoint (variant-1, variant-2) from env (dev , stage, prod) for a particular model and package to be deployed.</p><p>At runtime of microservice, we will have configure environment variable per instance. In below example, we will have environment variable named <strong>endpoint</strong> which value will be used to follow the directory path in blob storage of that respective region.</p><pre>- name: dev-variant-01<br>  flows: [master]<br>  target:<br>    - cluster_id: [north-dev-a3]<br>  helm:<br>    values:<br>      scaling:<br>        enabled: true<br>      env:<br>        endpoint: variant-1</pre><pre>deploy_env: dev</pre><h4><strong>Archival Process</strong></h4><p>At any point of given time, solution is designed to store only two versions in blob storage. Hence Archival process is handled through undeployment workflow. In this case, on every deployment from UI will automatically trigger an undeployment API call to delete/archive the last old deployment on that environment. This will help us to clean lot of space as we had <strong>1.2 PB </strong>previously has been reduced to <strong>72 GB </strong>in all replicas.</p><p>Two versions : 4GB + 4GB = 8GB</p><p>With Three environments : 3 * 8GB = 24 GB</p><p>With Three data centers/replicas : 24 * 3 =<strong> 72GB</strong></p><h4>Disaster Recovery</h4><p>Automated Process: On-demand DAG created to achieve this workflow. Replicas of binary and package jar are maintained in GCP Blob store. We have feature to download all the directories in a container for both GCP and Blob Store. When entire blob storage is corrupted, then we will use the GCP blob store and copy it all the region specific blob storage.</p><h4><strong>Latency Metrics</strong></h4><p><strong>Uploading 4GB model and package </strong>to blob store of all three regions in less latency is quite challenging. We started with 45 minutes upload latency using blob Storage Python, Java SDKs and async processing. But later when we optimised using blob store cli, the latency was brought down to <strong>1 minute 40 seconds</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*kNo468HcDynkWQLYE4fWyw.png" /></figure><p>Similarly, <strong>Download latency</strong> took <strong>1 minute</strong> using blob Storage Python SDK during service startup time.</p><h4><strong>Summary</strong></h4><p>This blog covered various design perspectives and challenges of implementing code deployment system. We also learned about how the high availability, disaster recovery is maintained for creating any new product. If you have any follow-up thoughts, please do leave in comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1f2f8404786" width="1" height="1" alt=""><hr><p><a href="https://medium.com/walmartglobaltech/design-ml-model-code-deployment-system-e1f2f8404786">Design ML Model &amp; Code Deployment System</a> was originally published in <a href="https://medium.com/walmartglobaltech">Walmart Global Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>