<?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 Aayush Gupta on Medium]]></title>
        <description><![CDATA[Stories by Aayush Gupta on Medium]]></description>
        <link>https://medium.com/@aayushguptaaa?source=rss-a873b26b1642------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Frc3TpiV0qZ_YdNo2qQz0w.jpeg</url>
            <title>Stories by Aayush Gupta on Medium</title>
            <link>https://medium.com/@aayushguptaaa?source=rss-a873b26b1642------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:49:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aayushguptaaa/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[Comparing and Benchmarking Go, Rust, C++ Java, Python, PHP, Javascript Frameworks on Latency and…]]></title>
            <link>https://aayushguptaaa.medium.com/comparing-and-benchmarking-go-rust-c-java-python-php-javascript-frameworks-on-latency-and-e025f890a33b?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/e025f890a33b</guid>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Fri, 28 Apr 2023 08:39:19 GMT</pubDate>
            <atom:updated>2023-04-29T18:18:27.875Z</atom:updated>
            <content:encoded><![CDATA[<h3>Comparing and Benchmarking Go, Rust, C++ Java, Python, PHP, Javascript Frameworks on Latency and Request/second</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/0*FRkgUYSEd-K--os9.gif" /></figure><p>So on one Bright Sunny Beautiful day, I was thinking what Language and Framework should I chose to build a Product that I was planning to build.</p><p>So first of all deciding on a programming language and framework for a project, there are several factors to consider :</p><ol><li><strong>Performance</strong>: execution speed, memory usage, and concurrency support.</li><li><strong>Scalability</strong></li><li><strong>Ecosystem and libraries</strong></li><li><strong>Community and support</strong></li><li><strong>Developer expertise</strong></li></ol><p>But but but wait, the Metrics which can be computed irrespective of the project setup are metrics like :</p><p><strong>P99.999 , P99, P95, Average Latency, Request Per Second</strong></p><h3>Let’s Start</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*T9HcIrWxzwFGtMxh.gif" /></figure><p><strong>First things to decide( In Order ) :</strong></p><ul><li><strong>What Programming Languages to compare and for each language what Frameworks to Benchmark?<br>- Go</strong> : <em>Fiber, Fasthttp, Gin, Beego, Echo, Httprouter, Gorilla</em><br>- <strong>Rust</strong> : <em>Rocket, Iron, Warp, Actix, Nickel</em><br>- <strong>Java</strong> : <em>Spring, ActiveJ, Quarkus, Vert.x</em><br>- <strong>C++</strong> : <em>Evhtp, Drogon</em><br>- <strong>Python</strong> : <em>Pyramid, FastAPI, CherryPy, Django, Flask</em><br>- <strong>Javascript</strong> : <em>Sifrr, Fastify, Koa, Express.js</em><br>- <strong>PHP</strong> : <em>Laravel, CodeIgniter, Symfony, Hyperf</em></li><li><strong>What Metrics to compute for Benchmarking?<br><em>- </em></strong><em>Number of Requests/Second </em><strong><em><br></em></strong><em>- Average Latency<br>- P99 Latency<br>- P90 Latency</em></li><li><strong>Concurrency Levels<br></strong><em>65,256,512</em></li><li><strong>What Hardware to be used for Benchmarking?<br><em>- </em></strong><em>CPU: 8 Cores (AMD FX-8320E Eight-Core Processor)<br>- RAM: 16 GB<br>- OS: Linux</em></li></ul><h3>How did I Benchmark?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*paIfGw1UMA2YKmCc.gif" /><figcaption>Minions on work for Benchmarking</figcaption></figure><ul><li>wrk, results are collected using wrk : wrk is a HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU. It combines a multithreaded design with scalable event notification systems such as epoll and kqueue.</li></ul><pre>wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html</pre><pre>// This runs a benchmark for 30 seconds, using 12 threads, and keeping 400 HTTP connections open.</pre><p>Output:</p><pre>Running 30s test @ http://127.0.0.1:8080/index.html<br>  12 threads and 400 connections<br>  Thread Stats   Avg      Stdev     Max   +/- Stdev<br>    Latency   635.91us    0.89ms  12.92ms   93.69%<br>    Req/Sec    56.20k     8.07k   62.00k    86.54%<br>  22464657 requests in 30.00s, 17.76GB read<br>Requests/sec: 748868.53<br>Transfer/sec:    606.33MB</pre><ul><li>postgresql, results are stored in postgresql</li><li>docker, each implementation is implemented in an isolated container</li><li>jq, processing docker metadata</li></ul><h3>Results :</h3><p><strong>Requests per Second</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UOBKiofjqtrAgx4QfAoqOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0fH9gltHiTYF8Gd1fEQjjg.png" /><figcaption>Requests per Second ( 64 Concurrency , 512 Concurrency)</figcaption></figure><ul><li><a href="https://activej.io/"><strong>ActiveJ</strong></a><strong> framework of Java wins the War</strong>, with 183K RPS at 512 Concurrency</li><li>Family of <strong>C++ &amp; Rust</strong> Frameworks seems to be the Consistent performer for this metric</li><li>It seems that Go-based frameworks like Fiber, Fasthttp, and Sifrr perform well, along with some C++ frameworks like Drogon and Evhtp. Among the Java-based frameworks, ActiveJ and Vertx perform well.</li><li>PHP frameworks like Symfony, Codeigniter4, and Laravel seem to be the <strong>weakest performers</strong> in terms of requests per second.</li></ul><p><strong>Average Latency (ms)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NvEmjJmNRDX-_RRUfn9otQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cE_yju0f1KmyWAtPRjbMHg.png" /><figcaption>Average Latency (ms) ( 64 Concurrency, 512 Concurrency )</figcaption></figure><ul><li><em>Nickel</em> and <em>Iron</em> framework of Rust wins this one with leaps and bounds, 0.14 ms and 0.67 ms.</li><li><strong>Rust-based frameworks show outstanding performance</strong>: Rust-based frameworks (<em>Actix, Rocket, Iron, Warp</em>, and <em>Nickel</em>) consistently demonstrate low latency across all concurrency levels. This can be attributed to Rust’s focus on performance and safety, making it an excellent choice for high-performance web applications.</li><li><strong>Lightweight Java frameworks are competitive</strong>: While Java is often perceived as heavy and slow, some lightweight frameworks like <em>ActiveJ, Quarkus</em>, and <em>Vert.x</em> demonstrate competitive performance, particularly at higher concurrency levels.</li><li><strong>Scalability concerns:</strong> Some frameworks (e.g., Express, Laravel, Django) show significantly higher latency as the concurrency level increases, indicating potential scalability issues.</li></ul><p><strong>P90 Latency (ms)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DtyMG_oIY-DAfgl18lZbUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Av6T7TjwoCbKwQIuusIlYQ.png" /><figcaption>P90 Latency (ms) ( 64 Concurrency, 512 Concurrency )</figcaption></figure><ul><li><strong>C++</strong> with evhtp, Java with ActiveJ and Vert.x, and <strong>Rust with Nickel </strong>show the <strong>lowest</strong> latencies across all concurrency levels.</li><li>PHP with CodeIgniter4 and Laravel, and Python with Django and Flask have <strong>higher latencies</strong>, especially when concurrency increases.</li></ul><p><strong>P99 Latency (ms)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5oNU20RjVtRt_Z2K93zQgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsprXSYJG_oqeGWfG_FGHQ.png" /><figcaption>P99 Latency (ms) ( 64 Concurrency, 512 Concurrency )</figcaption></figure><ul><li>C++ with evhtp, Java with ActiveJ and Vert.x, and Rust with Nickel continue to demonstrate low latencies.</li><li>PHP with CodeIgniter4 and Laravel, and Python with Django and Flask have even higher latencies at P99 than at P90, which could indicate poor performance under heavy load.</li></ul><h3><strong>Concluding :</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h5Fei7cm-9t6yS6jwk2YYw.png" /><figcaption>Rust wins the War</figcaption></figure><ul><li><strong>Rust frameworks</strong> (Actix, Rocket, Iron, Warp, and Nickel) consistently perform <strong>well</strong> across different concurrency levels, <strong>especially Nickel</strong>.</li><li><strong>Java frameworks</strong> (ActiveJ, Spring, Quarkus, and Vert.x) also show relatively good performance, with ActiveJ and Vert.x having the <strong>lowest</strong> latencies.</li><li><strong>PHP and Python frameworks</strong> generally exhibit higher latencies, with PHP’s CodeIgniter4 and Laravel, and Python’s Django and Flask having the <strong>highest</strong> latencies.</li><li><strong>Go frameworks</strong> (Gin, Gorilla-Mux, Fiber, Beego, Fasthttp, Httprouter, and Echo) have mid-range latencies compared to other languages.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e025f890a33b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scaling APIs to 10 million rpm with P99 latency of 100ms : Disney+ Hotstar]]></title>
            <link>https://aayushguptaaa.medium.com/scaling-apis-to-10-million-rpm-with-p99-latency-of-100ms-disney-hotstar-76e43eae4dcd?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/76e43eae4dcd</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 17:33:43 GMT</pubDate>
            <atom:updated>2023-04-26T17:33:43.824Z</atom:updated>
            <content:encoded><![CDATA[<h3>Scaling APIs to 10 million rpm with P99 latency of 100ms : Disney+ Hotstar</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*8w9rKsHhv12P4efF.jpeg" /><figcaption>Peak concurrency Disney+ Hotstar has seen is 25.3 million</figcaption></figure><p>The API at Hotstar which is responsible to fetch all the Metadata of any Content has seen a Scale of greater than <strong>10 million RPM, </strong>while maintaining <strong>P99 latency</strong> of less than <strong>100ms.</strong></p><p>This can be viewed over network tab, Response is like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sYRFX09iMX1zWXiD.png" /><figcaption>Response contains all the Metadata for any Content</figcaption></figure><p>Let’s discuss how an <strong>Ideal designed Architecture</strong> would look like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VkA1aK_0OQz_Ff2y.png" /><figcaption>Ideally Designed Architecture</figcaption></figure><p><strong>API Gateway</strong> : Forwards the requests to respective Service</p><p><strong>User Facing Service : </strong>This is responsible to get data for a particular content ID, as the Database is highly <strong>De-Normalized</strong>, The queries can have extremely <strong>Complex joins</strong> which can require querying upto <strong>17 tables</strong> and <strong>Aggregation</strong> over that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xxDUGQRIeL4OIaDt.png" /><figcaption>Highly De-Normalized Schema, complex joins are required to get Entity Data</figcaption></figure><p>Now the <strong>query time</strong> and creating a <strong>normalized view</strong> according to agreed upon response Schema will take significant Time and be reflected as <strong>increased latency</strong></p><p><strong>Content Management Service : </strong>All Create, Update and Delete Operations are done by this Service, Devs and Ops only are having access to this.</p><h3>Auto-Scaling</h3><p><strong>How Scaling is done</strong> : There exist basically two models to ensure seamless scalability: <strong>Traffic based </strong>and<strong> Ladder based.</strong></p><p><strong>Traffic-based</strong> : New nodes are added/deleted according to change in the metrics like :</p><ul><li>CPU Utilization</li><li>Primary Memory Usage</li><li>Number of DB Connections</li><li>Network In/Out</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qDEjcW6CRl-K_m0s.gif" /><figcaption>Traffic Based Scaling</figcaption></figure><p><strong>Bottlenceks, Challenges with this :</strong></p><ul><li>Query <strong>Execution time</strong> is <strong>high.</strong></li><li><strong>Checking</strong> the existence of <strong>key</strong> in Cache <strong>adds latency.</strong></li><li>Aggregations and computing the view in response Schema takes time</li><li>If concurrency <strong>jumps</strong> from <strong>10 million to 11 million under a minute</strong>, such sharp rise can’t be handled, as it takes some time to add new infrastructure to the pool, and the container and the application takes few seconds to start.</li></ul><h3>How Hotstar solved it?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xEPO4IeLlgxQ7u9o.png" /></figure><p>How we solved all the Challenges :</p><ul><li><strong>Not</strong> using Primary DB for Reads.</li><li>Anytime a create, update or delete operation is there on primary DB, a view is created and <strong>indexed</strong> in Downstream Database, fine tuned for providing <strong>latencies</strong> in <strong>Microseconds(μs).</strong></li><li>Using <strong>Cache</strong> as the <strong>only Data Source</strong>, user facing service interacts with.</li><li>Maintaining a <strong>Response Cache</strong> at <strong>Reverse Proxy</strong> Level</li><li>Switching to <strong>ladder based</strong> <strong>Scaling</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dzmSy02yrgy7t9I2.png" /><figcaption>Optimized for Scale</figcaption></figure><p>DynamoDB Accelerator (DAX) is used an In-Memory Cache over DynamoDB, to provide <strong>read</strong> <strong>latencies</strong> in <strong>Microseconds(μs).</strong></p><p>An <strong>Inline Write-Through</strong> Caching Strategy is used, helping in solving <strong>inconsistency</strong> problem and high throughput for writes as well</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oS_eFhsWJJShQi10.png" /><figcaption>Write-Through Cache</figcaption></figure><h3>How is Autoscaling done ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bN4_xZUpJ8chlvhG.gif" /><figcaption>Ladder Based Scaling</figcaption></figure><p>Disney+Hotstar has <strong>pre-defined ladders</strong> per million concurrent users.</p><p>As more requests are processed by the system adds on, new infrastructure in terms of ladders is added.</p><p>As of now, the Disney+Hotstar has a <strong>concurrency buffer</strong> of <strong>2 million</strong> concurrent users, which is optimally utilized during the peak events such as World Cup matches or IPL tournaments.</p><p>In case the number of users goes beyond this concurrency level, then it takes 90 seconds to add new infrastructure to the pool, and the container and the application take 74 seconds to start.</p><p>In order to handle this time lag, there is a <strong>pre-provisioned buffer</strong>, which is the opposite of auto-scaling and has proven to be a better option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/0*91C7CB7YKWV3cstn.jpeg" /><figcaption>An example of Infra Ladder</figcaption></figure><p><strong>Load Testing</strong> is done and Match day <strong>simulation</strong> is run to figure out how many <strong>K8 nodes</strong> and underlying <strong>DB Nodes </strong>are required for a specific <strong>service</strong> for a specific <strong>region</strong> is required to serve <strong>x million concurrent users. </strong>To<strong> </strong>handle the time lag of adding new infra and start application, there is a <strong>pre-provisioned buffer</strong></p><p>Connect with me on <a href="https://www.linkedin.com/in/zyushg">Linkedin</a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76e43eae4dcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Expanding Globally to 50 Countries, Moving from Multi Tenant DB Architecture to Single DB: Disney+…]]></title>
            <link>https://aayushguptaaa.medium.com/expanding-globally-to-50-countries-moving-from-multi-tenant-db-architecture-to-single-db-disney-5a82b33c498c?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a82b33c498c</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 17:31:15 GMT</pubDate>
            <atom:updated>2023-04-26T17:31:15.781Z</atom:updated>
            <content:encoded><![CDATA[<h3>Expanding Globally to 50 Countries, Moving from Multi Tenant DB Architecture to Single DB: Disney+ Hotstar</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*142tCUXJrE__XWRj.jpeg" /><figcaption>Disney+ Hotstar</figcaption></figure><blockquote>In later half of the 2021, Disney+ Hotstar decided to launch in Middle Eastern and Northern African Countries, around 19 countries.<br>The Content Platform team manages Database for Content Management System(CMS).</blockquote><p>CMS is built on RDBMS Architecture and constitutes of more than 200 tables storing humongous amount of MetaData, hierarchy, mapper tables for all the playable and non-playable assets like : movie, shows, seasons, sport matches, images, playback urls, menu, page, trays, etc.</p><p>Each Tenant( Country ), has it’s own database hosted at the nearest available region. So for every country we decide to expand into, these things happen:</p><ul><li>We need to maintain another Database, monitor all the metrics like <strong>CPU utilization</strong>, read write <strong>latencies</strong>, network metrics, <strong>IOPS</strong>, etc..</li><li>Decide and monitor individual <strong>scaling</strong>.</li><li>As most of the content is same and only few fields are <strong>localised</strong>, huge amount of <strong>Data Replication</strong> is there, the Ops team needs to replicate and maintain <strong>sanity at multiple tenant level.</strong></li><li>For RDBMS systems, to reduce <strong>data redundancy, inconsistency</strong> and achieve <strong>Integrity</strong> high degree of <strong>Normalization</strong> is maintained, which makes <strong>Data retrieval slower</strong> and <strong>multiple join</strong> queries and <strong>complex DAOs </strong>and<strong> DTOs </strong>inevitable.</li><li>Due to high degree of Normalization, <strong>code repository</strong> becomes unnecessarily <strong>large</strong> and accommodation of <strong>new changes</strong> and <strong>De-bugging</strong> becomes time taking and <strong>tough</strong>.</li></ul><blockquote>For going live in 50 countries, we need to setup and maintain 50 Databases, 200 replica clusters and 10k tables with RDBMS architecture</blockquote><h3>How did we solve this?</h3><p>Database choice and design</p><p><strong>Schema full</strong> vs <strong>Schema less</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4tM0w_2FT6xhMmkX.jpeg" /><figcaption>RDBMS vs No Sql Comparison</figcaption></figure><p>We Decided to go with <strong>Schema less</strong> on this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/0*SIjmLdUq6v0scKF9.jpeg" /><figcaption>Types of NoSql Databases</figcaption></figure><p>We Benchmarked using <strong>Key Value Storage</strong>( ex: DynamoDB), <strong>GraphDB</strong>( ex: Neo4J) ,<strong>DocumentDB</strong>( ex: MongoDB) vs <strong>Column Oriented</strong> on following aspects :</p><ul><li>support for ACID Transactions</li><li>Aggregation and group by queries</li><li>Join Queries Performance</li><li>Queries complexity</li><li>Schema Structure</li><li>Horizontal scalability</li><li>Secondary indices support</li><li>Audit and integration support for external services</li><li>Supports<strong> Change Data Capture (CDC)</strong></li></ul><p>We Decided to go with <strong>DocumentDB</strong> on this, for following reasons :</p><p><strong>Data Model agility</strong> : A document based approach also allows us to embed small arrays without affecting the performance. This allows us to move away from many number of mapper tables and also eliminate the need for a cache layer for base entities together this leads to simpler data layout and app implementation</p><p><strong>Horizontal Scalability</strong> : MongoDB supports horizontal scalability with auto sharding and multi region deployment as well.</p><p><strong>Evolving Business requirements (Growth in terms of complexity of requirements)</strong> : Flexibility in data model allows the schema to evolve through code. We can have sparse indexes, attributes being added to newer documents, configurable and tunable schema validators</p><blockquote>We Chose AWS DocumentDB over MongoDB Atlas, because we wanted to be under same Ecosystem of AWS and not setting and maintaining separate infra. and avoiding setting up dedicated instance for VPC peering.</blockquote><p>Now comes the part where we need to figure out Collection Patterns and do Database Modelling.<br>What do we want to achieve while defining these collection patterns :</p><ul><li>Achieve<strong> high Degree </strong>of<strong> De-Normalization</strong></li><li>Remove mapper tables and maintain <strong>Referential Integrity</strong></li><li>Customizable DB Reference Objects for keeping data of all other table’s data, whose foreign id was in sql table</li></ul><p>Example : How Data looks like in SQL :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l13hfG3X1sxiQrzE.jpeg" /><figcaption>RDBMS Tables</figcaption></figure><p>De-Normalized Data Model in Document DB would be something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vlQi3Mx3K5MRKhVu.jpeg" /><figcaption>Document in DocumentDB</figcaption></figure><p>Note : Shown schema is dummy, and consist of very few tables and columns of the actual schema</p><p>Considering 50 Countries, there would have been <strong>10,000 tables</strong> storing all the data, moving to De-Normalized Data Model, the number of <strong>Collections</strong> is limited to <strong>47</strong>, and doesn’t grow as Disney+ Hotstar expands to more number of Countries</p><p>Connect with me on <a href="https://www.linkedin.com/in/zyushg">Linkedin</a>:)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a82b33c498c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Evolution of Data Storage Formats: From CSV to Delta]]></title>
            <link>https://aayushguptaaa.medium.com/the-evolution-of-data-storage-formats-from-csv-to-delta-8ba749fbe344?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ba749fbe344</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 17:28:11 GMT</pubDate>
            <atom:updated>2023-04-26T17:28:11.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*3t-Opvcah3TmGAzF.gif" /></figure><p>Hey there! Can you believe how far we’ve come from the good ol’ days of the basic CSV data storage format? As our need for faster and more adaptable data storage solutions grew, we’ve seen some pretty awesome new formats hit the scene. In this article, we’re gonna take a deep dive into the evolution of data storage formats — from CSV to Delta — and what makes each one an improvement over the last. Get ready to geek out with me</p><h3>CSV (Comma Separated Values)</h3><p>CSV is a simple used format for storing tabular data. Each line in a CSV file represents a record, with values separated by commas.</p><p><strong>Why it was introduced?</strong><br>CSV was created as a straightforward way to store and share tabular data, requiring minimal processing to read or write.</p><p><strong>Limitations:</strong></p><ul><li>Limited data types and structure</li><li>No support for data compression</li><li>No schema enforcement or data validation</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/0*ICvXYrGZAY9LJEQB.png" /><figcaption>CSV</figcaption></figure><h3>JSON (JavaScript Object Notation)</h3><p>JSON is a lightweight, text-based format for data interchange that uses a subset of JavaScript’s syntax.</p><p><strong>Why it was introduced?</strong><br>JSON was designed as an alternative to XML, offering human-readable and easy-to-parse data structures.</p><p><strong>Improvements over CSV:</strong></p><ul><li>Supports hierarchical data structures</li><li>More flexible in handling different data types</li><li>Better support for metadata</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/0*u0zTcH0am9aWpc7x.png" /><figcaption>JSON Object</figcaption></figure><p><strong>Why JSON is inefficient?</strong><br>JSON is not efficient format for serialization and deserialization, which can lead to high CPU utilization. There are a few reasons for this inefficiency:</p><ol><li><strong>Verbosity</strong>: JSON is a text-based format, which means it requires more bytes to represent the same data compared to binary formats. The added overhead can lead to increased memory consumption and processing time, especially for large data sets.</li><li><strong>Parsing</strong>: JSON data needs to be parsed into native data structures when it’s deserialized, which can be computationally expensive.</li><li><strong>Stringification</strong>: Converting various data types to their string representation can require significant CPU cycles.</li><li><strong>Encoding and decoding</strong>: JSON uses Unicode, which can increase the processing time for encoding and decoding operations, particularly for non-English characters or special symbols.</li><li><strong>Lack of schema</strong>: JSON does not have a built-in schema or type system, which means that data validation and error checking must be done manually.</li></ol><h3>Parquet</h3><p>Parquet is a columnar storage file format optimized for use with big data processing frameworks like Apache Hadoop and Apache Spark.</p><p><strong>Why it was introduced?</strong><br>Parquet was developed to address the need for efficient storage and processing of large-scale datasets in distributed systems.</p><p><strong>Improvements over JSON:</strong></p><ul><li>Columnar storage format, allowing for better data compression and query performance</li><li>Schema evolution support</li><li>Optimized for big data processing frameworks</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hy16ImWrBa8L4Zcp.png" /><figcaption>Binary Representation of Columnar Layout can be thought as of Parquet</figcaption></figure><p><strong>Now, let’s come to the point that How come Columnar Storage in Parquet is more efficient for Read? let’s deep dive here</strong></p><ol><li><strong>Compression</strong>: Columnar storage allows for better compression because values within a column are often similar in type and range. This similarity results in better compression ratios compared to row-based storage formats, where data from different columns is mixed.<br>Snappy being the default compression Algorithm because of perfect balance between compression and speed</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1NfUlhNBaHN4y2x5.png" /><figcaption>All Compression Algorithms compared</figcaption></figure><p><strong>2. Encoding</strong>: Parquet supports various encoding techniques, such as dictionary encoding, run-length encoding, and bit packing, which can further reduce the storage footprint and improve read performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p6YFqO1Gh0yDnUep.png" /><figcaption>All the Encoding Algorithms explained</figcaption></figure><p><strong>3. Vectorized query execution</strong>: Modern query engines can take advantage of columnar storage to perform vectorized operations, allowing them to process data in large batches rather than one row at a time. This approach improves</p><h3>ORC (Optimized Row Columnar)</h3><p>ORC is another columnar storage format designed for the Hadoop ecosystem, with a focus on optimizing performance and storage efficiency.</p><p><strong>Why it was introduced?</strong><br>ORC was created to provide better compression and faster read performance compared to other columnar storage formats.</p><p><strong>Improvements over Parquet:</strong></p><ul><li>Light-weight compression algorithms, resulting in smaller file sizes</li><li>Improved read performance</li><li>Predicate pushdown and vectorization support</li></ul><h3>Avro</h3><p>Avro is a row-based storage format that supports schema evolution, making it suitable for storing long-term data.</p><p><strong>Why it was introduced?</strong><br>Avro was developed to address the need for a flexible and efficient data serialization framework that could handle schema changes over time.</p><p><strong>Improvements over ORC:</strong></p><ul><li>Row-based storage, better suited for certain use cases</li><li>Native support for schema evolution</li><li>Compact binary format</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VenzktExpmLchbZH.png" /><figcaption>Avro</figcaption></figure><p>Serialized Avro data (binary format):</p><pre>\x0cAlice\x1e\x0cNew York\x0cBob\x19\x0eSan Francisco\x0eCharlie\x16\x10Los Angeles</pre><h3>HDF5 (Hierarchical Data Format 5)</h3><p>HDF5 is a versatile data storage format designed for high-performance computing and large-scale datasets.</p><p><strong>Why it was introduced?</strong><br>HDF5 was developed to handle complex, hierarchical data structures and support efficient data storage and retrieval in scientific applications.</p><p><strong>Improvements over Avro:</strong></p><ul><li>Supports complex, hierarchical data structures</li><li>Optimized for high-performance computing environments</li><li>Advanced data compression and chunking capabilities</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4PekdAHTIo-bFxyJ.png" /><figcaption>Example of HDF5</figcaption></figure><h3>Delta Lake</h3><p>Delta Lake is an open-source storage layer built on top of Apache Spark that brings ACID transactions and time-travel capabilities to big data workloads.</p><p><strong>Why it was introduced?</strong><br>Delta Lake was developed to address the challenges of data reliability and consistency in large-scale, distributed data processing systems.</p><p><strong>Improvements over Avro:</strong></p><ul><li>ACID transaction support, ensuring data consistency</li><li>Time-travel capabilities for versioning and data rollback</li><li>Schema enforcement and evolution</li><li>Integration with Apache Spark and other big data frameworks</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5nWFiR06m8eV639G.png" /><figcaption>Delta Lake Table Structuring</figcaption></figure><h3>Concluding</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_MavDFkROI8Elect.png" /><figcaption>Comparison between All the Data Storage Formats</figcaption></figure><p><strong>When choosing a data storage format, consider the following factors:</strong></p><ol><li><strong>Compatibility</strong>: Ensure the format is compatible with the tools, languages, and platforms you are using.</li><li><strong>Compression</strong>: If storage space is a concern, choose a format that provides better compression ratios.</li><li><strong>Schema evolution</strong>: If your data schema is likely to change, choose a format that supports schema evolution, like Avro, Parquet, or Delta Lake.</li><li><strong>Query performance</strong>: If read performance is a priority, consider using columnar formats like Parquet or ORC, which are optimized for fast analytical queries.</li><li><strong>Write performance</strong>: Consider formats like HDF5 or Delta Lake that offer efficient write performance, especially if you have real-time or high-volume write requirements.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ba749fbe344" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Eye Power Detection by just using Web Camera]]></title>
            <link>https://aayushguptaaa.medium.com/eye-power-detection-by-just-using-web-camera-520b1e165399?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/520b1e165399</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 17:24:29 GMT</pubDate>
            <atom:updated>2023-04-26T17:24:29.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2lDzkm20oJ8O-zcT.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*30il8GrND5vaZG_p.jpeg" /></figure><h3>Calculate Power of Lens required for correct vision using Laptop/ Smartphone without any external help or Machine</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gBl6XBM6Z6n51mRx.png" /></figure><p>I named the Product <strong>Eye Assist</strong></p><p>How to use Eye Assist?</p><ul><li><strong>Look</strong> towards the <strong>camera</strong> of the Laptop/Mobile</li><li><strong>Read</strong> the <strong>text</strong> being shown on Instructions Page</li><li><strong>Move</strong> <strong>away</strong> from Camera until you can read the <strong>text carefully</strong></li><li><strong>Stabilize</strong> at that Position</li><li>Voila it’s done</li></ul><p><strong>How does it look like?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qzWwqE7NgVnmtb9o.png" /></figure><p><strong>How does it work ?</strong></p><ul><li>A Convolutional Neural Network(CNN) trained on i-Bug 300-W facial Landmarks dataset to get <strong>Facial Landmark co-ordinate points </strong>on Face.</li><li>Co-ordinates of <strong>points</strong> representing both <strong>eyes</strong> are calculated.</li><li>From which <strong>Cornea</strong> to <strong>Cornea</strong> <strong>distance</strong> is calculated.</li><li>Another <strong>Pre-Aligned</strong> model Calculates <strong>distance of eye from Camera</strong> at which the person can see clearly.</li><li>Now <strong>Depth perception</strong>(that too from a Single Camera) is used to Calculate power of Lens the person require.</li><li>3D — Facial construction is done using <strong>Position Map Regression Networks</strong></li></ul><p>How does it help ?</p><ul><li>Makes use of <strong>Auto-refractometer </strong>and <strong>Snell’s test</strong> <strong>redundant</strong></li><li><strong>Ease</strong> of performing the <strong>test</strong></li><li>3D- face model can be used for AR- based applications like <strong>trying Spectacles at home </strong>at much better measurements and <strong>higher accuracy</strong></li><li>E-commerce sites like Lenskart can integrate it with AR service and directly deliver the spectacles</li><li>Free of Cost</li><li>No internet dependency</li><li><strong>3D facial reconstruction</strong> can be used to construct images of Criminals and it can be known how they actually look and many permutations of how they would look with different facial aspects like moustache, beard and long hairs, etc.</li><li>Prediction of facial paralysis</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=520b1e165399" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Telling how accurate an address is, solving for incorrect user location| Zomato]]></title>
            <link>https://aayushguptaaa.medium.com/telling-how-accurate-an-address-is-solving-for-incorrect-user-location-zomato-439b54590e80?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/439b54590e80</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 17:22:48 GMT</pubDate>
            <atom:updated>2023-04-26T17:22:48.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*coj80ONCvmt8g-n1.png" /></figure><h3>What were the Problems?</h3><p><strong>Incorrect user location</strong>, which leads to -</p><p>• Increase in <strong>delivery time</strong><br>• Increase in <strong>driver-customer calls</strong><br>• Decrease in driver utilization<br>• Inefficient clubbing<br>• <strong>Wrong address rejections</strong> in extreme cases</p><p>Delivery partner (DP) marking incorrect complete location -</p><p>• <strong>DP payout frauds</strong> : Zomato pays Delivery partners for an order. proportional to the distance they’ve travelled, now if the the delivery partner marks the location where they’ve delivered the order, X Kms. away from actual delivery location, we will have to pay them extra for those X Kms.<br>• Increase in delivery time which in-turn <strong>decreases driver utilization</strong></p><h3>How did I solve it?</h3><p>Introducing Address Confidence.</p><blockquote><em>Address confidence score is the measure of accuracy/correctness of the coordinates or geo-location of every address. We assign address confidence to customer saved addresses, as well as restaurant addresses.</em></blockquote><p>Here Address Constitutes of Geo-location only, i.e lat/lng.<br><strong>Orange Cluster</strong> : where user marked their location<br><strong>Green cluster</strong> : Cluster formed by GPS pings of delivery partners when they marked the order complete</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m-mZbB6OrhyEDsqC.png" /><figcaption>Actual(green) location vs User Marked(Orange) location</figcaption></figure><h3>How is customer address confidence calculated?</h3><p><strong>Address IDs are segregated into 2 categories on basis of number of orders since last 6 months</strong></p><ul><li>If the Orders are &gt;=3 than only 1 parameter is used:<br>• Completed latitude/longitude marked by Rider for the Trip</li><li>If the Orders &lt; 3 than following 3 parameters are used:<br>• Completed latitude/longitude marked by Rider for the Trip<br>• Quality of S2 Cell the Address ID lies in (in terms of drop error)<br>• GPS ping lat/lng of the user while placing an order and while adding the Address</li></ul><p>Using the Completed lat/lng we compute the cluster and basis the distance between centroid of the Densest Cluster and other parameters we assign Confidence to the Address ID</p><blockquote><em>Drop error is defined as the distance between user marked address and actual address where order is delivered(in mtrs.)</em></blockquote><blockquote><em>Address Confidence scores are in similar Pattern to HTTP status Codes, i.e 1xx, 2xx, 3xx, 4xx, 5xx<br>1xx : Confidence scores for new added adrs. having low number of orders<br>2xx : Confidence scores for adrs. having high number of orders<br>3xx : Confidence scores for adrs. requiring correction in their coordinates<br>.<br>.</em></blockquote><p>Examples of High/Medium/Low confidence addresses :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fDx3oMqHxojSoh-g.png" /><figcaption>High Confidence Address</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jWddPUJyJS6x0car.png" /><figcaption>Medium Confidence Address</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UDVHvXYiOSEanxWP.png" /><figcaption>Address Requiring Correction in their Geo-location</figcaption></figure><h3>How Do We correct the Geo-location of Addresses ?</h3><p>In a case when the address is to be corrected, we try to predict the customer’s correct location. If we have high confidence in this predicted location, then we update the customer location from the backend itself.</p><p>If we do not have high confidence in the customer predicted location, then we send a frontend prompt asking the customer to manually correct his/her location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*5anaP0HPPOEk3sXr.png" /><figcaption>Prompts that are sent to Customers</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=439b54590e80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing Google Maps : Zomato]]></title>
            <link>https://aayushguptaaa.medium.com/enhancing-google-maps-zomato-8634a75c2234?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/8634a75c2234</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[system-architecture]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 17:20:43 GMT</pubDate>
            <atom:updated>2023-04-26T17:20:43.290Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enhancing Google Maps : Zomato</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zcN3vYiRZNCQVD1t.png" /></figure><p>Locating you better</p><p>‘Location’ is one of the most critical aspects that drives customer experience through ‘Search &amp; Discovery’ and ‘Online Ordering’ on Zomato. Starting from the different restaurants to be showcased on the app, to delivering orders at the accurate location, it plays a big role in determining how customer-friendly the platform really is.</p><p>A correct location input ensures a seamless delivery experience for both, the customers and the delivery partners. More than anything, it helps the delivery partners navigate with ease, and deliver orders without making multiple phone calls to the customers. This allows them to optimise their time and deliver as many orders as they can.</p><p>Till around early 2020, the map views displayed on the app were not as well defined as we would’ve wanted them to be, and instead looked like broadly mapped block visualisations that could lead to <strong>ambiguity and marking of incorrect locations</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P37SnitxmGk_gU0l.png" /><figcaption>How previous map use to look like</figcaption></figure><p>In light of these issues and while solving for a better last-mile handshake experience between the customers and delivery partners, it occurred to us, why not develop enhancements to the existing mapping system? This could be done by building footprints instead of relying on external mapping services.</p><h3>How did we go about enhancing the system?</h3><p>We started by taking on two challenges –</p><ul><li>Identifying high volume geographical entities (‘Points of Interest’). For example, <em>Offices</em>, <em>Colleges</em>, <em>Apartments</em>, <em>Hospitals</em>, etc.</li><li>Mapping these geographical entities</li></ul><h3>Step 1</h3><p>Mapping actual <em>buildings</em> / <em>societies </em>/ <em>offices</em> is a complex task; especially when the GPS accuracy relies a lot on the devices of the customers.</p><p>We started by evaluating customer addresses as the first step.</p><p>On a daily basis, there are a large number of customer addresses added, which contain details around their latitude and longitude, as well as information around the names of their <em>localities / societies</em>. We tokenized these customer addresses and started ranking words on the basis of the rarity of tokens similar to <em>TF-IDF</em>. This helped us generate key terms in relation to <em>localities / societies</em> such as ‘<em>vipul’</em>, ‘<em>hiranandani</em>’, ‘<em>ventura</em>’, ‘<em>wellington</em>’, <em>etc</em>.</p><h3>Step 2</h3><p>Managing the local language diversity was another challenge. We had to iterate and smoothen the model inputs for different cities. For example, the spatial density clustering inputs that worked for Gurgaon or Chandigarh failed to produce results for Mumbai.</p><p>To tackle this, we started creating density-based clusters for each of the key terms we had defined in Step 1. Post this, we added smoothening models on these clusters and started seeing areas being defined in a much better manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C1Ohh0xeQKGD1kuX.png" /><figcaption>Dense Clusters</figcaption></figure><ul><li>We created GeoJSONs to map the geographical entities and built a moderation queue. It was also important to add some quality metrics in place to check for any incorrect POI mapping.</li><li>Once the moderation process was complete, the POIs were activated for the customers to view.</li><li>Additionally, we built a feedback loop to track a few UX metrics. We released these POIs in A/B mode and utilised the metrics to compare and correct any wrongly mapped POIs, which were live at that point.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2U2dk_DR53Z4h9_n.png" /><figcaption>How Maps experience looks now in Zomato</figcaption></figure><h3>Step 3</h3><p>To take a step further and make POIs even more helpful, we attributed whether a particular POI entity was an <em>office</em>, <em>home</em>, <em>college campus</em> or a <em>hospital</em>. This allowed us to create dynamic address forms, which helped us share information with the delivery partners in a more structured format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jkMr9L27bmy6E13i.png" /><figcaption>Specific Entity attribution with POI</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DmwWCasVFHzm2WJs.png" /><figcaption>Information provided to Delivery Partners</figcaption></figure><h3>What was the impact?</h3><h3>1. Better accuracy</h3><p>Since the customers can now view building footprints on their map, it helps them correct any GPS inaccuracies on their own devices even during a low signal in the area.</p><p>With high to medium range devices, we get an average GPS accuracy of 60m to 150m. However, these can be of up to 2–3km as well, depending on the signal and device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T4EkVDNVOEfqO_Mj.png" /><figcaption>before vs after</figcaption></figure><h3>2. Fewer partner-to-customer calls and shorter handshake time</h3><p>With more accurate delivery locations (lat/lng) and with structured addresses in place, the delivery partner doesn’t have to call and confirm the lane, tower, or floor with the customer. This also results in faster deliveries (which is especially helpful during peak times).</p><h3>3. Better dining recommendations</h3><p>POIs also helped us drive better <em>Go Out</em> recommendations. For example, if a customer is within an office complex, it’s better to showcase restaurants within that complex on priority, rather than those outside of it or across the street.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rvepFAEWx2yNmnG8.png" /><figcaption>Relevant Dine Out listings according to location</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8634a75c2234" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reducing Under Delivery and Over Delivery of Ads. in Zomato]]></title>
            <link>https://aayushguptaaa.medium.com/reducing-under-delivery-and-over-delivery-of-ads-in-zomato-2058f3662b47?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/2058f3662b47</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-design]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 17:17:56 GMT</pubDate>
            <atom:updated>2023-04-26T17:17:56.960Z</atom:updated>
            <content:encoded><![CDATA[<p>My first team at Zomato was <strong>AdTech Team. </strong>Zomato provide options to merchants to run their Ad. campaigns over Zomato’s app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IxBNJkxmEL8ibmt6.png" /></figure><p>So, first things first, Merchants here are restaurant Owners, chains are groups of merchants under same name( ex : Dominos, McDonald’s).<br>Now these Merchants need to Promote their restaurants in various verticals :</p><ul><li>Online Ordering</li><li>Dine Out</li><li>Search drop down and results page</li></ul><p>So they buy Clicks and Impression counts that they want in a given Period of time, and this is called a <strong>Campaign</strong></p><p>An <strong>impression</strong> is when a user only sees an <strong>advertisement, Click </strong>is when user actually clicks on an <strong>advertisement.</strong></p><p>Ex : Dominos Connaught Place runs a Campaign of 30k Clicks and 100k impressions and similarly <strong>x </strong>number of restaurants also running similar campaigns. <strong>y</strong> amount of money is charged from merchants on basis on number of impressions, clicks, time period, location and time of the year. If the campaign isn’t fulfilled, proportional amount of money is returned back to the Merchant let’s call it <strong>z</strong></p><p>Now these Impressions and Clicks need to be positioned and shown to users in such a manner and that all these cumulative targets could be achieved with minimising <strong>z </strong>( the amount that needs to be returned to merchant )</p><p><strong>What’s the Problem that we were facing ?</strong></p><p>The <strong>existing Pipeline</strong> for reporting <strong>Aggregated clicks</strong> and impressions per campaign per time window was a <strong>Batch Processing</strong> one, using <strong>Apache Spark</strong> as distributed processing system. This job used to run in every 15 minutes, Now During Peak loads this Batch Processing used to be so slow that it used to take anywhere from 1.5 hours to 2 hours.</p><p>Now this translates to the fact that the data that visibility and positioning algorithms are being fed is of -2 hours, and for those few hours that <strong>campaign is still live</strong> even though the <strong>Clicks</strong>/Impressions <strong>quota</strong> for that campaign could <strong>already</strong> be <strong>fulfilled</strong>. For Example: The campaign run by McDonalds was for getting 30k clicks, now let’s say till 7:00 p.m this particular campaign had 27k clicks and as the quota is yet to be fulfilled, it’s still on the at a boosted position, now the Algorithm which decides the position on the campaign didn’t get any data till 9:00 p.m and thus can’t take any action. But in meanwhile of this lag that campaign got 35k clicks, 5k over the asked limit.</p><blockquote><em>So for multiple campaigns Over Delivery of Ads. will be there and for others Under Delivery of Ads. and for the Under Delivered Ads. Zomato had to return the money in proportion.</em></blockquote><p>So for every user action, an event with multiple user and action details are sent to dedicated service</p><pre>{<br>    &quot;events&quot; :<br>    [<br>        {<br>            &quot;data&quot; : { &quot;campaign_id&quot; : 9857323},<br>            &quot;event_type&quot; : &quot;impression&quot;<br>        }<br>    ],<br>    &quot;device_info&quot; : {&quot;sec-ch-ua-platform&quot; : &quot;ios&quot;},<br>    &quot;source_request_id&quot;:&quot;7fa67be4-f83a-429f-9d73-38b660c50825&quot;,<br>    &quot;user_attributes&quot; : {&quot;id&quot; : &quot;mn3f6f67ff7tfdx6f&quot; },<br>    &quot;deleted_user_attributes&quot; : [],<br>    &quot;user_identities&quot; : {},<br>    &quot;application_info&quot; : {},<br>    &quot;schema_version&quot;: 2,<br>    &quot;environment&quot; : &quot;production&quot;,<br>    &quot;context&quot;: {},<br>    &quot;mpid&quot;:7346244611012968789,<br>    &quot;ip&quot; : &quot;172.217.12.142&quot;,<br>    .<br>    . <br>    .}</pre><p>On daily basis ~100 to ~150 million such events stream through our pipeline. These events are then Published to a particular <strong>Kafka</strong> topic to keep the <strong>pipeline asynchronous</strong>.</p><p>Further a Worker dumps this data to an <strong>Apache Hive Table</strong>, on top of this <strong>Presto</strong> was being used as a <strong>Distributed Querying engine</strong> for <strong>OLAP </strong>load.</p><p>The aggregation logic was written in <strong>Apache Spark</strong>, The Algorithm for the computation goes like this :</p><ul><li>Entire day is divided in <strong>8 windows</strong> of <strong>3 hours</strong>, in sync with Meal time</li><li>Every <strong>Click/Impression in a window is unique</strong>, i.e irrespective how many clicks made by a person in particular window it will only be <strong>counted as a single click</strong></li><li>Clicks per campaign is set as key value pair in two format clicks for particular 3 hour window ( 12 am to 3 am, 3 am to 6 am, …)and clicks for particular day till time, ex :<br><em>campaign_1553454_3_030422</em> = 798 ( campaign id 1553454 has got 798 clicks in 3rd(6am to 9am) window of day till now for 3rd April 2022 ), <em>campaign_1553454_030422</em> = 9670 ( campaign id 1553454 has got 9670 clicks 3rd April 2022 till now)</li><li>This Data is published as key-value pair in <strong>Redis, </strong>The Algorithm deciding the <strong>status, position</strong> and <strong>Boost intervals</strong> consumes the data from here.</li><li>As soon as the promised quota is fulfilled, the campaign is at back of the rail to give other campaigns visibility</li></ul><h3>How was event Drop Rate dropped to 0?</h3><blockquote><em>Consider this once scenario, user saw a rail having multiple ads, clicked few and then closed the app switched off the network. let’s say this happened at 4:37 p.m, now user opens the app again at 7:02 am next day. the app will send this event to the server at this time only, but as the actual click happened a day before it should have been counted in the previous window only. Now in this case events are dropped</em></blockquote><p>There are <strong>3</strong> different notions of time in streaming Programs :</p><ul><li><strong>Processing Time</strong>: Processing time refers to the system time of the machine that is executing the respective operation</li><li><strong>Event Time</strong> : Event time is the time that each individual event occurred on its producing device.</li><li><strong>Ingestion Time</strong> : Ingestion time is the time that events enter Flink</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/0*avPOM2KavCtFau9k.png" /></figure><p>So, what we did was that all the aggregations were done on Event Time contrary to Processing time as used to happened in Apache Spark</p><p><strong>How Was the pipeline made entirely Fault Tolerant?</strong></p><blockquote><em>One word : Checkpointing</em></blockquote><p>The fault tolerance mechanism was to consistently recover the state of data streaming applications. The mechanism ensures that even in the presence of failures, the program’s state will eventually reflect every record from the data stream <strong>exactly once. </strong>The fault tolerance mechanism continuously draws snapshots of the distributed streaming data flow</p><p>In case of a program failure (due to machine-, network-, or software failure), Flink stops the distributed streaming dataflow. The system then restarts the operators and resets them to the latest successful checkpoint. The input streams are reset to the point of the state snapshot.</p><p>We used RocksDB for checkpointing, RocksDB is an embedded key-value store with a local instance in each task manager.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2058f3662b47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing the experience of Writing over Canvas/whiteboard in Live Classes: Unacademy]]></title>
            <link>https://aayushguptaaa.medium.com/enhancing-the-experience-of-writing-over-canvas-whiteboard-in-live-classes-unacademy-a075a096591b?source=rss-a873b26b1642------2</link>
            <guid isPermaLink="false">https://medium.com/p/a075a096591b</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[system-architecture]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Aayush Gupta]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 17:15:47 GMT</pubDate>
            <atom:updated>2023-04-26T17:15:47.055Z</atom:updated>
            <content:encoded><![CDATA[<p>I interned at <strong>Unacademy</strong> back in 2019 where I got to work on Enhancing the experience for Educators who write over Canvas/Whiteboard.</p><h3>The Problems</h3><ul><li>Lot of <strong>Aliasing</strong> is there, the <strong>curves </strong>and<strong> strokes</strong> are not smooth</li><li>It doesn’t mimic the <strong>strokes width</strong> which happens while we are actually writing i.e. width of strokes should be t<strong>hin when we write fast</strong> and <strong>thick when writing slow</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zTcjD2iz7nX3z3zK.png" /></figure><p><strong>How solving these problems are going to help users?</strong></p><ul><li>Makes the <strong>Writing</strong> over virtual Canvas <strong>easier</strong>, as it gives the <strong>real writing experience</strong></li><li>Makes <strong>handwriting</strong> more <strong>understandable</strong></li></ul><h3>The How?</h3><p><strong>Smoothening</strong></p><p>I used Savitzky–Golay filter which uses least squares to regress a small window of the data onto a polynomial, then uses the polynomial to estimate the point in the center of the window. Finally the window is shifted forward by one data point and the process repeats. This continues until every point has been optimally adjusted relative to its neighbours. I defined the number of iterations and in each iteration tried to find the best curve and keep the<br>error below the given Maximum Error. It learns from the current points and accordingly changes the alignment of previous points to find the best curve.</p><p>Parameters that decides the smoothness are:<br>• Squared error between points and fitted curve</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/0*cjpPVNGml_zqjvSO.png" /></figure><p><strong>Speed dependent variable width</strong></p><p>Variable width is achieved by drawing perpendiculars to a line, length of the perpendicular is calculated according to the speed with which mouse is moving, ends of two adjacent perpendicular lines are joined to form a quadrilateral and then it’s filled.</p><p>Parameters that decides the width of stroke are:<br>• Distance between two consecutive points( Directly proportional to speed)<br>• Canvas Width and height<br>• Speed Dependence exponent</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/0*W_Zu_42-fkYuiKqR.png" /></figure><h3>Results</h3><p>Here are side by side comparisons of the lectures with pen option with and without the features of smoothing and real looking strokes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YwZHMHz1J4tR9KAC.png" /></figure><p>Before vs After</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C9cBDgnzHrQgxeL1.png" /></figure><p>Before vs After</p><p><strong>Tech Stack</strong> : The entire code was written in React Framework</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a075a096591b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>