<?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[engineering-udaan - Medium]]></title>
        <description><![CDATA[Read about how udaan’s engineering team is building India’s largest B2B eCommerce platform, serving millions of small retailers across the country. - Medium]]></description>
        <link>https://udaan.dev?source=rss----bd0ab722bd7b---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>engineering-udaan - Medium</title>
            <link>https://udaan.dev?source=rss----bd0ab722bd7b---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 04:29:37 GMT</lastBuildDate>
        <atom:link href="https://udaan.dev/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[Why Our “Optimal” Routes Kept Missing Delivery Slots]]></title>
            <link>https://udaan.dev/why-our-optimal-routes-kept-missing-delivery-slots-b16a5e801445?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/b16a5e801445</guid>
            <category><![CDATA[supply-chain]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[operations-research]]></category>
            <category><![CDATA[logistics]]></category>
            <dc:creator><![CDATA[Udaykiran]]></dc:creator>
            <pubDate>Thu, 23 Jul 2026 08:33:18 GMT</pubDate>
            <atom:updated>2026-07-23T08:33:16.861Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ullLuJFuyWVyT8zoNbJomg.png" /></figure><p>Imagine a hotel preparing breakfast for hundreds of guests. A delivery truck arrives only a few minutes late, but those minutes ripple outward: chefs wait, staff improvise, and service falls behind before the day has properly begun. That is what last-mile reliability looks like from the customer’s side.</p><p>We discovered something surprising: our routing engine produced routes that looked mathematically optimal, yet drivers still missed delivery slots. The algorithm wasn’t broken. Its model of reality was.</p><h3>TLDR;</h3><ul><li>What this post is about: How we solved slot-based routing for HoReCa logistics by building realistic time models and prioritization-aware routing</li><li>Who it’s for: Supply chain and logistics engineers, operations researchers, and teams building last-mile delivery systems</li><li>What you’ll learn: How data-driven transit and dwell time modeling, geographic clustering, and priority-aware sequencing transformed routing from distance-minimization to promise-keeping</li></ul><h3>Problem</h3><p>In last-mile logistics, customer time promises and routing efficiency often work against each other.</p><p>For HoReCa (Hotels, Restaurants, and Catering) orders, where dwell time — the time a vehicle spends at a buyer location after arrival, including unloading, verification, quality checks, and handover — can vary significantly, and customers expect strict adherence to delivery windows, our routing system struggled with:</p><ul><li><strong>Over-optimistic transit time estimates</strong>: Transit time — the time required for a vehicle to travel between consecutive delivery drops — was initially estimated using generic travel-time models. These models relied on coarse, network-level averages and overlooked local geographical nuances, resulting in estimates that did not accurately reflect vehicle movement within specific HoReCa operating zones.</li><li><strong>Inconsistent prioritization of deliveries</strong>: Route planning did not adequately account for differences in delivery importance or service commitments, increasing the risk of missed timelines.</li><li><strong>Slots were not treated as hard routing constraints</strong>: Last-mile routing optimized for feasible delivery plans, but buyer delivery windows were not modeled strongly enough during route sequencing. As a result, a route could look efficient on paper while still missing committed slots during execution.</li><li><strong>Cost vs. adherence trade-off</strong>: Attempting to guarantee slot adherence for every buyer led to higher costs and severe under-utilization of vehicles. To ensure near-perfect timing, vehicles had to be dispatched with fewer orders and more unused capacity, making the operation economically unsustainable.</li></ul><p>The result: Routes that appeared optimal on paper often failed in execution, resulting in missed delivery slots, frequent manual interventions, and increased pressure on operations teams.</p><h4>The “Promise vs. Reality” Gap</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d88xiG3b72d5daRnnopDmQ.png" /></figure><p>Even small timing errors compound into broken downstream slot commitments.</p><h3>Approach</h3><h4>Key Idea</h4><p>A route is only optimal if it can realistically honour customer time slots without increasing last mile costs.</p><p>Every optimization problem begins with assumptions. Improving the search algorithm would not help if travel and service-time assumptions remained wrong. Better optimization had to begin with a better model of the operation.</p><p>Instead of approaching this as a vanilla distance and time optimization problem, we formulated this as a slot-based delivery-priority-aware last mile route optimization problem. This required aligning three foundational elements:</p><ol><li>Customer Slot Commitments: Time windows became first-class constraints, not soft preferences. High-priority deliveries were explicitly prioritized during route sequencing.</li><li>Realistic Time Modeling: Replaced generic assumptions with data-driven dwell-time and transit-time models that better reflected how HoReCa deliveries operate on the ground.</li><li>Time-Consistent Optimisation: A unified model where travel time between stops, unloading time at each buyer, and committed delivery slots are planned together. This removed the earlier disconnect where different parts of the system used different assumptions about time.</li></ol><h4>Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PFnTWqhLeOw7LX4x05-Qtg.png" /></figure><h3>Implementation</h3><p>The implementation had two layers: first, predict execution more honestly; then, optimize against those predictions. This distinction mattered because a sophisticated solver cannot rescue unrealistic inputs.</p><h4>1. Data-Driven Transit Time Model</h4><p>We built a transit time model that uses actual trip data to estimate travel times between stops, instead of relying on fixed assumptions.</p><p>How the model is built:</p><ul><li>GPS and historical trip data capture the actual time different classes of vehicles take to travel between delivery areas at different time points during the day</li><li>Travel patterns are learned separately by hub, time of day, and weekday</li><li>Distances and effective speeds are derived from completed trips, not fixed assumptions</li></ul><p>Key features:</p><ul><li>Hub-specific calibration captures congestion and exit delays</li><li>Time-of-day and weekday segmentation reflects traffic variation</li><li>Empirical distance-time grounding replaces theoretical shortest paths</li><li>Execution-derived speeds capture signals like traffic lights, parking search, and micro-route friction</li></ul><p>This shift moved transit estimation from optimistic theoretical routing to execution-realistic travel prediction, forming a reliable temporal backbone for slot-based optimization.</p><h4>2. HoReCa-Specific Dwell Time Modeling</h4><p>HoReCa buyers exhibit high dwell-time variance. One-size-fits-all timing fails quickly because HoReCa deliveries differ widely in order size and handling effort. We observed that HoReCa buyers typically have:</p><ul><li>Mixed assortments such as staples, FMCG, fresh, eggs, and meat, which take different amounts of time to unload and verify</li><li>Deliveries to higher floors, which require more movement from the vehicle to the handover point</li><li>High tonnage per buyer, increasing unloading effort</li><li>Strong dependence on buyer behavior, outlet type (Hotel, Restaurant, PG, Caterer, etc.) and the outlet’s operational scale</li></ul><p>How the dwell-time model is built:</p><ul><li>The model is trained using historical delivery records where the actual dwell time at each buyer location is known. By learning from past deliveries, it identifies patterns between buyer characteristics, order details, and the time spent at each stop. These insights are then used to predict dwell times for future deliveries with much greater accuracy.</li></ul><p>Key feature groups used in prediction:</p><ul><li>Category mix (FMCG, staples, fresh, etc.) reflects product-specific handling requirements and unloading patterns. For example, a fresh-and-meat-heavy order may need more careful checks than a staples-only order.</li><li>Order tonnage indicates order size and total weight to be delivered</li><li>Total and unique order lines capture the total count of items and unique products across categories, reflecting picking, sorting, and verification complexity</li><li>Total order volume represents the physical space and handling effort required</li><li>Buyer class (enterprise, large, medium, or small) reflects transaction time differences. Large and enterprise buyers often take more time to complete transactions.</li></ul><p>This meant that the planned time at each stop was based on what actually happens on the ground — taking into account the effort required to unload, the mix of products being delivered, and the size of the buyer. As a result, delivery schedules became far more realistic and reliable.</p><p>This was the first major lesson from the build: historical execution data was more valuable than a cleaner theoretical assumption. Once transit and dwell estimates reflected the operation, every downstream routing decision improved.</p><h4>3. Geography-Aware Route Optimisation</h4><p>To make routes easier to execute and reduce unnecessary overlap, geographical proximity was built directly into the route optimisation logic.</p><p>The optimiser was designed to assign nearby buyers to the same vehicle wherever possible, while still considering delivery slots, vehicle capacity, travel time, and overall route efficiency. This created more compact routes without relying on fixed geographic clusters.</p><p>Why route overlap is operationally harmful:</p><p>Route overlap occurs when multiple vehicles serve buyers in the same or nearby geographic pockets instead of operating within clearly defined territories. While this may appear harmless in planning, it creates several real-world execution problems:</p><ul><li>Driver territory ownership: On-ground drivers typically prefer operating within familiar areas; sending a driver into another driver’s zone creates resistance, confusion, and coordination overhead</li><li>Unnecessary travel distance: Overlapping routes make vehicles cover the same locality multiple times, increasing total kilometers travelled and fuel consumption</li><li>Higher operating cost: Extra distance and time directly translate into higher last-mile delivery cost per drop</li><li>Reduced slot reliability: When a vehicle takes detours across another route’s area, arrival times become harder to predict and later buyer slots are more likely to be missed</li><li>Operational complexity: Overlap makes monitoring, escalation handling, and accountability harder for control-tower and field teams</li></ul><p>By incorporating geographical proximity into the optimisation itself, the system produced more compact routes, reduced overlap, and improved delivery-slot adherence.</p><h4>4. OR-Tools Based Route Optimisation</h4><p>Geography-aware assignment and delivery-priority sequencing provided the foundation, while the core route optimisation was handled by Google OR-Tools. We extended its Vehicle Routing Problem solver with domain-specific constraints and logic tailored to HoReCa delivery operations.</p><p><strong>Cluster-Guided Initialization</strong></p><p>Rather than starting from scratch, we give the solver a head start using <em>k-means</em> clustering:</p><ul><li>Delivery points are grouped into a configurable number of geographic clusters</li><li>These clusters are mapped into initial route plans and passed directly to the solver</li><li>This drastically reduces the search space, allowing the solver to find viable solutions faster</li></ul><p><strong>Cross-Cluster Penalization</strong></p><p>To prevent vehicles from hopping between distant areas, a common cause of route inefficiency, we implemented a penalization system:</p><ul><li>Transition Penalty: When a vehicle moves from one cluster to another, a penalty is added to the travel duration</li><li>Distance-Based Scaling: The penalty increases with the distance between geographic areas. Longer jumps beyond a defined distance threshold incur a penalty up to 10 times higher than shorter cross-area movements.</li><li>Cluster boundary limit: A custom constraint counts cross-cluster boundary crossings and keeps them within a configured limit</li></ul><p>This ensures routes remain compact and localized, reducing unnecessary travel distance.</p><p><strong>Multi-Dimensional Constraints</strong></p><p>Our VRP module enforces operational realities through OR-Tools’ “Dimensions” system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TeDQvMAf-7AKU9G5d9QfIQ.png" /></figure><p><strong>Advanced Solution Strategies</strong></p><p>We fine-tune OR-Tools’ search parameters to improve solution quality and routing efficiency.</p><ul><li>First Solution: SEQUENTIAL_CHEAPEST_INSERTION builds routes incrementally</li><li>Metaheuristic: GUIDED_LOCAL_SEARCH escapes local minima by penalizing suboptimal features</li><li>Local Neighborhood Search (LNS): Destroys and recreates route subsections to find improvements</li><li>TSP Optimizers: Two-Opt, Relocate, Swap-Active, and Exchange operators untangle crossed routes</li><li>Full Propagation: All constraints evaluated at every step, avoiding wasted effort on infeasible paths</li></ul><p>This combination of smart initialization, domain-aware penalization, and rigorous constraint enforcement produces routes that are both optimal in theory and executable in practice.</p><p>But route assignment was only half the problem. A well-formed trip could still fail if its stops were visited in the wrong order.</p><h4>5. Slot-Aware and Priority-Aware Intra-Cluster Sequencing</h4><p>OR-Tools based optimization alone is not enough. The order of stops inside a cluster or trip determines whether time slots are actually met.</p><p>Stops within a trip are sequenced based on:</p><ul><li>Customer segment</li><li>Committed delivery slot start and end time</li><li>Predicted dwell time + transit time feasibility</li><li>Vehicle capacity</li><li>Order tonnage</li></ul><p>Customers with tighter delivery windows or more critical commitments are scheduled earlier within their feasible time ranges, rather than simply being placed earlier based on geography. At every step, the sequencing logic checks whether the remaining stops can still be completed on time, helping prevent one delay from cascading across the rest of the route.</p><p>Intra-Cluster Sequencing Concept:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F6okvvQ32k5CrCx7XKrspg.png" /></figure><p>This ensures that:</p><ul><li>Slot adherence is preserved within the trip, not just across vehicles</li><li>Priority promises remain protected even under small execution delays</li><li>Routes remain operationally executable, not just geographically efficient</li></ul><h3>Results</h3><p><strong>Grounded in real execution data:</strong> Metrics are derived from driver-marked delivery completions during live trips, capturing actual arrival and completion times rather than planned estimates. Execution data showed immediate and dramatic improvement.</p><h4>Key Outcomes:</h4><p><strong>Significant improvement in slot adherence:</strong> Before the rollout, fewer than one-third of deliveries were completed within their committed slots. After implementation, slot adherence increased to nearly 90%.</p><h4>Slot Adherence Over Time</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vB-6h2LwvXohoeA32Fug9g.png" /></figure><h4>Transit Time Error Reduction</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*3Rr8jWjZw1AnXI5YH9SmiA.png" /></figure><h4>Operational Impact</h4><ul><li>Median transit-time error reduced from approximately 70% to 20%</li><li>Fewer delivery time-window violations</li><li>Improved on-time performance for deliveries with tighter commitments</li><li>Reduced need for manual intervention by operations teams</li></ul><h3>Tradeoffs</h3><p><strong>Adherence vs. Efficiency</strong>: As the data shows, after peaking near 90%, slot adherence was intentionally stabilized into a significantly improved range. The optimizer could push adherence even higher by adding larger time buffers, assigning fewer buyers per vehicle, and keeping more spare fleet capacity. However, that would reduce vehicle utilization and increase cost per drop. The practical goal was not to maximize adherence at any cost, but to find a zone where most delivery promises were protected while vehicles still carried enough orders to keep the route economically viable.</p><p><strong>Model complexity</strong>: The data-driven transit and dwell time models require continuous maintenance and retraining as operating conditions change. Traffic patterns, buyer behavior, order composition, unloading effort, and hub-level execution practices all drift over time. If these models are not refreshed, the optimizer may again start planning routes using stale assumptions, causing the gap between planned and actual execution to widen.</p><p><strong>Computational overhead</strong>: Geography-aware assignment, slot constraints, vehicle capacity checks, and priority-aware sequencing add computational complexity to route optimization. The solver now has to evaluate not just distance, but also whether each route can satisfy committed delivery windows after accounting for travel time and dwell time. This makes planning more realistic, but it also requires careful tuning of solver parameters and runtime limits so route generation remains fast enough for daily operations.</p><p><strong>Data dependency</strong>: The system relies on high-quality historical execution data from completed trips. Driver-marked stop completion times, GPS traces, order attributes, buyer characteristics, and hub-level patterns are all important for training reliable estimates. New hubs, new buyer pockets, or routes with limited history remain harder to model because the system has less evidence about actual travel speed, unloading time, and local operating constraints.</p><h3>Conclusion</h3><p>Reliable last-mile logistics is not just about shorter routes. It is about keeping promises while still running an efficient operation.</p><p>The fundamental shift was moving from optimizing what looked efficient on paper to optimizing what actually holds up in execution. A route with low distance is not useful if the vehicle reaches buyers outside their committed windows. By replacing optimistic transit assumptions with data-driven time models, treating slots as hard constraints rather than soft preferences, and sequencing stops around real dwell and travel behavior, we closed the gap between planned and delivered routes.</p><p>The results speak for themselves: slot adherence rose from under one-third to nearly 90%, transit time error reduced from approximately 70% to 20%, and operations teams spent far less time firefighting broken plans. The deeper win is architectural: routing decisions are now grounded in execution reality, including how vehicles move through a city, how long unloading takes at different buyer types, and how delivery commitments should influence stop order.</p><p>This makes the plan more useful for every stakeholder. Drivers receive routes that are easier to execute, operations teams get fewer last-minute escalations, and customers experience more predictable deliveries. Every planned route is now closer to a route we can actually keep, and that reliability compounds across every downstream commitment we make.</p><h3>Next Steps</h3><p>This transformation is only the beginning. The same routing foundation can be extended to other delivery motions, but each category introduces different operational constraints.</p><p>Food and FMCG routes have different service expectations compared with HoReCa. These routes may require better handling of higher stop density, demand surges, and different vehicle utilization patterns.</p><p>In upcoming posts, we will explore how these variants handle demand surges, driver behavior, route compactness, and more detailed implementation choices. We will also cover how routing decisions change when the objective shifts from improving slot adherence alone to balancing adherence, fleet cost, vehicle utilization, and operational resilience together.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b16a5e801445" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/why-our-optimal-routes-kept-missing-delivery-slots-b16a5e801445">Why Our “Optimal” Routes Kept Missing Delivery Slots</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Actionable Recommendations for Market Managers: The Push-List Approach]]></title>
            <link>https://udaan.dev/actionable-recommendations-for-market-managers-the-push-list-approach-bf609b7694c6?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/bf609b7694c6</guid>
            <category><![CDATA[recommender-systems]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Anand Choudhary]]></dc:creator>
            <pubDate>Fri, 26 Jun 2026 05:13:39 GMT</pubDate>
            <atom:updated>2026-06-26T05:13:38.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Every morning, thousands of udaan Market Managers step into India’s vibrant, chaotic markets carrying a simple but heavy responsibility: to help millions of <strong>kirana</strong> (traditional Mom &amp; Pop) entrepreneurs make the right buying decisions at the right time. To make that mission more precise and data-driven, we built the <strong>Push-List</strong>, a multi-signal recommendation engine that replaces generic top-seller lists with hyper-localized daily shortlists.</p><p>In India’s retail space where a storefront’s physical footprint is measured in square feet, inventory space is premium real estate. Behind every single product recommendation is a critical choice that directly impacts a small retailer’s working capital, inventory turnover, and ultimately, their livelihood.</p><p>Unlike consumer e-commerce, India’s retail landscape operates through assisted selling, fragmented demand, sparse digital signals, and highly localized buying behavior. This makes the offline-to-online digitization of this ecosystem a fascinating technical frontier. The engineering challenge at udaan was way beyond building another standard recommendation engine; it was about architecting intelligence that survives and thrives in the unique chaos of Bharat’s commerce.</p><h3>TLDR;</h3><p>We have deployed field sales representatives in udaan that visits kirana shops to onboard retailers and drive repeat orders. These field sales representatives are called <strong>Market Managers (MMs)</strong>.</p><ul><li><strong>The Problem:</strong> Empowering India’s kirana ecosystem to make better business decisions through data intelligence delivered to the last mile.</li><li><strong>The Solution:</strong> A multi-signal recommendation engine that delivers a daily Top K product list.</li><li><strong>The Impact:</strong> 22% basket size increase and 15% lift in high-margin product adoption.</li></ul><h3>Problem</h3><p>In the fragmented domain of traditional B2B trade, empowering frontline teams means solving an immense problem of data scale and signal quality. Market Managers must optimize supply chains and inventory choices across thousands of independent kirana storefronts while navigating a highly volatile product catalog characterized by dynamic pricing and shifting hyper-local availability.</p><p>In the high-stakes world of B2B e-commerce, Market Managers (MMs) are the drivers of daily operations and revenue. Every morning, Market Managers (MMs) in B2B e-commerce face a critical decision: <strong>Who do I visit today, and what exactly should I pitch?</strong></p><p>With only a few minutes to convert a sale, getting this wrong means losing client’s attention and trust.</p><ul><li><strong>The Context Gap:</strong> Generic “Top Seller” lists ignore buyer-specific needs. Pitching flour to a baker who stocked up yesterday is an inefficient rookie mistake.</li><li><strong>The Data Desert:</strong> Sparse user interaction data makes it hard to derive meaningful insights from browsing behaviour alone.</li><li><strong>The “Average” Trap: </strong>One-size-fits-all recommendations ignore business attributes, purchase cycles, and local demand patterns.</li></ul><p><strong>The core constraint? </strong>Time. Market Managers need a <strong>short, pre-ranked list </strong>they can act on immediately, not a catalog to sift through.</p><h3>Approach</h3><p>We built <strong>The Push-List:</strong> a unified recommendation engine that transforms billions of data points to produce a daily shortlist of exactly K high-conversion likelihood products.</p><p><strong>The Human + AI Philosophy</strong>: The Push-List doesn’t replace the judgment of our Market Managers. Instead, it provides them few moments of clear, actionable insight. This frees our frontline teams from administrative guesswork, allowing them to focus entirely on building trust, nurturing relationships, and driving persuasion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ery2umyQcfemmkNrL7Svkw.png" /></figure><h3>Why Push List ?</h3><p>The Push-List is a time-saving tool designed for speed and precision rather than another list of products. Here is how it solves the core challenges:</p><ul><li><strong>Precision over Volume:</strong> We moved away from “what sells the most” to “what does this specific buyer need right now?” The Market Manager acts as the consultant, validating the recommendation using their real-world knowledge of the shop.</li><li><strong>Respecting the Clock:</strong> By limiting recommendations to a focused Top K, we eliminate choice paralysis and cognitive load, allowing Market Managers to pitch confidently within that crucial few-minute window.</li><li><strong>Intelligent Prioritisation:</strong> The engine accounts for purchase history and timing, ensuring we never pitch a product to a client who is already fully stocked.</li></ul><h3>What We Didn’t Build (And Why)</h3><ul><li><strong>Pure Collaborative Filtering:</strong> Sparse data in B2B e-commerce; many buyers have less than 5 purchases.</li><li><strong>Single LightGBM Model:</strong> Black box model; Market Managers couldn’t understand why items were recommended.</li><li><strong>Real-Time Deep Learning: </strong>Overkill for daily batch updates; inference latency not needed.</li><li><strong>Third-Party Recommendation Systems : </strong>Couldn’t encode B2B constraints like margin, inventory and clusters.</li><li><strong>Top Sellers Only: </strong>Already tried model; ignores buyer-specific context.</li></ul><p><strong>The Lesson:</strong> In B2B, <strong>interpretability &gt; sophistication.</strong></p><p>The ensemble’s signal-based slots give Market Managers an intuitive mental model for each recommendation, unlike a single opaque gradient boosted score. Market Managers trust the system more when they can validate the logic.</p><h3>Key Idea</h3><p>We designed a <strong>triple-threat ensemble architecture</strong> that listens to three distinct behavioural signals:</p><ol><li><strong>The Heartbeat (Replenishment):</strong> When will buyers run low on purchased products? It ensures that we capture the recurring revenue without manual intervention.</li><li><strong>The Hyper-Local Pulse (Geo-Trends):</strong> What’s trending in specific neighbourhoods? It capitalises on local demand spikes and trending products.</li><li><strong>The Digital Breadcrumb (App Activity):</strong> What did buyers recently view or add to cart? It tries to convert high-intent browsing into sales.</li></ol><p>These signals are merged through a custom <strong>Slotting Engine</strong> that balances conversion probability with strategic business goals (margin formation, inventory movement).</p><h3>Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0LgstVJwrLRFZh5NuGuAzg.png" /></figure><p><strong>The Brain:</strong> A custom merger that distributes K slots across signals in fixed proportions so the list isn’t dominated by a single signal on any given day.</p><p><strong>The Overlay:</strong> We inject margin-makers (high-margin private labels, key value items, and near-key value items) to balance volume with profitability.</p><p><strong>The Flow: </strong>Rather than viewing the system as isolated technical boxes, the data flow can be traced across a single continuous narrative as</p><ul><li><strong>Millions of Transactions:</strong> Ingesting raw, historical B2B invoice lines across our entire commerce platform.</li><li><strong>The Purchase Heartbeat:</strong> Predicting unique replenishment cycles at a buyer-product specific level.</li><li><strong>Neighborhood Intelligence:</strong> Aggregating regional buying trends via H3 geospatial grids to solve local data sparsity.</li><li><strong>Digital Intent:</strong> Capturing real-time app interactions like views and cart additions via a priority funnel.</li><li><strong>Business Constraints:</strong> Overlaying profit margins, inventory availability, and product category mixes.</li><li><strong>The Push-List:</strong> Delivering a curated, 20-slot daily checklist straight to our Market Managers’ mobile screens.</li></ul><h3>Implementation</h3><h4>1. The Math of “When” (Replenishment via Modified Poisson Gamma)</h4><figure><img alt="MPG model graphs showing Repeat Rate and Purchase Probability against ‘days since last purchase’" src="https://cdn-images-1.medium.com/max/1024/1*nEzI2NbF4FO7FCfZXteJhA.png" /></figure><p>We moved beyond simple averages. Replenishment is buyer-product specific, not a single average across either dimension. Using a <strong>proprietary adaptation of the Poisson Gamma </strong>framework, we estimated a buyer’s unique purchase “heartbeat”.</p><ul><li><strong>The Logic:</strong> The model predicts the purchase probability for any user-item pair by analysing historic purchase attributes and the number of days since last purchase.</li><li><strong>The Recency Penalty:</strong> We calculated the average interval ( <em>t_mean</em> ) and added a critical constraint. If a buyer exceeds their usual product interval by ( 2 × <em>t_mean</em> ), the model realises the pattern is broken (perhaps they switched to a different item) and de-prioritises the item by applying a recency based penalty.</li><li><strong>Why this works:</strong> Unlike simple averages, the Modified Poisson Gamma (MPG) model handles <strong>irregular purchase patterns</strong> and applies a <strong>recency penalty</strong> which helps us to assess buyer’s product specific behaviour in real time.</li></ul><h4>2. The Geometry of “Where” (H3 + Greedy Clustering)</h4><p>Trends are neighbourhood-specific, but data can be sparse. To solve this, We used an open-source geospatial indexing system <strong>H3 hexagonal grid </strong>to map buyers spatially, then applied an <strong>Iterative Greedy Merger</strong> to solve sparsity.</p><ul><li><strong>Clustering:</strong> Geospatial clustering helps us to understand what is selling in a neighbourhood.</li><li><strong>Solving Sparsity:</strong> By using Iterative Greedy Merger, algorithm automatically absorbs “weak” neighbours (hexagons with low buyer counts) into <strong>larger, statistically significant clusters.</strong></li><li><strong>The Human Touch:</strong> Numeric cluster IDs like 8528347 mean nothing to sales teams. We built a <strong>phonetic name generator</strong> to create memorable identifiers: KOPA, ZITI, MELA.</li></ul><h4>3. The Digital “Window Shopping” (App Priority Funnel)</h4><p>Not all app events are equal. We need to establish hierarchy based on purchase intent to ensure we capture the most actionable signals.</p><ul><li><strong>Signal Extraction &amp; Ranking:</strong> We built a <strong>priority-ranked signal extraction</strong> to capture intent. We ranked these by frequency and recency.</li></ul><ol><li><strong>Add to Cart (Priority 1):</strong> High-intent signal. The user wants the product now.</li><li><strong>Listing Impression (Priority 2): </strong>General interest. The user is browsing the product.</li></ol><h4>4. The Business Overlay (Margin Formation)</h4><p>Data is great, but profit matters. We added a final layer of business intelligence through different measures.</p><ul><li><strong>Context Tags:</strong> We attach useful tags to every item to help the Manager frame their pitch (e.g., “Trending in KOPA”, “Price Drop”).</li><li><strong>Strategic Insertion:</strong> We deliberately slot in Margin Makers and incentive-driven products to ensure the sales mix is healthy for the company’s bottom line.</li></ul><h4>5. The K-Slot Brain (The Slotting Engine)</h4><p>The final Push-List isn’t random, it’s a <strong>strategically balanced allocation.</strong></p><ul><li><strong>Conversion Possibility Score:</strong> We calculated this weighted score based on attributes at the buyer, cluster, and city levels derived by Wilson Score (statistical method to calculate confidence interval for a proportion) corresponding with pre-defined thresholds.</li><li><strong>Slot Ranking Formula:</strong> We then apply a category adhered strategic mix (Replenishment, Geo-trends, and App activity) to fill the slots. This dynamic mix has products recommended by all 3 strategies and ensures a perfect balance of margin-makers and sale drivers.</li><li><strong>The Overflow Safety Net:</strong> New buyers with no app activity? The engine <strong>auto-fills empty slots</strong> with geo-trends to ensure a complete K-item list.</li></ul><h4>6. Production Infrastructure (Scaling to Millions)</h4><p>The pipeline runs daily across millions of buyer-product pairs ensuring:</p><ul><li><strong>Batching &amp; Partitioning:</strong> Since data size was millions, we used batch APIs to update relevant Postgres tables.</li><li><strong>Resilience:</strong> Rigorous timeout and retry logic ensures server hiccups don’t result in data loss.</li></ul><h3>Development Challenges</h3><p>Transitioning the Push-List from concept to production meant navigating a series of critical algorithmic and engineering bottlenecks.</p><p>Initially, we built a user-level collaborative filtering model using dense embeddings (1 for purchase, 0 for no purchase) across our entire product catalog. However, calculating these pairwise across millions of users proved computationally slow and unscalable. Even after converting to sparse matrices, data sparsity and long processing times forced us to abandon this approach and pivot to a decentralized ensemble architecture that slots distinct behavioral signals into a unified list.</p><p>Once the framework was set, balancing items suggested by behavioral signals with margin-makers required tight collaboration with field teams. We mathematically fixed allocation fractions for each signal and built an over-deduplication layer to ensure no products are repeated across slots. Determining the exact positioning and ranking of high-margin items within the list was another puzzle which we solved through product team discussions and by designing a composite score that blends historical conversion rates with active product promotion strategies.</p><p>To improve the accuracy of our rankings, we also had to refine our conversion probability metric: the Wilson Score. Initially calculated only at broad geographic cluster and city levels, we re-engineered the score to ingest buyer-specific signals. We also expanded our definition of a digital “impression” to include high-intent actions like product views and add-to-cart events rather than final purchases only.</p><p>Finally, our early prototypes suffered from severe production infrastructure bottlenecks. The engine generated massive lists containing hundreds of recommendations per buyer, causing widespread API timeouts and delivering delayed or empty lists to Market Managers. We cut the payload to 20 slots to match the fast-paced reality of field visits, and by overhauling our database write layer to use robust batch APIs equipped with retry and timeout circuit breakers.</p><h3>Results</h3><p>To measure the business impact of the Push-List, we tracked performance metrics over a continuous 12-week observation window across all operational markets. Because the system was scaled directly to production across our entire network, we utilized a pre-vs-post rollout analysis.</p><p>This long observation window allowed us to establish our baseline data while the system was offline and stabilize and scale the changes to all markets while troubleshooting infrastructure bugs and optimizing ground recommendation quality. The final weeks data represented the steady-state post-rollout period where the human+AI loop operated at full scale.</p><p>We tracked metrics weekly to smooth out day-to-day fluctuations. We tracked Average Basket Size (ABS) separately for Staples and FMCG (Fast-Moving Consumer Goods), as they operate independently. High-margin product metrics were evaluated by tracking both the weekly number of distinct buyers purchasing those items and the average variety of unique high-margin items ordered per buyer.</p><h4>Quantitative Impact (Bengaluru Pilot)</h4><p>The data shows a clear basket size boost and increase in high-margin items adoption. Here is the tangible impact we witnessed after deploying the Push-List in Bengaluru.</p><figure><img alt="Quantitative results from the Push-List pilot" src="https://cdn-images-1.medium.com/max/1024/1*LVOT_xfl91a7XD_Lg5Bijg.png" /></figure><p><strong>Basket Size Boost:</strong></p><p>Because we predicted needs accurately, buyers bought more per visit:</p><ul><li>+22% Average Basket Size increase for Staples.</li><li>+18% Average Basket Size increase for FMCG (Fast-Moving Consumer Goods).</li></ul><p><strong>Margin Maker Effect:</strong></p><p>By strategically slotting high-margin items and related products into the list, we saw:</p><ul><li>+15% increase in weekly users buying Margin Maker products.</li><li>+9% increase in the average quantity of Margin Maker items ordered per user.</li></ul><h4>Qualitative Wins</h4><ul><li><strong>Reduced Prep Time: </strong>Market Managers shifted from <strong>administrative list generation</strong> to <strong>strategic sales execution.</strong></li><li><strong>Confidence Boost:</strong> Top 3 slots now consistently contain high-probability items, so no scrolling is needed.</li><li><strong>The “Nudge” Strategy:</strong> By training our Geographic-model on the <strong>75th percentile</strong> of historical quantities instead of average, we nudged buyers toward aspirational yet realistic volumes without pushback, <strong>directly driving GMV growth.</strong></li><li><strong>Context Tags</strong>: Managers can now frame pitches with data-driven tags like “Trending in your area”. It acts as collaborative, data-backed business recommendation that helps the retailer optimize their capital.</li></ul><h3>Edge Cases We Handle</h3><h4>1. The “Stockout” Problem</h4><p><strong>Scenario:</strong> Push-List recommends any item, but warehouse is out of stock.</p><p><strong>Solution:</strong></p><ul><li>Daily inventory sync filters out unavailable items before scoring.</li><li>Fallback: Replace with next-best item from same category.</li></ul><h4>2. The “New Buyer” Cold Start</h4><p><strong>Scenario: </strong>Buyer has zero purchase history.</p><p><strong>Solution:</strong></p><ul><li>Use Geo-cluster trends (similar businesses in same area).</li><li>Bootstrap with “industry starter pack” (e.g., Bakery Essentials).</li><li>After first purchase, replenishment model kicks in.</li></ul><h4>3. The “Seasonal Spike” Anomaly</h4><p><strong>Scenario:</strong> Occasional events drives 10x demand for certain items.</p><p><strong>Solution:</strong></p><ul><li>Geo-trend model naturally captures this (local surge → higher ranking).</li><li>Recency weighting ensures recent spikes override old patterns.</li></ul><h4>4. The “Lapsed Buyer Re-engagement”</h4><p><strong>Scenario:</strong> Buyer stops purchasing staple items and we have to ensure that buyers never run out of key items.</p><p><strong>Solution:</strong></p><ul><li>Recency penalty in MPG model (if <em>t_current</em> &gt; 2 × <em>t_mean</em>, deprioritise).</li><li>Alert Market Manager: “Buyer hasn’t ordered flour in 45 days (usual: 15 days)”.</li></ul><h3>Conclusion</h3><p>The Market Manager’s dilemma about <strong>“Who do I visit and what do I pitch?” </strong>is a universal problem in B2B sales. By moving away from generic “Top Seller” lists and embracing a <strong>multi-signal ensemble</strong>, we turned data into a competitive advantage.</p><p>Technology often promises automation. In commerce, however, the far greater opportunity is augmentation. At udaan, we learned that the best recommendation systems don’t try to replace the people closest to customers. Instead, they help them make better decisions faster and with confidence.</p><p><strong>The Push-List didn’t just organise a catalog, it organised the day.</strong> It transformed chaotic mornings into focused missions, proving that when you give sales teams the right insights, they don’t just sell more but they also <strong>sell smarter. </strong>Because ultimately, behind every algorithm is a kirana entrepreneur trying to grow their business, and a Market Manager standing right there to help them make that happen.</p><h3>Next Steps</h3><p>The Push-List organised the day. The next milestone is about organizing the moment, moving from a static morning snapshot to an anticipatory, real-time recommendation reacting to demand signals during the visit.</p><h4>1. Shifting from Batch to Real-Time Urgency</h4><ul><li><strong>Live Geo-Trend Streaming:</strong> Replace the 12-hour batch cycle with streaming updates, so geo-trend signals reflect localized demand spikes happening at the moment.</li><li><strong>Instant Operational Alerts:</strong> Transition to real-time communication triggers (like instant message alerts) so Market Managers can capitalize on hyper-local demand while it’s hot, not the next morning.</li></ul><h4>2. Predictive Discovery &amp; Solving the Cold Start</h4><ul><li><strong>Neighborhood Collaborative Filtering:</strong> Surface net-new catalog items a buyer hasn’t tried yet by mapping the high-volume purchasing patterns of their regional peers.</li><li><strong>Intelligent Onboarding:</strong> Handle the “cold-start” problem properly. Right now, new buyers get generic geo-cluster defaults. The goal is a lightweight predictive layer that kicks in from day one using regional peer patterns.</li></ul><h4>3. Closing the Data Loop</h4><ul><li><strong>Dynamic Feedback Ingestion:</strong> Every interaction, call outcome, and rejection will feed directly back into the scoring model in real time.</li><li><strong>Continuous Model Refinement:</strong> By closing the loop between recommendation and reality, the system automatically self-corrects, outcomes are fed back as training labels ensuring the precision of the tool sharpens with every single signal.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf609b7694c6" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/actionable-recommendations-for-market-managers-the-push-list-approach-bf609b7694c6">Actionable Recommendations for Market Managers: The Push-List Approach</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we pivoted from App Center and reduce OTA costs by 90%]]></title>
            <link>https://udaan.dev/how-we-pivoted-from-app-center-and-reduce-ota-costs-by-90-45e3de5f9df4?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/45e3de5f9df4</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[appcenter]]></category>
            <category><![CDATA[ota]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Abijith B]]></dc:creator>
            <pubDate>Tue, 26 May 2026 08:37:26 GMT</pubDate>
            <atom:updated>2026-05-26T08:37:25.726Z</atom:updated>
            <content:encoded><![CDATA[<h3>How udaan cut React Native OTA costs by 90% after App Center shutdown</h3><p>In fast-moving commerce products, waiting days for app-store approvals isn’t always an option. At udaan, OTA updates help us ship fixes quickly across multiple React Native apps. When Microsoft announced App Center shutdown, we had to replace a critical release system-without slowing engineering velocity. What followed was an unexpected lesson in cloud costs, bandwidth, and pragmatic infrastructure decisions.</p><h3>Why CodePush Matters to Us</h3><p>At udaan, our user-facing mobile apps support critical commerce and financial workflows for retailers and businesses across the country. These apps are deeply embedded in everyday operations, from product discovery and ordering to inventory planning and credit access. When issues arise in such workflows, delays in resolution can directly affect business continuity. OTA updates help us reduce that risk by allowing urgent fixes to reach users within hours, instead of waiting days for traditional app-store rollouts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dnx6zsnX2M3LCK-Jkby31A.png" /><figcaption>CodePush OTA update vs normal app update</figcaption></figure><p>A React Native app ships with JavaScript files and assets bundled inside a platform-specific binary, such as an APK or IPA. After the app is released, changing JavaScript code or bundled assets normally requires rebuilding the binary, submitting it again, and waiting for store review or rollout.<br>CodePush solves this for JavaScript and asset updates. Instead of shipping a new binary for every small React Native change, we can publish a new JS bundle to a CodePush server. The app checks that server, downloads the update if one is available, and applies it based on the configured install strategy.</p><p>This means no waiting for App Store reviews or slow user adoption. When there is a critical bug, users get the fix the moment they open the app. For regular updates, the process remains smooth: the download happens in the background, and the update applies on the next app launch. Adoption is healthy too.</p><p>So when App Center was scheduled to be <a href="https://github.com/microsoft/code-push-server">shut down on March 31, 2025</a>, we needed a pivot fast.</p><h3>Our Options</h3><p>We were not just choosing an OTA update provider. We had to balance reliability, scale, cost efficiency, migration risk, and team bandwidth without slowing down product delivery.</p><p>As a small frontend team, we needed a solution that kept our release pipeline stable in the short term while giving us enough room to plan a more sustainable long-term migration. That shaped how we evaluated each option.</p><h4>Option 1: Move to Expo Application Services (EAS)</h4><p><a href="https://expo.dev/services">Expo Application Services</a> was the most future-facing option due to its strong Expo ecosystem support, active maintenance, and structured release workflow. It offers cloud builds and OTA update capabilities, making it attractive for long-term maintenance.</p><p>However, adopting EAS would not be a simple drop-in replacement for our current setup, as it would require significant effort to make our existing bare React Native app compatible with Expo and to update the deployment process.</p><p><strong>Pros:</strong></p><ul><li>Actively maintained and backed by the Expo ecosystem.</li><li>EAS also covers more than OTA updates: it can build app binaries, submit them to the stores, and publish compatible OTA updates from the same ecosystem.</li><li>Supports structured deployment workflows using channels, branches, runtime versions, and rollouts.</li></ul><p><strong>Cons</strong></p><ul><li>Requires migration work in an existing bare React Native app.</li><li>Changes the build and release process, not just the OTA update command.</li><li>High cost for our production OTA update usage and user scale.</li></ul><h4>Option 2: Use a third-party CodePush alternative</h4><p>There were a few third-party alternatives available, such as <a href="https://revopush.org/">RevoPush</a>. This would have allowed us to continue using a CodePush-like workflow without owning the infrastructure ourselves.</p><p>The trade-off was confidence. Most OTA service providers in this space were still relatively new, and we did not have enough information about their reliability, operational maturity, or long-term support.</p><p><strong>Pros</strong></p><ul><li>Faster to adopt than a full Expo migration</li><li>Less infrastructure ownership compared to self-hosting</li><li>Similar mental model to CodePush</li></ul><p><strong>Cons</strong></p><ul><li>Unclear reliability and maturity of newer providers</li><li>Vendor dependency for a critical release path</li><li>Risk of needing another migration if the provider changes direction</li></ul><p>This option looked convenient, but we were not comfortable depending on a relatively new external service for such a critical part of our deployment pipeline.</p><h4><strong>Option 3: Host CodePush ourselves</strong></h4><p>The third option was to self-host the <a href="https://github.com/microsoft/code-push-server">open-source CodePush server</a>. This allowed us to keep our existing app and release workflow mostly intact while replacing the hosted dependency.</p><p>This was not a perfect long-term solution. Self-hosting meant we would own the infrastructure, monitoring, maintenance, and any future fixes. But compared to the other options, it caused the least disruption to the team and the product.</p><p><strong>Pros</strong></p><ul><li>Minimal changes to the existing app and deployment pipeline</li><li>No immediate migration to Expo or another platform</li><li>Full control over the OTA update infrastructure</li><li>Gave us time to plan a proper long-term migration</li></ul><p><strong>Cons</strong></p><ul><li>We own the operational responsibility</li><li>Requires infrastructure setup and maintenance</li></ul><p>We chose option 3 because it gave us the best balance between continuity and effort. Our immediate goal was not to redesign the release system, it was to keep OTA updates working without blocking product delivery. Self-hosting gave us control and cost flexibility. It allowed us to keep the existing React Native CodePush integration, preserve the release workflow used by CI/CD and our dashboard, and avoid a rushed migration to a new OTA platform.</p><p>But it also came with clear responsibilities. We now owned the server, storage, monitoring, operational fixes, and future maintenance. Any React Native upgrade also had to be checked against the CodePush SDK used inside the app, because OTA compatibility depends on the native binary and the bundled SDK continuing to work correctly together. For us, that trade-off was acceptable because it reduced immediate migration risk and kept product delivery moving. Self-hosting bought us time to continue shipping updates while we evaluated a proper Expo migration at a more reasonable pace.</p><h3>Hosting Our Own CodePush System</h3><p>Replacing an OTA update system is not a single code change. It touches the full path from bundle generation in CI/CD to update checks on a user’s device. Multiple systems need to work together: the CLI, the server, storage, the client SDK, and the release management UI.</p><p>Let’s start by understanding the CodePush architecture, then look at how we migrated from the hosted CodePush service to our own self-hosted setup.</p><h4>CodePush Architecture</h4><p>At a high level, a CodePush setup has five major parts:</p><ul><li>CodePush CLI</li><li>CodePush server</li><li>Client SDK inside the mobile app</li><li>Storage layer</li><li>Release management UI</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*_9SjzpuGqFRBpSv9zmHs-Q.png" /><figcaption>CodePush release management flow</figcaption></figure><p><strong>The release flow looks like this:</strong></p><ol><li>CI/CD pipeline creates a React Native bundle.</li><li>The CodePush CLI uploads that bundle to the CodePush server.</li><li>The server stores the bundle in blob storage and records release metadata.</li><li>The mobile app asks the server whether an update is available.</li><li>If the app is eligible for an update, the server returns update metadata and a download URL.</li><li>The app downloads, installs, and applies the update using the client SDK.</li><li>Rollout, rollback, and release state are managed through metadata on the server.</li></ol><h4>CodePush CLI</h4><p>The CodePush CLI is the operational tool used to publish updates and manage releases from CI/CD or release workflows. For our setup, the most important CLI responsibility is release publishing. The CLI bundles the React Native changes and uploads the generated bundle to the CodePush server.</p><h4>CodePush Server</h4><p>The CodePush server is an Express.js service. It sits between release producers and mobile clients.</p><p>When a release is published, the server receives the uploaded bundle, stores it, and updates the metadata that describes the release. When a mobile app starts or explicitly checks for updates, the server evaluates whether that app should receive an update. If an update is available, the server responds with metadata and a bundle download URL.</p><h4>Client SDK</h4><p>The client SDK is embedded in the React Native app. Its responsibility is to check for updates, download them, install them, and apply them based on the app’s configured behavior.</p><h4>Storage</h4><p>Our self-hosted setup needs three storage systems.</p><p><strong>Azure Blob Storage: </strong>Blob storage stores the actual JavaScript bundles and assets generated by the CLI. When a client is eligible for an update, it ultimately downloads the update package from this storage-backed URL.</p><p><strong>Azure Table Storage: </strong>Table storage acts as the metadata database. It stores information such as: apps, deployment, releases, package metadata and release history.</p><p><strong>Redis: </strong>Redis is needed for percentage-based rollout and runtime update tracking. CodePush uses it to track rollout-related state such as downloads, successful patching, active devices, and which users or devices are on which release.</p><h4>Release Management UI</h4><p>We already had our own release management UI before this migration. Even when the hosted CodePush service was active, we used our own UI for release operations because it allowed us to enforce our internal rules.</p><p>Our UI helped us manage:</p><ul><li>Who can release a specific app</li><li>Promotion, disable and rollback</li><li>Package size visibility</li></ul><h3>Migration Process</h3><h4>1. Host the CodePush Server</h4><p>The first major step was to fork the CodePush server and host it ourselves.</p><p>The hosted server needs access to:</p><ul><li>Azure Blob Storage for bundle packages</li><li>Azure Table Storage for metadata</li><li>Redis for rollout state</li></ul><p>Once the server was running, it became the new source of truth for apps, deployments, releases, and update checks.</p><h4>2. Configure the CodePush CLI</h4><p>Next, we forked the CodePush CLI and configured it to use our self-hosted server URL.</p><p>This was required because the CLI is used in CI/CD to publish bundles.</p><p>We also generated new access tokens from our self-hosted setup. Those tokens were then used by CI/CD and the release management UI to communicate with the CodePush server.</p><h4>3. Create Apps and Deployments</h4><p>We recreated the required apps and deployments in the new CodePush server.</p><p>For each mobile app, Android and iOS were created separately because they receive different bundles. Each app also needed its required deployments, such as Production and Staging.</p><p>This setup had to be created for every existing app that needed CodePush support.</p><h4>4. Update CI/CD Pipelines</h4><p>The CI/CD pipeline had to switch from the original CodePush CLI to our forked CLI.</p><p>The pipeline changes were:</p><ul><li>Use the forked CLI</li><li>Replace old access keys with new access tokens</li><li>Publish Android and iOS bundles to the self-hosted server</li><li>Preserve the previous release path temporarily for emergency support</li></ul><p>We did not remove the old flow immediately. Keeping it available during the migration reduced risk, especially for older app versions that might still be pointing to the old CodePush service.</p><h4>5. Update the Native Apps</h4><p>The native app change was minimal. We did not need to change the CodePush SDK dependency. We only needed to configure the SDK to use our self-hosted server URL.</p><p>On Android, we added the server URL in <em>strings.xml</em>. On iOS, we added the server URL in <em>Info.plist</em>.</p><p>After this change, we released new Android and iOS binaries. Those binaries started checking our self-hosted CodePush server for updates.</p><h4>6. Continue Release Management Through the Dashboard</h4><p>Since we already had a release management dashboard, we continued using it after the migration. We added the newly created apps to the dashboard and pointed those app configurations to the new self-hosted CodePush server.</p><p>The dashboard remained the operational layer for release managers, while the forked CLI and server handled the underlying CodePush operations.</p><h3>Optimizing the cost</h3><p>By this point, the self-hosted CodePush setup was running in production for two React Native apps: <a href="https://play.google.com/store/apps/details?id=com.udaan.android&amp;hl=en_IN">udaan</a> and <a href="https://play.google.com/store/apps/details?id=com.udaancapital.pratishtha&amp;hl=en_IN">udaanCapital</a>. Across these apps, thousands of users could fetch OTA bundles, and we typically had one or two updates per week.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CVf0KOqL_Kr0SAg5FReAUA.png" /></figure><p>A few weeks in, our cost monitoring dashboard started showing some concerning numbers. The self-hosted setup was already costing much more than we expected, and the trend was moving in the wrong direction.</p><p>From the cost dashboard, we could see it was related to storage, and on Azure we saw that blob storage usage had grown noticeably, so we initially thought this could be the issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7aiZH_pcirCUNgycKBcJg.png" /><figcaption>Monthly cost index for CodePush hosting before optimization</figcaption></figure><h3>First Attempt: Clean Up Storage</h3><p>We built a cleanup endpoint in our CodePush server. It would keep the last 5 bundles (configurable) and delete everything older. We could trigger it from our dashboard whenever storage got too heavy.</p><p>Results were disappointing 😔:</p><ul><li>Storage usage dropped by around 85%</li><li>No change in cost</li></ul><p>Wait, what? A 85% storage reduction for, …, nothing?!</p><h3>The Real Problem</h3><p>After talking with our DevOps team, we figured out what was actually happening. Storage in Azure Blob is dirt cheap. <strong>The real killer was bandwidth cost</strong>, ~₹10 per GB for data transfer. Every time thousands of users downloaded our bundles, we got charged for bandwidth. That’s where the money was going.</p><p>With one or two updates per week, and occasional hotfixes, the cost could increase quickly. You can see the variation in cost from the first screenshot. The number of users also impacts cost, and as we grow, the cost will grow as well. Since users need to download a single file at a time, setting up a CDN would be the best solution for us.</p><p>The bigger lesson was simple: optimizing the wrong bottleneck is common in cloud systems. A large storage reduction looked impressive, but it did not matter because storage was not the real cost driver. Network egress was.</p><h3>Adding CDN</h3><p>Our DevOps team already had a solution in their mind. We already had a Cloudflare contract with plenty of unused bandwidth allowances. Adding a CDN layer wouldn’t cost us anything extra.</p><p>The implementation was simple:</p><p><strong>Before</strong>: CodePush API returns Azure Blob Storage URLs<br><strong>After</strong>: CodePush API returns CDN URLs</p><p>We changed a few lines in our Express server to return CDN links instead of direct blob storage URLs. DevOps configured Cloudflare to cache the blob storage content.</p><p>Here’s how it works:<br><strong>First user downloads an update</strong>: Azure → CDN → User (we pay bandwidth once)<br><strong>All other users</strong>: CDN cache → User (zero bandwidth cost)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*BzYvx0ul4N5ff2saS5tFAQ.png" /></figure><h3>Impact</h3><p>The final impact was measurable:</p><ul><li><strong>90% reduction</strong> in monthly OTA infrastructure cost.</li><li><strong>99.6% reduction</strong> in blob storage-related spending.</li><li>Faster bundle downloads for users through CDN edge caching.</li><li>One self-hosted OTA infrastructure powering multiple React Native apps in production.</li><li>No disruption to release velocity during the App Center migration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mDAHLydmUj_hkZ5hXADiAw.png" /><figcaption>self hosted CodePush system is utilized by udaan and udaanCapital</figcaption></figure><p>Finding the right root cause is important. An 85% storage reduction sounds good, but barely moved the needle.</p><h3>What We Learned</h3><p>A few lessons from this whole experience:</p><p><strong>Always dig into actual cost breakdowns first: </strong>The storage cleanup was actually just a one-day effort, but the real lesson is to understand what’s driving your costs before jumping into optimizations. Cloud billing isn’t always intuitive.</p><p><strong>Simple fix can have huge impact: </strong>We didn’t migrate to Expo or move to a more expensive managed service. One URL change and CDN configuration solved most of the recurring spend problem.</p><p><strong>Self-hosting can actually be cheaper: </strong>With smart optimizations, we’re running our deployment infrastructure for less than most SaaS alternatives cost. And since we control the infrastructure, we can host multiple apps and scale to more users without being boxed into a service provider’s pricing tiers.</p><h4>The Road Ahead</h4><p>There are still a couple of areas where we can reduce the cost further.</p><p>One promising direction is <strong>diff-based OTA updates</strong>. Today, CodePush updates serve the complete JavaScript bundle to the client. Instead, we can generate a patch between the previously installed bundle and the new bundle, and send only that patch to the device. We had already tried an experiment in this direction, where the update size reduced from around <strong>7 MB to 100 KB</strong>, which is roughly a <strong>98% reduction</strong>.</p><p>However, making this production-ready would require more than just generating binary diffs. We would need infra changes to store and serve patches based on base and target bundle versions, and client SDK changes to safely apply patches, validate them, and fall back to the full bundle when required.</p><p>Another area to explore is the <strong>CodePush Server</strong> itself. A meaningful part of the remaining cost now comes from running the Express server. Since this service mostly handles polling requests and returns update metadata, we can evaluate lighter alternatives such as workers or other serverless runtimes to reduce infra overhead further.</p><h4>Closing Thoughts</h4><p>App Center had made OTA updates effectively free for us. But once the hosted service was shutting down, we had to own that release path ourselves. Self-hosting the open-source CodePush server gave us continuity, but it also exposed the real infrastructure cost behind OTA delivery.</p><p>The initial version worked, but it was expensive. The meaningful improvement came only after we diagnosed the right bottleneck: storage was not the problem; repeated bundle downloads and network egress were. What had previously felt free through App Center now had visible infrastructure costs in our own environment, and adding a CDN made the self-hosted setup economically sustainable.</p><p>It was a reminder that pragmatic engineering is often about choosing continuity first, understanding the system deeply, and then optimizing the part that actually matters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45e3de5f9df4" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/how-we-pivoted-from-app-center-and-reduce-ota-costs-by-90-45e3de5f9df4">How we pivoted from App Center and reduce OTA costs by 90%</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How udaan cut SQL database costs by 50% without sacrificing performance]]></title>
            <link>https://udaan.dev/how-udaan-cut-sql-database-costs-by-50-without-sacrificing-performance-50781d25306c?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/50781d25306c</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[scaling]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[udaan]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Rajesh Kumar]]></dc:creator>
            <pubDate>Thu, 30 Apr 2026 07:37:35 GMT</pubDate>
            <atom:updated>2026-04-30T07:37:34.062Z</atom:updated>
            <content:encoded><![CDATA[<h3>Overview</h3><p>At udaan, India’s largest B2B e-commerce platform, SQL databases power everything critical: <em>payments, shipments, fulfillment, warehouse management </em>and core business operations.</p><p>What made this harder than a generic SaaS setup was shape of our eB2B workload: <em>seasonal procurement spikes, multi-tenant retailer and supplier data growth, and credit-driven transaction flows</em>. We were also not tuning one kind of system. Our fleet included latency-sensitive transactional paths, analytical and reporting-heavy stores, and batch-oriented workloads with very different performance and cost profiles.</p><p>As we scaled so did our database bill and like most fast-moving engineering teams, our provisioning decisions were conservative:</p><ul><li>we picked “safe” SQL server tiers.</li><li>we over-allocated vCores.</li><li>we enabled replicas as it appeared to be responsible thing to do.</li><li>we carried performance headroom we didn’t actually need.</li></ul><p>Eventually <strong><em>while auditing our database fleet we realized the uncomfortable truth</em>:</strong> We were paying premium prices for capacity and replicas we weren’t using. After audits, modeling and staged migrations, we clawed back waste and turned it into a structured optimization:</p><ul><li>Reduced database spend by ~50%</li><li>Improved operational agility</li><li>Removed several scaling bottlenecks</li><li>Increased resilience in real incidents</li></ul><p>This post breaks down what we learned and a tier-selection framework you can reuse.</p><h3>The Problem: Over-Provisioning is the Default</h3><p>Database provisioning decisions are rarely revisited. Once a database is created in a premium tier with a replica setup, it tends to stay there indefinitely, even if:</p><ul><li>workload characteristics change</li><li>storage grows unexpectedly</li><li>replicas are never actually used</li><li>scaling becomes painful</li></ul><p>In our case, we discovered multiple patterns:</p><ul><li>Several<strong><em> Business Critical databases</em></strong> were paying for <em>premium SSD performance</em>, yet were still approaching <em>4 TB storage</em> ceiling, creating a scaling and cost risk.</li><li>Multiple <strong><em>General Purpose databases</em></strong> were <em>running replicas</em> that were never actually used for read-only traffic or recovery, effectively doubling cost.</li><li>In both <strong><em>General Purpose </em></strong><em>and</em><strong><em> Business Critical</em></strong>, storage growth often forced us to scale up vCores, even when CPU wasn’t bottleneck, leading to structural over-provisioning.</li><li>Many databases were simply oversized: vCores allocated far above real CPU and I/O demand, with utilization staying low for long periods.</li></ul><h3>A Simple Mental Model of Database Tiers</h3><p>Before we got to decisions, we aligned on what these three tiers really mean operationally.</p><h4>General Purpose (GP): cheapest, but remote storage</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UX5VrQLOm-WB4UQKaHGcVQ.png" /></figure><p>General Purpose decouples compute and storage: the database engine runs on compute nodes while the data lives on remote storage. This gives good flexibility, but it introduces storage I/O latency (typically ~5–10 ms).</p><p><strong>Key characteristics</strong></p><ul><li><strong>Compute:</strong> 2 to 128 vCores</li><li><strong>Storage:</strong> 1 GB to 4 TB (paid on allocated size)</li><li><strong>Replicas:</strong> no built-in read replica</li><li><strong>IOPS:</strong> ~320 IOPS/vCore (max 16,000 IOPS)</li><li><strong>HA:</strong> backup replica (not a read replica)</li></ul><blockquote><strong><em>The big gotcha: </em></strong>If you add a replica for availability, you’re effectively paying for two databases, yet still not getting Business Critical performance.</blockquote><h4>Business Critical (BC): fastest I/O, but scaling is painful</h4><p>Business Critical uses local SSDs: compute and storage run on the same machine. I/O latency is typically ~1–2 ms due to tightly coupled &amp; SSD architecture. It also includes a free read replica via an Always On availability group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GuqkSAwGjfPrXfPUxU9rTQ.png" /></figure><p><strong>Key characteristics</strong></p><ul><li><strong>Compute:</strong> 2 to 128 vCores</li><li><strong>Storage:</strong> 1 GB to 4 TB (paid on max assigned)</li><li><strong>IOPS: </strong>~4,000 IOPS/vCore (max 327,680 IOPS)</li><li><strong>Replicas: </strong>1 read replica included</li><li><strong>HA:</strong> multiple replicas managed by the platform</li><li><strong>Scaling:</strong> mostly vertical</li></ul><blockquote><strong>The biggest limitation:</strong></blockquote><blockquote>Scaling (especially storage) can be operationally heavy. If you need to move to a larger configuration, you may need hours-long migration windows.</blockquote><blockquote><em>4 TB</em> cap becomes a real bottleneck at scale.</blockquote><blockquote>General Purpose and Business Critical <em>force a fixed vCore-to-storage ratio</em> — as storage grows, compute must grow even when CPU demand stays flat, which leads to structural over-provisioning.</blockquote><h4>Hyperscale (HS): the tier that changed everything for us</h4><p>Hyperscale decouples compute and storage like General Purpose, but <em>adds a multi-tier caching architecture with local SSD caches on compute nodes</em>. This gives:</p><ul><li>General Purpose-like elasticity (compute and storage scale independently)</li><li>Business Critical-like performance for hot data (2-level SSD cache)</li><li>Drastically higher storage limits</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FOnei2detjaflrx3K_7BQ.png" /></figure><p><strong>Key characteristics</strong></p><ul><li><strong>Compute: </strong>2 to 128 vCores</li><li><strong>Storage: </strong>10 GB to 100 TB (pay for what you use)</li><li><strong>Replicas: </strong>configurable high-availability replicas</li><li><strong>Scaling: </strong>fast scale up/down (minutes, not hours)</li><li>Supports multiple read scale-out replicas (named replicas)</li><li>Unlike GP and BC, it can run the 100 TB with 2 vCores.</li></ul><blockquote><em>In practice, Hyperscale removed </em><strong><em>three biggest pain points</em></strong><em> we had with Business Critical:</em> 4 TB ceiling, slow scaling during incidents and compute and storage being tied.</blockquote><h3>Our Tier-selection Decision Framework</h3><p>After auditing our database fleet, we arrived at a simple framework that held up across most workloads.</p><h4>When General Purpose makes sense</h4><p>General Purpose is the right choice when:</p><ul><li>workload is non-critical</li><li>workload is mostly batch, back-office, or low-QPS internal traffic</li><li>you don’t need read replicas</li><li>you can tolerate 5–10 ms storage latency</li><li>cost is dominant constraint</li><li>your data size is small</li></ul><p><strong>Rule of thumb: </strong>If you need a replica, General Purpose stops being “cheap”. The moment you add replicas to GP, you’re often paying 2× for performance that still isn’t great.</p><h4>When Business Critical makes sense</h4><p>Business Critical is the right choice when:</p><ul><li>you have strict low-latency requirements (<em>1–2 ms</em>)</li><li>workload is primarily transactional and user-facing</li><li>you need a built-in read replica</li><li>your database is safely under the<em> 4 TB cap</em></li><li>you want the simplest high-performance operational model</li></ul><p><strong>Note: </strong>It’s great until you hit scaling constraints.</p><h4>When to skip Business Critical and go straight to Hyperscale</h4><p>This was our biggest insight. We initially assumed Business Critical was “correct” tier for production workloads that required performance and availability. In 80%+ of production workloads we evaluated, Hyperscale provided equal or better latency while materially reducing cost.</p><p><strong>Hyperscale gives:</strong></p><ul><li>Business Critical-like latency for hot data (two tier SSD-cache)</li><li>Far better scaling characteristics</li><li>Dramatically higher storage headroom up to 100 TB</li><li>Fast vertical scaling during incidents - <em>scale up takes maximum 5 minutes</em></li><li>Flexible HA replica configuration</li></ul><p>It worked especially well for mixed workloads where transactional traffic, reporting reads, and growth in multi-tenant datasets were all pulling in different directions.</p><p><strong>And most importantly:</strong> it was consistently cheaper for us.</p><h3>The Replica Trap (and why it was costing us lakhs)</h3><p>We discovered several <em>General Purpose</em> production databases running with replicas. This doubled our billing because a replica is essentially a second, independently billed database. The painful part was that even after paying 2X, we still had General Purpose limitations:</p><ul><li>remote storage latency (higher I/O time)</li><li>no built-in read scale-out</li><li>higher vCore requirements to compensate for I/O bottlenecks</li></ul><p>As these databases grew, we often ended up scaling vCores just to stay stable, which made the “cheap” tier surprisingly expensive.</p><h3>The Migration Playbook That Worked for Us</h3><p>This is part that determines whether you actually save money: how we executed cost reduction without breaking production.</p><h4>Step 1: Audit everything</h4><p>We collected for every database: tier (GP / BC / HS), replica configuration, vCore utilization trends, storage usage and growth rate, I/O and latency patterns, read vs write mix, scaling history (how often we had to scale during incidents).</p><p><strong>Immediate candidates are:</strong></p><ul><li>Business Critical databases approaching the 4 TB limit, or cases where we were forced to scale up vCores purely to unlock more storage (even when CPU wasn’t bottleneck).</li><li>General Purpose databases running replicas, effectively doubling cost without delivering proportional performance or availability benefits.</li><li>Any database with consistently low CPU utilization but high monthly spend, indicating clear over-provisioning.</li></ul><h4>Step 2: Migrate to Hyperscale</h4><p>Online migration to Hyperscale is possible with minimal downtime. The migration itself is fairly documented and the real win comes from what you do after migration.</p><p><strong>One migration did not go as smoothly as planned:</strong> we treated it like a straight tier switch, but the workload had a heavier reporting pattern than we had modeled. We saw temporary latency regression until caches warmed and had to slow down the cutover, re-check the read pattern, and right-size more carefully after the move. That experience is what pushed us to treat workload shape, not just database size, as a first-class input.</p><h4>Step 3: Right-size after migration (where most savings come from)</h4><p>This is the step most teams miss. Hyperscale’s architecture often delivers significantly higher performance for the same workload due to distributed storage, multi-level caching, and higher log throughput.</p><p>That means the same workload can often run on fewer vCores. Our workflow was: migrate, monitor for a tuning period, validate <strong><em>p95/p99</em></strong> latency, CPU, IO stalls, query time, and reduce vCores gradually until we hit a stable efficient point. This is where the majority of our savings came from.</p><h4>Step 4: Use fast scaling during incidents</h4><p>One operational advantage we underestimated: Hyperscale scaling speed is a game-changer in system degradations or outages. With Business Critical, scaling could take hours in certain scenarios.</p><p><strong>With Hyperscale:</strong></p><ul><li>scaling up vCores is fast</li><li>scaling down is fast</li><li>you pay only for the burst window</li></ul><p>During unexpected load spikes, this turned scaling from a stressful multi-hour operation into a reversible configuration change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28ebeL-DTxgiYuSX8wjYjQ.png" /></figure><h3>Results</h3><p>The impact was immediate and measurable.</p><ul><li><strong>Business Critical → Hyperscale: </strong>These migrations accounted for roughly <em>30% savings of 50% monthly cost-down while simultaneously removing the 4 TB storage ceiling</em> and <em>dramatically improving our ability to scale during incidents</em>.</li><li><strong>General Purpose + replica → tuned Hyperscale:</strong> These contributed <em>another ~20% savings of 50% monthly cost-down</em> while simplifying our <em>replica strategy and actually improving read performance</em>.</li><li>Post-migration vCore right-sizing Real optimization isn’t just picking the right tier, but tuning within it (and it remained the biggest lever per database once migrations completed).</li></ul><p><strong>In total:</strong> ~50% savings, with better performance, better scalability, and simpler operations.</p><h3>A Decision Cheat Sheet</h3><p>If you’re evaluating database tiers today, here’s the simplified framework we now use internally:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WVq1sztnMexQh21QDUlj3Q.png" /></figure><h3>What’s Next</h3><p>The cost program is still evolving, and we see three areas worth exploring next:</p><ul><li>Automate the fleet audit by wiring telemetry feeds (CPU, IO, replica lag, storage growth) into a weekly report so rightsizing candidates are surfaced continuously instead of ad hoc.</li><li>Explore elastic-pool style approaches for smaller multi-tenant workloads where isolated provisioning is inefficient.</li><li>Connect operational databases more deliberately to analytics and data lake layers so reporting and batch demand do not distort transactional sizing decisions.</li><li>Add cost-governance guardrails and alerts directly into the provisioning workflow so fast scaling does not quietly become recurring over-provisioning.</li></ul><h3>Key Takeaways</h3><p>The most expensive database is one you haven’t audited recently. Over-provisioning compounds quietly — unused replicas, oversized tiers, vCores allocated “just in case” — and the bill grows without anyone noticing because no single decision looks unreasonable in isolation.</p><p><strong>Here’s what we learned the hard way:</strong></p><ul><li>Hyperscale has matured enough to be default for most production workloads in our fleet. Its combination of performance, scalability, and cost efficiency made it the right choice for <strong><em>80%+ of our databases</em></strong>.</li><li><em>Replicas on General Purpose are a cost trap</em>. The moment a GP database needs replicas, you should seriously evaluate whether Hyperscale is a better fit. It almost always is.</li><li>Real savings happen after migration. Migrating to the right tier is necessary but not sufficient. The majority of our cost reduction came from post-migration vCore right-sizing by methodically stepping down compute until we found the efficient operating point for each workload.</li></ul><blockquote>Treat tier selection as an ongoing economic decision, not a one-time architectural choice. Workloads evolve. Storage grows. Traffic patterns shift. The tier that was right 18 months ago may be costing you lakhs today. If your organization runs SQL databases at meaningful scale, a tier + replica audit is likely one of the highest-ROI infrastructure optimizations you can do this quarter.</blockquote><p>Authored by Engineering team at udaan. If building and scaling complex backend systems interests you, this is the kind of work we do every day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50781d25306c" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/how-udaan-cut-sql-database-costs-by-50-without-sacrificing-performance-50781d25306c">How udaan cut SQL database costs by 50% without sacrificing performance</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we solved a 2s+ stutter caused by re-rendering React components]]></title>
            <link>https://udaan.dev/how-we-solved-a-2s-stutter-caused-by-re-rendering-react-components-5b852ca1852a?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/5b852ca1852a</guid>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-compiler]]></category>
            <dc:creator><![CDATA[Divjot Singh]]></dc:creator>
            <pubDate>Wed, 30 Jul 2025 08:45:07 GMT</pubDate>
            <atom:updated>2025-07-30T08:45:07.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ehp9JyhlnsE3MVB-D66rIQ.png" /></figure><h3>TL;DR</h3><ul><li>Add to Cart interaction in our React Native app developed a <strong>2-second UI lag </strong>due to accumulating tech-debt and improper usage of context and redux.</li><li><a href="https://react-scan.com/">react-scan</a> while really amazing, was too good for our app&#39;s chaotic re-render patterns; using <strong>React DevTools&#39; &quot;Highlight Updates&quot; with video recording</strong> helped in pinpointing the issue better.</li><li>Careful refactor of context usage into multiple granular custom hooks in one file and then replacing those with <strong>useSelector hooks and </strong><strong>batching</strong> helped us reduce frequency of re-renders 14 times over.</li><li><strong>React Compiler </strong>further reduced the problem horizontally by reducing the breadth of components that re-rendered.</li></ul><p><strong>Disclaimer: </strong>This post is touched up using LLM tools.</p><p>Before we begin, let’s first understand the problem we are trying to solve. We started receiving user reports about how our add to cart button felt slow and unresponsive. Originally the cart APIs were quite latent, so the original diagnosis was written off as a “backend issue” and we added a loading bar to give immediate feedback to the user. However, as the latency was reduced, another problem surfaced. Notice how the loading bar stutters and gets stuck and the footer doesn’t update for good 2 seconds? Yeah, this post is about solving that with minimal code changes.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fshorts%2FAI7-GsQF2b8&amp;type=text%2Fhtml&amp;schema=youtube&amp;display_name=YouTube&amp;src=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2FAI7-GsQF2b8%3Ffeature%3Doembed" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/14489f5ff43cd3169e098177bc94d322/href">https://medium.com/media/14489f5ff43cd3169e098177bc94d322/href</a></iframe><h3>Making Our React Native App Faster</h3><p>Ever notice your app slow down, even for a moment? That little pause is a gateway to your users bouncing off of your app. This is especially bad when your user is trying to actually transact, like adding items to their cart or completing a purchase. These delays, often caused by too many screen updates and heavy calculations, make users frustrated, reduce how much they use the app, and can even make them think less of your product. In this post we go over how we made key interactions <strong>2850ms faster</strong> by controlling re-renders of our React application.</p><h3>How did we get here: Compounding works both ways</h3><p>Small design choices and incremental feature additions can quietly compound into significant performance problems over time.</p><p>At first, we used <strong>Redux</strong> for managing our app’s data. To simplify interactions, an abstraction layer was introduced using React’s <strong>Context API</strong>. This was not a logical, well-thought-out architectural choice; rather, it was a decision made in haste, driven by the immediate pursuit of shipping features quickly.</p><p>However, this decision began to obscure the underlying complexity. The problem was, for every re-render caused by redux store update, context was adding another re-render to update its own value.</p><p><strong>Over two years</strong>, as new features were added and existing logic grew, it became increasingly straightforward to add more state-related logic directly within this Context-wrapped Redux setup. The result? Instead of a single, atomic update to our Redux store, a seemingly simple action like “Add to Cart” could trigger <strong>14 back-to-back store updates and re-renders</strong>. Each dispatch, though individually small, contributed to a cascade of UI updates, monopolizing the main thread and leading to noticeable stutters. This illustrates a critical lesson: taking the easy route now can lead to major headaches later.</p><p>This insidious degradation is a bit like the “boiling frog” story. Maybe an interaction first had a tiny <strong>100ms lag</strong>. Then it slowly grew to <strong>250ms</strong>, then <strong>800ms</strong>. Developers might have felt something was a bit off, but with constant deadlines for new features, it was hard to argue for time to fix a small 100–200ms problem.</p><h4>Measure twice, cut once</h4><p>Finding exactly what was causing these problems and how big they were was crucial. We first tried using <a href="https://react-scan.com/">react-scan</a> for performance insights. While react-scan is a very powerful and robust tool, the sheer volume and chaotic nature of re-renders occurring across our application meant its detailed output, though accurate, was too overwhelming to quickly pinpoint specific culprits in <em>our</em> particular scenario (oof!).</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3DoWcN4Jcrlmw&amp;type=text%2Fhtml&amp;schema=youtube&amp;display_name=YouTube&amp;src=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2FoWcN4Jcrlmw" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3474d2524bab5073e811184747aa4800/href">https://medium.com/media/3474d2524bab5073e811184747aa4800/href</a></iframe><p>Our breakthrough came from a more direct, visual approach. We used <strong>React DevTools’ “Highlight Updates”</strong> feature. This tool visually showed us what was updating on screen. We combined this with recording a video of the “Add to Cart” task on a test phone. By looking at the exact moment right after the action, we clearly saw which parts of the screen were redrawing and, most importantly, <em>how many times</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*vpWA54Re8_4ZkjaKvAth6Q.png" /><figcaption>Screenshot of the app showing every element with a bright golden label “View x14” “Path x13” etc. where the first part is the name of the component and the x14 is the number of times that component re-rendered.</figcaption></figure><p>We could also see in the Chrome Performance Dev Tools an undeniable visual proof of <strong>2246ms</strong> delay on moderately slow phones during critical user flows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JaLs9SdaOCYIYsm54DfI4A.png" /><figcaption>Chrome Performance Dev Tools showing a massive 2.2s stutter, all that time spent in scripting.</figcaption></figure><p>This gave us the clear reason we needed to dedicate time to fix it. That annoying, jagged mountain in our performance graph, showing 14 back-to-back updates, told the whole story.</p><p>Crucially, having this reliable measurement technique not only exposed the problem but also gave us a precise target for our code changes. We’ll see how this simple janky measurement ended up being a great metric.</p><h3>How we fixed it with minimal changes</h3><p>It’s easy to give in to the desire to grab shiny tools when posed with such issues. Maybe we should migrate to <a href="https://github.com/pmndrs/zustand">zustand</a>? Maybe we should upgrade to react 19 and use <a href="https://react.dev/reference/react/use">use</a>? Maybe we should enable React Compiler everywhere? Maybe we should rewrite entire state logic in <a href="https://redux-toolkit.js.org/">redux toolkit</a>? But when dealing with production code, it’s often in your best interest to find minimal fixes for your problems to reduce the maintenance and QA load, and actually ship the fixes in realistic timelines.</p><p>Our plan involved three key steps:</p><h4>1. Cleaner Code and Switching to Redux: Setting Up for Speed</h4><p>For <em>context</em>, whenever the value in a <a href="https://react.dev/learn/passing-data-deeply-with-context">React Context</a> changes, all the <a href="https://react.dev/reference/react/createContext#consumer">Context.Consumers</a> and components surrounding <a href="https://react.dev/reference/react/useContext">useContext</a> re-render, regardless of which part of that value updated. You may find this <a href="https://www.developerway.com/posts/react-re-renders-guide">excellent post by Nadia</a> to be quite valuable in understanding the nuances of React re-renders. If you really have to use context, consider splitting each key of object into its own individual Context.</p><p>In our case, not only we had a huge object in context, we also were then saving it to redux. This meant, that we were paying 2x the price of state updates due to the unnecessary context layer in between. We didn’t really need to “fix” context usage, we could just remove it, as we already had redux in place.</p><p>To make our lives easy, our first step to solving the problem was a big code cleanup. We started by finding all the places where useContext() was used directly and made sure they all went through specific, smaller custom hooks. For example, lines like</p><pre>const {<br>  cartItems,<br>  activeCategoryId,<br>  cartCoupons,<br>  // and so on...<br>} = useContext(CartContext);</pre><p>became</p><pre>const cartItems = useCartItems();<br>const activeCategoryId = useCartActiveCategoryId();<br>const cartCoupons = useCartCoupons();</pre><p>This careful work limited <strong>all direct </strong><strong>useContext calls to just one single, dedicated file</strong>. It’s a nice refactoring technique that helps you isolate your problem to one file. This didn&#39;t change how our data was managed right away, but it created a clear, traceable path for data flow and paved the way for more impactful optimizations. Putting the problem code into one file was a major reason we could fix it so fast.</p><p>After this cleanup, the next logical step was to replace the useContext calls with <strong>Redux&#39;s </strong><strong>useSelector hook</strong>.</p><pre>function useCartItems() {<br>  const cartItems = useContext(CartContext).cart.cartItems;<br>  return cartItems;<br>}<br><br>function useCartActiveCategoryId() {<br>  const activeCategoryId = useContext(CartContext).activeCategoryId;<br>  return activeCategoryId;<br>}<br><br>function useCartCoupons() {<br>  const cartCoupons = useContext(CartContext).cartCoupons;<br>  return cartCoupons;<br>}<br><br>// became<br><br>function useCartItems() {<br>  const cartItems = useSelector(store =&gt; store.cart.cartItems);<br>  return cartItems;<br>}<br><br>function useCartActiveCategoryId() {<br>  const activeCategoryId = useSelector(store =&gt; store.cart.activeCategoryId);<br>  return activeCategoryId;<br>}<br><br>function useCartCoupons() {<br>  const cartCoupons = useSelector(store =&gt; store.cart.cartCoupons);<br>  return cartCoupons;<br>}</pre><p>Switching from context to redux alone reduced the re-renders two-fold, and the granular hooks now only asked for the specific bits of Redux data they needed, and had no React Context to worry about. This stopped unnecessary redraws when other parts of the data changed.</p><blockquote>One could argue that it would be nice if React team to <a href="https://github.com/facebook/react/pull/20646">add selectors</a> to the context API itself, but it looks like they’re taking a <a href="https://x.com/acdlite/status/1741188563926962190">different approach</a> by letting you use use(context) inside of an useMemo , which also means it could get optimized by React compiler in the future.</blockquote><blockquote>As of July 2025, use(context) has shipped in React 19 but not the part where you can use it within useMemo and get it to recompute automatically. I think the idea has merit as it bypasses the code-smell of selectors and lets compilers take care of it. Alternatively, selectors too could be written by compilers, so there’s that.</blockquote><p><strong>Key takeaway:</strong> By limiting Context use and switching to specific useSelector hooks, we halved the re-renders caused due to improper usage of React context.</p><h4>2. Using Redux Batching: Combining Updates</h4><p>With the Redux selectors properly in place, we quickly found situations where several related actions were being sent out very fast upon add to cart action. Like before, the problem grew over time.</p><pre>// day 1<br>function onAddToCart () {<br>  dispatch(someAction());<br>}<br><br>// 2 years later<br>function onAddToCart () {<br>  dispatch(defaultValues());<br>  // someRandomCommentedCodeCozWhyNot();<br>  dispatch(resetSomeOtherValues());<br>  someTelemetryCode();<br>  dispatch(someAction());<br>  if (someCondition) {<br>    dispatch(someOtherAction());<br>    if (userConditon) { <br>      someOtherTelemetryCode();<br>      dispatch(newUserConditionAction());<br>    }<br>  }<br>  someFunctionThatCallsDispatchInternally();<br>  dispatch(newFeatureAction());<br>}</pre><p>Ideally all your business logic should be written in your reducer, or even better, in a separate service file, but in practice this falls apart if not properly enforced, especially with changing business requirements that prevent you from creating perfect abstractions. Luckily, we can solve this without rewriting any business logic.</p><p>While modern React (version 18 and newer) and recent react-redux updates automatically batch state updates, our older <strong>React Native</strong> version in the app meant we couldn&#39;t just wait for a big platform update to benefit. The urgency of fixing this massive stutter without an equally massive QA pass prompted us to specifically use <strong>Redux Batching</strong> with the <a href="https://react-redux.org/api/batch">batch</a> function from react-redux. Simply wrapping onAddToCart in batch was enough to substantially bring down the re-renders.</p><p>This resulted in a <strong>6x reduction in screen redraws</strong> compared to just using Redux before, and an amazing <strong>14x reduction</strong> from our original, unoptimized state. Our performance graph, which once showed a long, bumpy line from 14 fast updates and redraws, now had one short, sharp peak for a single, larger redraw. We literally watched the bottleneck shrink.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiGXJY-FkWrlxCtnoaIJqw.png" /><figcaption>Before vs After of Chrome Dev Tools. We can see a much smaller mountain of “Scripting” time in the graph, with the time reduced from 2246ms to 321ms. There’s still scope for improvement but this is a dramatic W.</figcaption></figure><p><strong>Key takeaway:</strong> Explicit Redux batching was a crucial manual intervention for our React Native application. It let us deliver immediate, critical performance improvements via OTA updates, greatly improving user interaction responsiveness.</p><h4>3. Getting Ready for React Compiler: Automatic Optimizations</h4><p>So far we’ve been tackling the frequency of updates, but there’s another issue that’s quite apparent in the screenshot of re-renders. Components that shouldn’t re-render, were re-rendering. Think of all the Svg Icons, the titles. Traditionally this is fixed by manually polluting your codebase with <a href="https://react.dev/reference/react/useMemo">useMemo</a>, <a href="https://react.dev/reference/react/useCallback">useCallback</a> and <a href="https://react.dev/reference/react/memo">memo</a>. Any sane person can tell you that this is a crazy whack-a-mole game. Enter <a href="https://react.dev/learn/react-compiler"><strong>React Compiler</strong></a>. This babel plugin (it’s being ported to <a href="https://react.dev/blog/2025/04/21/react-compiler-rc#swc-support-experimental">swc</a> soon) automatically detects dependency of variables within your React components and “memoizes” them. You can play with it <a href="https://playground.react.dev/">here</a>. In fact, that’s what we did first to identify potential gains before setting up react-compiler for our project.</p><p>It’s important to know that while it stops <em>unnecessary</em> screen redraws by smartly optimizing components, it doesn’t remove the <em>fundamental reasons</em> for redraws (like when data or properties legitimately change). In our specific case, our original code was intentionally triggering 7 separate redux dispatches, and then doubling that with setting it in context, effectively <em>compounding</em> the redraw problem. I doubt the compiler can fix that big error of judgement, but it can surely reduce the blows of that suboptimal architectural decision.</p><p>By adding the React Compiler to our Bolt Design System (our internal library of components), we unlocked the potential for automatic speedups. For some of our Bolt components, this has already led to <strong>zero redraws</strong> in certain update situations, greatly reducing their contribution to the overall work the app has to do. We were careful, though. Adding a tool that changes how our app runs at the compilation stage can be risky in a large, existing codebase. To lower this risk, we decided to enable the React Compiler <strong>only within our separate, isolated Bolt component library</strong>. This allowed us to thoroughly test its effects on a small set of frequently used components, building confidence before thinking about using it more widely. This also paves the way for devs to simply drop reusable components in the library without explicitly adding useMemo or useCallback . To be honest, it isn’t even practical to ensure referential stability when you’re dealing with 10+ props for some components. This is where React Compiler shines, and <a href="https://dev.to/ryansolid/a-hands-on-introduction-to-fine-grained-reactivity-3ndf">fine-grain reactivity frameworks</a> outshine React.</p><p><strong>Key takeaway:</strong> The React Compiler offers powerful, automatic optimizations to stop unnecessary redraws, however it can’t solve logic that deliberately causes re-renders. Now that we’ve fixed the fundamental issue, future gains will come from effective usage of the React compiler.</p><h3>The Result: A More Responsive User Experience</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ehp9JyhlnsE3MVB-D66rIQ.png" /><figcaption>Four screenshots of the search page with “highlighted updates” enabled in react dev tools. First image says “On Project Start” and shows almost every element in the screen re-rendering 13–14 times with a bright yellow color, implying costly re-renders. Second image says “Context -&gt; Redux, 14 -&gt; 6 re-renders” and has reduced frequency of re-renders (from 14 to 7) with a darker shade of yellow, implying less costly re-render. Third image says “react-compiler for bolt-components, 0 re-renders for some components”, and with this some icons, images and text fields have disappeared from re-render labels and the color is still darker shade of yellow. Fourth image says “redux batching 6 -&gt; 1 re-renders”, here everything has is re-rendering only once and the color has changed to teal color, implying cheap re-renders. There is still scope for improvement as many elements are still re-rendering, but it’s a long way from “Project start”.</figcaption></figure><p>Let’s see the difference in action now.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2F6oo2svMIfYc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fshorts%2F6oo2svMIfYc%3Ffeature%3Dshare&amp;image=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fi.ytimg.com%2Fvi%2F6oo2svMIfYc%2Fhq2.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d5a59553666e5ecf97878c6bd103a26/href">https://medium.com/media/9d5a59553666e5ecf97878c6bd103a26/href</a></iframe><p>All these optimizations together have greatly improved how fast and smooth our app feels. While our app isn’t universally lightning-fast, eliminating a debilitating 2-second stutter in add to cart action was extremely gratifying.</p><h3>What’s Next: Always Making Things Better</h3><p>Even though we’ve made big progress in making our frontend faster, our work isn’t over. We’ve found more areas to improve:</p><ul><li><strong>Optimizing other components:</strong> Right now, our listing widget depends on the entire list of cart items due to some edge case. Similarly the footer depends on cart value and progress of coupon ladders). By breaking or isolating this dependency, we will further reduce redraws when cart items change. We defintely can get to the point where only Add to Cart button and the footer re-render. But we are looking at diminishing returns for the amount of code changes required. The next point is probably a better investment;</li><li><strong>More React Compiler Use:</strong> As we learn more and gain confidence with how the React Compiler works in our Bolt components, we will look for chances to use it in other important parts of our code, aiming to get the most out of its automatic optimization features.</li></ul><p>Improving performance is an ongoing process, and it also keeps getting worse as more code is checked in. It’s important to audit your app from time to time to find gaps, and for every highly dynamic state, it’s better to take the time to make right choices early.</p><p>What are your experiences with performance problems that grew from small changes? Share your thoughts below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b852ca1852a" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/how-we-solved-a-2s-stutter-caused-by-re-rendering-react-components-5b852ca1852a">How we solved a 2s+ stutter caused by re-rendering React components</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Taming the Ebb and Flow: Cost Efficient Time Based Autoscaling]]></title>
            <link>https://udaan.dev/taming-the-ebb-and-flow-cost-efficient-time-based-autoscaling-efe696c68f9d?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/efe696c68f9d</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-cost-optimization]]></category>
            <dc:creator><![CDATA[Aditya Bennur]]></dc:creator>
            <pubDate>Thu, 01 Aug 2024 14:26:50 GMT</pubDate>
            <atom:updated>2024-08-01T14:26:50.274Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Challenge: Predictable Peaks and Unpredictable Costs</h3><p>At Udaan, we operate a complex microservices architecture with over 200+ Kubernetes deployments. Analysis of our application traffic patterns reveals distinct “ebbs” and “flows”.</p><p>During business hours, our servers are bustling city squares, by night, they’re quiet ghost towns. This cyclical nature of our workloads presented us with an opportunity to optimize our compute resource utilization and reduce operational costs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vppuNH4dWcJGDcPAEfgzdA.png" /><figcaption>y=rps; x=time</figcaption></figure><h3>Primer: Autoscaling</h3><p>Kubernetes autoscaling capabilities play a pivotal role in its widespread adoption across enterprises. Among the various autoscaling methods available for microservices, such as Vertical Pod Autoscaling (VPA), Horizontal Pod Autoscaling (HPA), and Event-Driven Autoscaling, HPA stands out as the most commonly adopted solution.</p><p>HPA dynamically adjusts the number of replicas for a Deployment or ReplicaSet based on metrics like CPU and memory utilization, or custom metrics. This reactive scaling responds to incoming traffic patterns without relying on predefined time-based components.</p><p>In contrast, time-based scaling is a modern approach that allows applications to scale based on user-defined schedules. This method proves advantageous for scenarios with predictable traffic patterns.</p><p>While HPA excels in handling dynamic and unpredictable traffic, it may not be the ideal choice for environments where traffic patterns are well-understood and predictable. Time-based autoscaling empowers organizations to efficiently scale resources up or down ahead of expected demand.</p><h3>Approach: Time Driven Scaling</h3><p>Post evaluation and comparison of available autoscaling solutions that aligned with our requirements and limitations, we opted to implement time-based autoscaling. Enter “Service Scaler”, a home-grown Kubernetes operator which pro-actively monitors and controls the <em>HPA</em> object of a corresponding <em>deployment</em> and facilitates gradual scaling of workloads in accordance with a specified configuration.</p><h4>The Configuration (CRD)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2QcCIMCTPyITxTSe777-g.png" /><figcaption>CRD definition</figcaption></figure><p>Time can be specified in the following formats:</p><ul><li><strong>ZonedTime </strong>— HH:MM&lt;tz-offset&gt;</li><li><strong>ZonedDateTime</strong> — <a href="https://datatracker.ietf.org/doc/html/rfc3339">rfc3339</a> format Ex: 2023-01-11T08:00:00+05:30</li></ul><p>If <em>no</em> time range matches the <em>default</em> configuration will be applied.</p><h4>Operator “Mechanics”</h4><p>Let’s explore the inner workings of the Service Scaler through visual representations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rqr1zO08Qb9PvAC4wWyX5Q.png" /><figcaption>state machine</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YznATfBDAqmNxfsaa7FDYQ.png" /><figcaption>architecture</figcaption></figure><h4>Operational Overview</h4><ul><li>The Controller monitors and reacts to three types of events within the ServiceScaler <em>CRD</em>:<br>1. <em>Create</em><br>2. <em>Update</em><br>3. <em>Delete</em></li><li>Reconciliation:<br>1. Verifies if the “time-range” matches.<br>2. Assesses “early-exit” conditions.<br>3. Execute HPA operations accordingly.</li><li>Given the dependency on the <em>“time”</em> dimension, reconciliation is forced every 5 minutes to maintain the desired state of the HPA consistently, even when Create/Update/Delete events are not triggered.</li><li>Invalid HPAs (HPAs having <em>minReplicas == maxReplicas</em>) are automatically removed conserving configuration sanity.</li></ul><h4>Ramp up-down “mechanics”</h4><p>Scaling activities commence <strong>30 minutes in advance</strong> of both anticipated traffic increases and decreases, ensuring systems are primed and ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUAg272cXLGwr7lbp6uIwg.png" /><figcaption>ramp-up down module</figcaption></figure><p>Enough talk! Let’s take a look at a scenario where it would begin scaling down from 14 to 2 replicas prior to midnight (00:00), ensuring the 2 replicas are fully provisioned and ready to handle the expected lower traffic load at the start of the day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2n8AHJjM6NgwXbEVpOIiQ.png" /><figcaption>y=replicas; x=time</figcaption></figure><h4>Kill Switch</h4><p>For those rare instances when things might not go as planned, we’ve built in a manual override. By adding a simple annotation to the HPA, the Service Scaler can be bypassed, putting control back in the hands of our operators.</p><blockquote>service-scaler.kubernetes.io/managed: “false”</blockquote><h3>Game Plan: patch “minReplicas”</h3><p>With the ServiceScaler framework in place, we proceeded to adjust the <em>minReplicas</em> field of the Horizontal Pod Autoscaler (HPA) based on the time of day for 200+ deployments. We divided the 24-hour period into three distinct intervals:</p><ol><li><em>Morning</em> (8am — 4pm)</li><li><em>Evening</em> (4pm — 12am)</li><li><em>Night</em> (12am — 8am)</li></ol><p>The corresponding <em>minReplicas</em> values for each interval was calculated statistically, proportional to the observed load patterns.</p><h3>Aftermath: More Than Just Promising Numbers</h3><p>We achieved a <strong><em>25%</em></strong> reduction in VM costs whilst ensuring our infrastructure was breathing in sync with our business demands. Let’s take a look at some visuals portraying the reduction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Su9QO71CFQtW9xrBaafyiQ.png" /><figcaption>node-count reduction</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*8cv9UqX7lpy7kabJ7l3RSA.png" /><figcaption>vm-quantity reduction</figcaption></figure><p>We’ve open sourced the <a href="https://github.com/udaan-com/service-scaler">Service Scaler</a>, so be sure to give it a spin! Contributions and feedback are always welcomed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efe696c68f9d" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/taming-the-ebb-and-flow-cost-efficient-time-based-autoscaling-efe696c68f9d">Taming the Ebb and Flow: Cost Efficient Time Based Autoscaling</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unveiling Innovation: udaan’s Inaugural Hackathon 2023]]></title>
            <link>https://udaan.dev/unveiling-innovation-udaans-inaugural-hackathon-2023-a2d6c9db0b86?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/a2d6c9db0b86</guid>
            <category><![CDATA[culture-change]]></category>
            <category><![CDATA[innovation]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[creativity]]></category>
            <dc:creator><![CDATA[Gaurav Bhalotia]]></dc:creator>
            <pubDate>Sun, 20 Aug 2023 02:15:26 GMT</pubDate>
            <atom:updated>2023-08-20T02:15:26.076Z</atom:updated>
            <content:encoded><![CDATA[<p>udaan celebrated its first ever tech meet-up ‘Techverse’ in the first week of August 2023, where engineers from various locations flew down to Bangalore for a week of fun, collaboration, learning and reconnecting with our customers. As part of the meet-up week, we hosted our inaugural Hackathon. This event offered a unique platform for our talented engineers to elevate their skills and channel their creativity, engaging in a 24-hour marathon exploration of the product lifecycle, from ideation to implementing a working prototype; and finally delivering a sales pitch to a panel of judges.</p><p>The underpinning mantra of the Hackathon was a simple yet potent phrase: ‘Unleash Your Inner Geek.’ With this rallying call, participants were not merely invited to demonstrate their technical prowess, but rather to delve into the depths of their creativity and problem-solving skills but also to build for Bharat. Engineers were encouraged to push their boundaries, break conventions, and craft solutions that solved any real-world problem, not restricted to udaan. Witnessing a remarkable 45+ submissions, culminating in 38 teams crossing the finish line, albeit sleep-deprived, the energy fuelled by adrenaline and the iconic red bull.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8QiAf1McdNnwJ5yJH7_BdQ.jpeg" /><figcaption>Red bull team supplying energy potions to the hackers :)</figcaption></figure><h3>Mentoring: Nurturing Innovators</h3><p>Each registered team was paired with a mentor from our esteemed executive team (TAB team). These TAB team leaders dedicated their time to collaborate with the teams both prior to and during the event, skilfully guiding them through the conceptual landscape and assisting in transforming ideas into concrete solutions. This constructive collaboration with our leadership team created a coming together of collective wisdom, enriching the journey towards innovation.</p><p>In the true sense of celebrating the spirit of technology at udaan, this mentorship not only helped hone ideas but also created a good tech connect for our leadership teams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rc9tEOv-WbZyZD1q2Aeg7Q.jpeg" /></figure><h3>Recap of an Unforgettable Experience</h3><p>As the dust settled and the final lines of code were written, the Hackathon had etched a memorable experience in the hearts of all involved. The collective energy, sleepless nights, and relentless pursuit of excellence culminated in an event that was more than a competition — it was a celebration of innovation.</p><p>Participants delved deep into their wellsprings of creativity, ignited by an unbridled passion for technology and innovation. Among the highlights, udaan’s trailblazing engineers — <a href="https://www.linkedin.com/in/sidsr/">Siddartha Reddy</a>, <a href="https://www.linkedin.com/in/tarun-mangal-3200021/">Tarun Mangal</a> and <a href="https://www.linkedin.com/in/shashwatagarwal/">Shashwat Agarwal</a> — reunited to evoke cherished memories from seven years ago when they forged the initial fragments of udaan’s technological journey. Embodying an entrepreneurial spirit, we even witnessed the convergence and divergence of ideas, with teams engaging in idea mergers and splits. This flexible approach saw teams pivoting their focus after identifying shared problem spaces, a testament to the adaptive ethos of the event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b8WplF4rLeqWlJ3ebivNfQ.jpeg" /><figcaption>Fun moments on the hack floor</figcaption></figure><h3>Judging and Awards: Celebrating Excellence</h3><p>The judging process commenced with a comprehensive floor walkthrough led by a panel of judges, aimed at handpicking the most promising ideas for further consideration. From the initial pool, a curated selection of ten standout ideas advanced to the final round. During this crucial stage, these shortlisted ideas were presented before an esteemed panel of judges, in addition to a larger audience spanning the entire company.</p><p>The criteria for evaluation encompassed multiple factors, including the degree of innovation, user-friendliness, potential impact, intricacy of the solution, and quality of presentation itself. This ensured that the ideas not only demonstrated technical prowess but also the ability to resonate with audiences on multiple levels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w07tx0F53jzkLmFfV4XCPw.jpeg" /><figcaption>Floor walkthroughs by the Judging panels</figcaption></figure><p>Artificial Intelligence, along with Generative AI (Artificial Intelligence), spurred a multitude of innovative ideas, including:</p><ul><li>AI-powered voice agents for enhanced customer support.</li><li>Multilingual voice interface amplifying app accessibility.</li><li>Extracting patterns from customer support calls for insights.</li><li>Utilising phone cameras for seamless inventory replenishment.</li><li>Human like chat interface to udaan analytics.</li><li>Decoding investment algorithms and trust from YouTube content.</li></ul><p>Three of these groundbreaking concepts secured their place in the esteemed league of final winners.</p><p>Five winners emerged, as highlighted below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uAhqsI6ynMbS25MQG5nvxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uRAdVF0ruCPzjZiFSU6JWw.jpeg" /></figure><p>In summary, the udaan Hackathon 2023 was not just an event; it was a hub of innovation, a showcase of creativity, and a testament to effective teamwork. As we move towards a tech-driven future, I invite all engineers to keep their passion alive and contribute as architects in this evolving eB2B commerce landscape.</p><p>A sincere thank you to the participants, mentors, judges, and organizers who made Hackathon 2023 a reality. Look forward to the next year’s edition of the event, brimming with even more groundbreaking innovations brought to you by team udaan.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2d6c9db0b86" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/unveiling-innovation-udaans-inaugural-hackathon-2023-a2d6c9db0b86">Unveiling Innovation: udaan’s Inaugural Hackathon 2023</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reacting to Change: Tale of a Web Developer Improving Startup Performance for a large React Native…]]></title>
            <link>https://udaan.dev/reacting-to-change-tale-of-a-web-developer-improving-startup-performance-for-a-large-react-native-854f8a4850fd?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/854f8a4850fd</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[app-startup-performance]]></category>
            <category><![CDATA[perceived-performance]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Divjot Singh]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 04:50:51 GMT</pubDate>
            <atom:updated>2023-08-15T04:50:51.166Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reacting to Change: Tale of a Web Developer Improving Startup Performance for a large React Native App | udaan</h3><h4>Two years into my stint at udaan, I was tasked with “improving the startup performance” of our react-native app. I asked myself, what does that even mean and how do I even begin tackling this?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v5yc11aab7IHcdFs" /><figcaption>AI-Generated image of a person scratching their head while looking at a large billboard with React’s atom logo at night with a starry sky</figcaption></figure><p>Join in my journey of understanding react-native’s startup flow, identifying bottlenecks, using simple optimization techniques, discovering common pitfalls with startup time telemetry, and realizing the importance of perceived performance. This isn’t a “one trick to boost your app performance by 10x”, but rather a long journey of figuring things out, finding patterns in a mess, measuring impact and delivering a much improved experience to your users. My hope is that this helps you build intuition and tackle daunting problems with your software, and at the same time learn from the larger community about similar challenges faced by developers in the react-native ecosystem.</p><p>It’s a long one, but don’t worry, there’s a tl;dr at the bottom.</p><h3>Background</h3><p>I know, as a web developer, what optimization of page load performance feels like. You go to <a href="https://web.dev/measure">web.dev/measure</a>, get a score for various metrics, and follow the recommendations mentioned over there. The usual suspects are large asset files, lack of good compression (brotli/gzip), lack of code splitting, lack of appropriate resolutions for images, lack of font compression, lack of inlining of assets, lack of inlining of HTML (SSR), lack of preloading/prefetching, lack of a CDN, lack of optimization of waterfalls, and so on.</p><p>If you squint hard enough, everything I just mentioned is basically trying to fit as much relevant information to that page’s initial render in the tiniest network footprint. Just taking care of that usually takes care of everything else. Even alternatives to ReactJS, like Preact, are touted for their 3kb size, and not necessarily for their runtime performance improvements.</p><blockquote>Fast 3kB alternative to React with the same modern API<em> <br></em><a href="https://preactjs.com/"><em>— Preact’s tag line</em></a></blockquote><p>Of course, there are caveats to the above, you do find fine-grain reactivity winning over lately thanks to efforts by the team behind <a href="https://svelte.dev/">Svelte</a> and <a href="https://www.solidjs.com/">SolidJS</a>. You also see a plethora of ReactJS-like alternatives that regularly outperform the runtime performance of ReactJS. In fact, ReactJS without hooks stands at ~95th position as of the time of writing on Krausest’s <a href="https://krausest.github.io/js-framework-benchmark/2023/table_chrome_115.0.5790.98.html">js-framework-benchmark</a>, while ReactJS with hooks is further behind, yet that’s the default choice.</p><p>Speaking of React, React Server Components, the next big thing in the React world also tries to primarily solve for the network bandwidth and bundle sizes.</p><blockquote>Put another way, the server, far more powerful and physically closer to your data sources, deals with compute-intensive rendering and ships to the client just the interactive pieces of code.<br><em> </em><a href="https://vercel.com/blog/understanding-react-server-components"><em>— Understanding React Server Components</em></a></blockquote><p>This tells us that improving the roundtrip performance matters far more when it comes to the web world rather than improving runtime/interactive performance. Maybe it’s thanks to browser engine vendors who consider the real-world performance of these frameworks when optimizing their hot code paths. Maybe it’s the fact that web-apps are usually very simple compared to native apps in terms of interactivity.</p><p>Needless to say, react-native is completely different <em>(or is it? </em><a href="https://www.youtube.com/watch?v=32EJg8lqJgQ"><em>vsauce.mp3</em></a><em>)</em>. There is no one “engine” per se. Host platforms have their own complex web of APIs, that introduce breaking changes annually. React Native adds its own layers of abstraction. And finally, there’s your application code using all sorts of third-party libraries. All the assets are bundled with the app and are accessible locally, so there’s no network roundtrip optimization to consider here. <br>When I was tasked with this, very little of my <a href="https://www.youtube.com/watch?v=lN8b_fXRC_A">web performance knowledge</a> could easily translate, or so I thought. I had to dive deeper.</p><p>The article is divided into three parts that demarcate three distinct parts of this journey. They deal with identifying the root cause via measurements and benchmarking, deploying fixes and measuring the impact, and lastly further improving the perception of startup loading times.</p><h3>Part 1: Let’s dive deep</h3><p>Quick Google searches left me with even more doubts. There’s no one answer to why your particular app is slow to start. Could it be the react-native version we were using (we already had Hermes enabled so everything post that wouldn’t necessarily bring large improvements)? Could it be the react-navigation version we were using? Should we migrate to react-native-navigation instead (yes, they’re two different things)? Maybe we should move to Flutter? What about running a PWA inside a native shell? All of these were wild guesses with heavy costs. Unlike websites, you can’t just upgrade every single thing about your app and expect to not have to worry about your old code base at all. Even though we heavily use <a href="https://microsoft.github.io/code-push/">CodePush</a>, upgrading the react-native version and pushing a new native release to respective application stores would still mean we would have to push bugfixes and maybe even major features to the old version until the new version is fully adopted, which can take anywhere from 1–3 months. Upgrading native dependencies would also lead to similar caveats as their JS APIs may not always be backward compatible. And moving to Flutter is a different story altogether. Even after going through all these steps, there’s no guarantee that we would’ve solved the problem.</p><p>Here’s how I see it, you seemingly have very little control over how things boot up when you use a complex stack like this. You can’t really remove all your modules, you can’t really delete all our JS logic, and you can’t really remove all your UI code. Largely, what you do between JavaScript VM kicking in and your first component rendering is where your control lies as someone who’s proficient only in JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tCLluwWJm2OOl0COY0VQJA.png" /><figcaption>An Excalidraw screenshot that shows 3 rectangles, “MainActivity”, “react-native” and “App Code”, left to right. “react-native” has two more rectangles within it; “modules” and “JS Bundle” left to right, implying that “react-native” phase has a module initialization phase and a “JS Bundle” execution phase. “App Code” has two rectangles within it; “Boot” and “&lt;UI /&gt;”, implying that “App Code” has a bootstrap phase where things happen before React components are mounted, and a “&lt;UI /&gt;” phase where React components and their lifecycles (componentDidMount, useEffects) dictate where time is spent.</figcaption></figure><p>A more formal graphic would be something shared by react-native’s own team, Ram Narasimhan, who has excellent videos on the same in their Chain React talks (<a href="https://www.youtube.com/watch?v=83ffAY-CmL4&amp;t=1331s">2018</a>) (<a href="https://www.youtube.com/watch?v=nphKGWjhg2M">2019</a>) (<a href="https://www.youtube.com/watch?v=_5Oo51viLw0">2020</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mQmJQBceK4_yVYrJWDYSSg.png" /><figcaption>A screenshot from the “Chain React 2019 — Ram Narasimhan — Performance in React Native” video around 9-minute mark, where Ram is describing all the steps that take place to go from app launch to first View to be rendered. It has a yellow bar, denoting the app startup time timeline. Beneath there are two bars horizontally laid down; “native” in blue and “JavaScript” in green, implying the first bar is comprised of these two bars. Then there are furthermore bars beneath “native” and “javascript”, like a flame chart. “native” has “init” taking 1/4th of space, “native modules” taking half space, and “jsvm” takes the remaining quarter. “Javascript” has “init”, “network” and “components”, all taking roughly a third of space. “components” has unlabeled bars underneath, implying various application components would be taking their individual times.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i_W07zhYeAok6ZOKtw8ryQ.png" /><figcaption>A screenshot from React Native EU 2020: Parashuram N — React Native Performance — Take 2 around the 2-minute mark. Parashuram is recapping his previous talk with the same screenshot mentioned above, this time it has labeled arrows to summarize the previous talk. The yellow bar is labeled as “app start”, this time around the bar is much shorter from its original length, and the original length is expressed as a dotted rectangle, implying we have reduced the startup time from what it was originally. The leftmost edge of the bar has an arrow labeled “ReactMarker”, denoting that it can be measured using React Markers, as explained in the previous talk. The rightmost edge has two arrows pointing to it. One says “End Marker”, denoting when we stop measuring the “startup time”, this could be the presence of a particular &lt;View nativeId=’1234’ /&gt; component, measured by an event listener on the native side where the nativeId matches. The other arrow says “Better App Startup time”, implying that we’ve reduced the bar length via optimizations discussed in the previous talk. This time around “network” has moved from being underneath “JavaScript” to being right beneath the “native” bar, but starting at the same time as “init”. The arrow pointing to “network” says “Native network, Mock Data, Native Loading Screen”, implying we can move the “network” required for app launch from “javascript” and do it in “native” land, to prevent stalling. “init”, “native modules” and “jsvm” are right where they were in the previous screenshot, just that “network” is now parallel to these three, implying concurrency. “TurboReactPackage” labeled arrow points to “native modules”, and “Hermes, JS Profiler” points to “jsvm”, implying strategies to improve these phases of startup. “init” underneath “javascript” has an arrow pointing towards itself labeled as “inline requires”, a strategy used to reduce module resolution times. “React Profiler” points towards the bars underneath “components”, implying “React Profiler” can be used to optimize these.</figcaption></figure><p>If I’m being honest, I don’t understand every single thing here. It was a bit intimidating at first. Don’t get me wrong, Ram explains it really well and it makes great sense. However, I could see large gaps in my understanding of the stack and domain knowledge required to tackle this. And I think that’s okay. It’s okay to be intimidated by something that runs your regular looking JavaScript and ReactJS code on a custom highly optimized JavaScript VM, on a framework that glues native platform APIs and the said VM, with fancy stuff like TurboModules, Hermes, Bridge, or JSI, in handful of languages that you may have very rusty familiarity with. Yup, it’s supposed to be hard.</p><p>However, one clear takeaway for me was that I need to measure before I can optimize anything. I need to understand how my app actually boots up, and where all the time is spent. Before I understand ReactMarkers, maybe I can take a hard look at the diagram I drew above and find the bottlenecks there. At least we’ll be somewhere in the ballpark. And trust me, the kinds of optimizations our app would require might not really reside in the native side of things, otherwise I’ll be having a hard time writing this post.</p><p>That’s my first learning to share. If your solution to the problem is to upgrade various dependencies, then the locus of control is never on your side. Sure, you may find great improvements every now and then (Hermes single-handedly saved so many react-native projects!), but at what opportunity costs? What if you’re waiting for react-native’s new architecture for years and even when it lands, you may still not necessarily get 5x improvements in startup performance? Was it worth the wait?</p><h3>Measure twice, cut once</h3><p>This is when I realized I shouldn’t approach this problem by finding packages to update in my package.json. I need to understand how our app even boots up. I was also tasked to evaluate react-native’s viability for our use case, and see if moving to alternate technologies is indeed a smart move for us or not.</p><p>Before I looked at any code, I wanted to truly see how slow our app is. Previous developers (<a href="https://www.linkedin.com/in/kartikssj/">Kartik Ukhalkar</a>, <a href="https://www.linkedin.com/in/bhavya-rawal/">Bhavya Rawal</a>) had already done great work by adding excellent telemetry. We already knew how much time our app spent in the real world to go from MainActivity to the first screen. The numbers looked something like this; 4.2 seconds on P50, 12.2s on P75, 59s on P90, and ~7 hours on P99 (Press F for our poor users waiting for hours to load our app). Yeah, something isn’t right here. Let’s put a pin on it for now.</p><p>Now that I know real-world performance, I wanted to compare our app to other apps. I launched all remotely resembling apps, and even highly performant ones, and tried to compare their performance <a href="https://www.youtube.com/@DigitalFoundry">Digital Foundry</a> style by making a video and comparing the start and end manually. I warmed up my phone by opening them all first after a fresh install and bypassing their onboarding step. Not the most scientific, but the most user behavior-like I would say.</p><p>This is what I found on my mid-range Android phone (Realme X, Snapdragon 710);</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2FeRjWn17kqhI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3DeRjWn17kqhI&amp;image=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fi.ytimg.com%2Fvi%2FeRjWn17kqhI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/052cd46d91f944b2b4eedbb52268c89b/href">https://medium.com/media/052cd46d91f944b2b4eedbb52268c89b/href</a></iframe><p>Never expected our app to actually be on the top side of the list! I was surprised to know Swiggy was actually technically slower to load, even though I regularly use it and never had any issues with its loading times. Clearly, the designers and engineers at Swiggy understand the importance of perceived performance, something we’ll talk about later in the article. Anyway, coming to our question of the viability of react-native, I know from my previous stint at Swiggy that it is not a react-native app, and if our app could actually “beat” it, then we can say that react-native is a fairly safe bet. Flipkart is also known for using react-native and their incredible engineering team for building one of the finest solutions in the react-native world, so if our app is able to match its performance as is in my unscientific test, surely we can ooze out a bit more performance staying with react-native. Note, unlike most b2c apps, our users are business owners, not necessarily with high-end phones. Another thing to note is that not all apps are comparable. BigBasket shows a relatively simple first page, notion’s shell is interactive much earlier just that their webview takes its time to load the page, and Slack shows a list of channels by default (which is much easier to cache). The intent of user also plays a role here, when you open Swiggy, you probably have very high intent to order something and your fingers quickly tap the right buttons right away, while when you open slack, you are probably dreading to see a list full of red bubbles. So please don’t draw incorrect conclusions out of this, the goal is simply to understand how apps load and how they feel and where udaan stands, at least in this unscientific test.</p><p>Coming to udaan, despite absolute numbers showing udaan to actually be quite competent, why is it that our team and users feel our app is really slow? I guess it’s a mix of perception, our user base, and a lack of optimizations. No matter how fast the app loads in this test, the median performance is still 4.2s, some ~30% slower than what we observed above, this probably means the majority of our users have even slower phones than my mid-range phone.</p><h3>Taking matters into your own hands</h3><p>So far I’m convinced our app is actually fairly performant and our bottlenecks are probably specific to our app code and not the technologies we are using. This meant I needed to dig deeper. I spent the next few days adding logs, right from MainActivity to the first meaningful screen we show to our users. I could figure out integrating several debugging tools, learn about <a href="https://source.android.com/docs/core/tests/debug/systrace">systrace</a> and make sense of <a href="https://fbflipper.com/">flipper</a>, but nothing beats the simplicity of the mighty logger. I can add a logger between two timestamps in any language and call it a day. By understanding the mechanics of how our app loads, I could truly understand the bottlenecks in the startup journey. This is what I came up with in the debug mode;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7W0UDfTHoQorBg8JjbnefQ.png" /><figcaption>A Gantt Chart with the title “App Startup Timeline (Before)”. The raw data can be found under “Appendix” at the bottom of the post in tabular format.</figcaption></figure><p>Legend:</p><ul><li>Native Package Registration is the time spent for each packages.add() in react-native template code for non-autolinked packages.</li><li>JS Bundle is a step in a debug mode where Metro bundler would build and stream a bundle to the emulator. This would be a file-read operation in the production build. This took ~15s on my setup, but I’ve trimmed it to 0.5s to prevent it from overshadowing everything else.</li><li>CodePush Wrapper + Redux is one of the first react components we render, the time is representative of react-native giving control to JS execution and the time spent to go from AppRegistry.registerComponent to render the function of these components.</li><li>&lt;AppBuilder /&gt;, &lt;App /&gt;, &lt;CodePush /&gt; etc. are just small react components in the initial react tree.</li><li>&lt;LoadingBanner /&gt; is the first react screen visible to user after splash screen. It is visible while we “load” our app.</li><li>Configuration.init() is the first operation outside of ReactJS where we await various promises and refresh our session tokens with our auth service.</li><li>&lt;ImagePerfTracker /&gt; is another small react component.</li><li>&lt;NavigationContainer /&gt; is the component that builds our react-navigation stack, tabs, drawers navigators.</li><li>&lt;InitialRoute /&gt; is the first react-navigation screen. It’s componentDidMount waits for navigation focus event, and a DeepLinkHelper.init() to finish before navigating to the actual first screen (HomePage/Login).</li></ul><p>This activity, while tedious, helped me truly understand our app better. It doesn’t even matter if it’s accurate or not, we only need to find relatively large tasks that we could move around or even eliminate here. And I could see that most of the time is spent AFTER control flow reaches JS, another sign that the problem lies in our app code side. Most of these components are part of critical path, and it doesn’t seem like we’re doing anything wasteful here. CodePush and Redux are needed to be initialized before anything else, a LoadingBanner is shown right when a long running task is executed, NavigationContainer has to setup all our screens during boot, and we need to handle deep links before showing the first screen to avoid splash of incorrect screens. Everything looks relatively alright.</p><p>Next, I tried to breakdown Configuration.init() and InitialRoute’s mounting phase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qkjt4YkJh0yWBNfAWFi7QQ.png" /><figcaption>A Gantt Chart with a title “Configuration.init() Breakdown”. The raw data can be found under “Appendix” at bottom of the post in tabular format.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNjrvOXlAZUR8GQNjQPCbg.png" /><figcaption>A Gantt Chart with a title “&lt;InitialRoute /&gt; breakdown”. The raw data can be found under “Appendix” at bottom of the post in tabular format.</figcaption></figure><p>I have simplified the pieces of the code to just a simple component with useEffect, however this was buried behind 5 components and different helper functions. So depending on your codebase and its age, expect finding such a pattern to not be so easy and obvious.</p><pre>/**<br> * Imagine this is how Configuration.init<br> * NavigationBuilder and LoadingBanner are<br> * used in the app startup<br> */<br>function App() {<br>  const [status, setStatus] = useState({<br>    loading: true,<br>    config: null,<br>    error: null,<br>  });<br><br>  useEffect(() =&gt; {<br>    let mounted = true;<br>    Configuration.init()<br>      .then((config) =&gt; {<br>        if (!mounted) return;<br>        setStatus({ loading: false, config, error: null });<br>      })<br>      .catch((error) =&gt; {<br>        if (!mounted) return;<br>        setStatus({ loading: false, config: null, error });<br>      });<br>    return () =&gt; {<br>      cleanup();<br>      mounted = false;<br>    };<br>  }, []);<br><br>  if (status.loading) return &lt;LoadingBanner /&gt;;<br><br>  if (status.error) throw status.error;<br><br>  return &lt;NavigationBuilder config={status.config} /&gt;;<br>}</pre><p>Hmm, at this point these charts started resembling the Network Panel of a website. I asked myself, can’t I just “prefetch” or “preload” some of these tasks and reduce the stalling phases in the pipeline? Clearly Configuration.init() is a critical task that blocks everything else, doing this as the very first step would speed up everything. Similarly, DeepLinkHelper.init() can be done before even React components are mounted. These functions are promise returning functions, so I thought it would be easier to fire up these functions and “cache” these promises in their pending state, so that by the time they’re actually required, they might as well be resolved. There are other obvious optimizations, such as loading session on native side and send it over the bridge right during boot, or to consider TurboModules to reduce package registration times, or refactor how we use react-navigation. All of these appeared to be large breaking changes, that may come with their own set of bugs, and may require segmenting our users and annoy development team to maintain two branches of our app for months. And they didn’t even seem to be that much impactful. Loading Configuration.init() ~500ms sooner seems much larger win than shortening a ~180ms &lt;NavigationBuilder /&gt; step to say ~100ms. So I shortlisted these two init functions to begin with. Here’s how you can go about “caching” these promises early:</p><pre>// before<br>export class Configuration {<br>  static init() {<br>    return somePromiseReturningFunction();<br>  }<br>}<br><br>// after<br>export class Configuration {<br>  private static promiseValue = null;<br><br>  static init() {<br>    if (this.promiseValue) {<br>      return this.promiseValue;<br>    }<br>    this.promiseValue = this.actualInit();<br>    return this.promiseValue;<br>  }<br><br>  static actualInit() {<br>    return somePromiseReturningFunction();<br>  }<br>}</pre><p>The above changes allow us to call Configuration.init() at any moment. So we can do this right before ReactJS is even in the picture, without changing its actual usage in App.</p><pre>/**<br> * Warm up Configuration.init for later use in &lt;App /&gt;.<br> * Make sure it is idempotent to avoid side-effects.<br> */<br>Configuration.init();<br><br>AppRegistry.registerComponent(appName, () =&gt; cp(Root));</pre><p>Say what you may, but classes are sometimes good tools encapsulating data and behaviour. If you’re more of a functional purist, I guess one could write it like this:</p><pre>// before<br>export function initConfiguration() {<br>  return somePromiseReturningFunction();<br>}<br><br>/**<br> * Should be called once per session<br> */<br>function createConfigurationInitializer() {<br>  let promiseValue = null;<br><br>  return () =&gt; {<br>    if (promiseValue) {<br>      return promiseValue;<br>    }<br>    promiseValue = somePromiseReturningFunction();<br>    return promiseValue;<br>  };<br>}<br><br>export const initConfiguration = createConfigurationInitializer();</pre><p>Moving on, we can do the same with DeepLinkHelper.init(), even though it depends on Session to be loaded, it’s still possible to “warm up” this async task before it’s required in &lt;InitialRoute /&gt;. It was also waiting on three other DeepLink handlers (CleverTap, AppsFlyer and react-native’s own Linking package), but sequentially. I made them concurrent to optimize it further, though keep in mind, the first few seconds of app launch tax the hardware quite a bit, CPU, GPU, RAM, everything is kick started to dump huge payloads all over the place, so it may not always be easy to find gains via concurrency.</p><p>I’ve simplified the code once again, so expect it to be nested and not so easily laid out in the real world. Nobody wants to write unoptimized code, in this particular case it probably started off with Linking.getInitialURL() where using async/await probably made sense, but with new requirements, developers just followed the already established pattern and added one more async call.</p><p>It’s simply impossible to anticipate and assume problems of future to write complex optimized code prematurely that actually scales well, but it is relatively very easy to identify unoptimized and simple code once a problem actually arises as you scale.</p><pre>// before<br>const linking = await Linking.getInitialURL();<br>const cleverTap = await CleverTap.getInitialUrl();<br>const appsFlyer = await AppsFlyer.getInitialUrl();<br><br>/* once all promises resolve, one with a url gets picked */<br>const url = linking ?? cleverTap ?? appsFlyer;<br>if (url) {<br>    handler(url);<br>}<br><br>// after<br>let handled = false;<br>const handleOnce = (url?: string) =&gt; {<br>    if (!url) return;<br>    if (hanlded) return;<br>    handled = true;<br>    handler(url);<br>};<br><br>/* first promise to resolve with a url gets handled */<br>Linking.getInitialURL().then(handleOnce);<br>CleverTap.getInitialUrl().then(handleOnce);<br>AppsFlyer.getInitialUrl().then(handleOnce);</pre><p>And yup, just these two pipeline reordering steps were enough to get substantial performance wins in my local tests. We went from 2335ms to 1862ms, a ~20% improvement without actually touching any business logic! Also observe how Configuration.init() and DeeplinkHelper.init() are now running concurrently to other tasks. Even though some of the task durations have actually increased, there’s still a net improvement in overall startup time. A ~470ms win is quite noticeable even in the debug mode and should stand out in production as well. Though I wouldn’t read too much into the absolute figures on a local setup in debug mode, the story may be different on production. <em>foreshadowing.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dAC5qTmkhNO4EBrln5sggw.png" /><figcaption>A Gantt Chart with a title “App Startup Timeline (After)”. The raw data can be found under “Appendix” at bottom of the post in tabular format.</figcaption></figure><h4>How to deploy scary changes?</h4><p>I was afraid of releasing it as is. What if some race condition somewhere could break something completely different? Sure our app loads ~500ms slower presently, but at least it loads! Also, how do I truly quantify these results in production? Can we do some sort of A/B?</p><p>Well, this all happens before session is loaded, so we need to bucket our users, or more accurately user sessions, on device. Fear not, Math.random() is here!</p><p>I refactored the above code something like this to begin with:</p><pre>/**<br> * Housekeeping before we mount and render the root react-native component.<br> * Use this to eagerly prefetch/initialize/warm critical I/O sources.<br> * Make sure these initializations aren&#39;t blocking main-thread,<br> * as that can lead to delays in startup times.<br> */<br>bootstrap.init();<br><br>AppRegistry.registerComponent(appName, () =&gt; cp(Root));</pre><p>This allowed me to do my shenanigans in an encapsulated bootstrap.init() method. I created a getLocalExperimentByPercent utility function that uses Math.random() to segment each session. I pushed my changes with conservative experiment values like 1% and regularly monitored its impact until I was confident about its stability. I actually found some bugs along the way, like this optimization breaks when the app is started by a notification due to some race condition. It wasn’t hard to disable this optimization in this manner, and we anyway don’t care about startup performance for background notifications.</p><pre>/**<br> * This is where we boostrap all startup related dependencies.<br> * Goal is to fire things asynchronously ASAP and then use them when they&#39;re actually needed.<br> * To do this, we&#39;ll save the reference to promise and keep them idempotent.<br> */<br>export class bootstrap {<br>  static config = {<br>    /**<br>     * warms up Configuration.init and DeeplinkHelper.init.<br>     * Observed benefit has been around 20-40%<br>     */<br>    shouldWarmUp: getLocalExperimentByPercent(1),<br>  };<br><br>  static init() {<br>    // ... other init tasks like setting up telemtry module, error reporting module, etc.<br>    const { shouldWarmUp } = this.config;<br>    /**<br>     * We don&#39;t need to optimize background app launches or shouldWarmUp is disabled<br>     */<br>    if (AppState.currentState !== &quot;active&quot; || !shouldWarmUp) {<br>      return;<br>    }<br>    /**<br>     * Warm up Configuration.init for later use in &lt;App /&gt;.<br>     * Make sure it is idempotent to avoid side-effects.<br>     */<br>    Configuration.init();<br>    /**<br>     * Warm up DeeplinkHelper.init for later use in &lt;InitialRoute /&gt;.<br>     * Make sure it is idempotent to avoid side-effects.<br>     */<br>    DeeplinkHelper.init();<br>  }<br>}<br><br>/**<br> * Simple util to provide local experiment system using Math.random<br> * This won&#39;t be sticky, i.e. each session is unique as oppposed to each user.<br> */<br>const getLocalExperimentByPercent = (percent: number) =&gt;<br>  Math.floor(Math.random() * 100) &lt; percent;</pre><h3>Was it worth it?</h3><p>So far whatever I’ve shared with you has very little to do with react-native, platform APIs or third party dependencies. One may even wonder if any of this was even worth it, after all how efficacious these ~100 lines of code could truly be. Thanks to the telemetry already put by my predecessors, it wasn’t hard to put it to the test. The changes were deployed in late May 2022 as a CodePush update (no native release required!). And I couldn’t have been happier with the results. We actually see a doubling of the performance on P75. This directly translated to 35% increase in conversions to our search page!</p><p>When I think about it, I guess for our users every latency would have exaggerated effects. If my auth handshake took ~400ms on my WiFi connection, their highly congested marketplace with appalling 4G performance might even be ~1200ms. Similarly, if my mid-range phone took sub 500ms for most tasks, their phones would’ve greatly benefited from this pipeline reordering to better utilize the constrained hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_AOS6tW0fTjkDi3AgNR4A.png" /><figcaption>A bar graph showing msApp for 75th Percentile. Jan 2022–12.59K, Feb 2022–12.98K, Mar 2022–13.15K, Apr 2022–10.37K, May 2022–12.49K, Jun 2022–6,637, Aug 2022–5,841, Sep 2022–5,722, Oct 2022–5,443, Nov 2022–5,354, Dec 2022–5,335.</figcaption></figure><p>I performed my <a href="https://www.youtube.com/@DigitalFoundry">Digital Foundry</a>-esque test once again, and yup, it was faster. We jumped a spot and were now in the top 3 apps from my weirdly curated list, with ~400ms improvement. Although, we can see other apps also improved and some even regressed, and this was done few weeks apart, so it’s probably not wise to read too much into it. However, our app still “feels” slow, despite being objectively faster. Clearly we need to work on perceived performance at some point.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f826d2d303bf80c5b2828c02a4fc65aa/href">https://medium.com/media/f826d2d303bf80c5b2828c02a4fc65aa/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2F_ygR9MF5J2M%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3D_ygR9MF5J2M&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/de4af8fe2d7ba3beb00e79c15ba93ed3/href">https://medium.com/media/de4af8fe2d7ba3beb00e79c15ba93ed3/href</a></iframe><p>Promising stuff. Now let’s look at the P90 numbers, which was already more than a minute! These changes could’ve saved them minutes of their lives every day. As I excitedly selected P90 aggregate group on <a href="https://mixpanel.com/">Mixpanel</a>, the startup performance of my frowns was beyond measure. I was utterly disappointed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpa_RQS_af0shVyfarEADg.png" /><figcaption>A bar graph showing msApp for 90th Percentile. Jan 2022–59.27K, Feb 2022–59.47K, Mar 2022–62.74K, Apr 2022–54.53K, May 2022–77.38K, Jun 2022–90.89K, Jul 2022–79.05K</figcaption></figure><p>“No, this can’t be right, I made it worse for them?! Shouldn’t my hypothesis only get proven right at fringes of our user base with even slower devices and slower network types?” I said to myself in despair. It was also curious to see how July numbers were better than June; this was my hint that these numbers are probably caused by events during June and now by the code directly.</p><h3>Part 2: Question everything, even the evidence</h3><p>I couldn’t believe it, so I dig deeper. I knew that P99 numbers were absolutely non-sensical. Nobody would wait for our app to load for hours, so something must be wrong with our measurements. I approached this from multiple directions.</p><ol><li>One of my colleagues recommended me to call some of the folks from this cohort. I requested access to their business phone numbers, and shortlisted ~5 people who were witnessing &gt;5 minutes startup times in the last week. They had all sorts of concerns, regarding promotions, delivery times, discovery of past orders, but they never mentioned app performance. When I specifically asked about app loading times, some said it’s alright, some said it’s okay, it loads up in 10–20 seconds. One said that even if it loads after 30 seconds it’s okay, but the order details page is loading very slowly for them. This was my first hint that our telemetry is reporting wrong numbers.</li><li>I looked at P90 closely over a span of a day, hour by hour in a tier 3 city. I was expecting to see a smooth line of ~60s, but that wasn’t the case. I saw numbers like 2.5s, 3.7s, 3.6s in most hours, but at some irregular intervals the number would spike up to 21s, and even 187000s (51 hours). These sporadic large spikes were making an otherwise ~3s P90 number an averaged 60s. 51 hours, damn, that’s over 2 days. These high peaks were not consistent, 12pm one one day, 3pm on another. All cities that I gathered the data for all had similar trends.</li><li>We have other react-native apps under udaan that were forked from the b2b app at some point in the past. I looked at their P90 numbers that are also measured similarly, and they actually were much better. Something must be unique about our app.</li><li>I also computed order conversion rates broken down by app launch. I made cohorts of 0–1s, 2–3s, 3–5s, 10–60s, 60s+ startup times. One would assume that if the app loads in 3–5 seconds vs 100–200 seconds, the user just might not care to place an order in the latter case. But I didn’t find any correlation. In fact, it was better in 10–60s group, which was also where majority of the reported startup times were. This was my second hint that these numbers are all non-sense.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0LsfdRk_ewDucv8f57cHg.png" /><figcaption>A screenshot showing line graph for Mar 20, 2022 — Apr 5, 2022 for msApp, P90. It’s largely near 0 but with peaks going as high as 500M. There’s a table beneath it, showing numbers ranging from 3000–5000 and and some in ~100 million. The average is 12.39M.</figcaption></figure><p>I started to wonder what all can make a simple subtraction so wrong. How we measure this msApp value is that we measure the time on the native side (t0) and pass it over the bridge to JavaScript side. Then, once we reach a particular phase of our startup timeline, we subtract the current system (t1) time with previously calculated native time, and send it to our telemetry service.</p><blockquote><em>🚨 React Native 0.72 adds </em><em>performance.reactNativeStartupTiming with similar measurements, though the pitfalls shared ahead might still be relevant.</em></blockquote><p>How can this number be so huge?</p><ol><li>What if t0 is from a previous app session? This can explain a number like 51 hours.</li><li>What if t1 occurs much after the app actually starts? This can explain sporadic events.</li><li>How come my changes regressed this number? What if t1 is actually that huge in certain cases?</li></ol><h4>Case 1</h4><p>After various experimentations and logging, I found that each time our codepush update is applied and the JS context refreshes, the startup time is counted again. The issue is that the native side never truly restarted, so that t0 was still stale. So if I started the app at 1pm, received an update at 1:30pm, and actually applied it at 2pm, t1 would be ~2 hours ahead of t0. This was easily fixed by adding an alreadyInvoked boolean that we flip to true after sending the initial t0 payload over the bridge at the native side. If JS requests for t0 again, say due to a codepush update, we can simply return early if alreadyInvoked is true, as we don’t have to measure this startup time. I did a small A/B using the above Math.random() system and yes, there was substantial difference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQF3mBk6hxtFPHqO9FnB5w.png" /><figcaption>A bar graph comparing two sets of data labeled “Without Fix (seconds)” and “With Fix (seconds)” for Sep 6, 2022 — Sep 13, 2022. “Without Fix” has erratic numbers, minimum value of 73.83 and maximum value of 784.7. “With Fix” is largely stable with a downward trend, with minimum value of 15.38 and maximum value of 23.06.</figcaption></figure><h4>Case 2</h4><p>The second point also turned out to be true. I got this hint from previously mentioned race condition I fixed by removing the optimization when our app was launched by a notification. So, t1 is measured when a particular component is mounted, but it doesn’t get mounted in case of a push notification. However, native system and some parts of our bootstrap timeline do get executed. Imagine I receive a notification at 1pm, and I actually open my app the next day. This would make t1 roughly 24 hours ahead of t0. This explains 51 hours. Users may receive notifications over the weekend but they may open the app only when the open their shops on Monday, for example. The fix was simple, we skipped these measurements if the app was in background using AppState.currentState !== &quot;active&quot;.</p><h4>Case 3</h4><p>What if t0 and t1 were truly that far apart? None of the above cases explain the regression that I might have caused by my simple optimizations? It was surely interesting to see that right when I was performing all these comparison and aggressively logging the app, the P90 numbers increased. Wait a minute, do we send logs in debug mode!? Yup. That was it. Can we please have a moment of laughter at the stupidity of this. Each time I was investigating our app performance, or a developer was running the emulator, we were inflating the P90 numbers! If only we didn’t work this hard, the numbers would’ve been so much better! The fix was simple, I just added an early return using __DEV__.</p><h3>Did we get it right this time?</h3><p>We pushed all these fixes under similar A/B experiments and took them to 100% by late September 2022. Now that we spent so much time fixing our telemetry, it was time to observe the impact, and it was once again incredible. Note, these improvements are largely on paper, as users were never actually observing 51 hour long app launches, but it doesn’t hurt to have accurate telemetry next time we do another round of optimizations. Note that P75 numbers immediately improved in June 2022, but improvements in P90 only started to appear around August-September 2022. This is also part of slow adoption rates at the fringes. The number came down to ~11s by the end of the year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cpr2UrHWQTWcBHFvWNYzRA.png" /><figcaption>A bar graph showing msApp for 90th Percentile. Jan 2022–59.27K, Feb 2022–59.47K, Mar 2022–62.74K, Apr 2022–54.53K, May 2022–77.38K, Jun 2022–90.89K, Jul 2022–79.05K, Aug — 39.02K, Sep 2022–20.33K, Oct 2022–13.86K, Nov 2022–11.71K, Dec 2022–11.66K. A clear downwards trend, settling around ~11 seconds.</figcaption></figure><p>This also shows that the P75 improvements weren’t the result of fixing the telemetry. However, we did see the numbers slightly improve (~200ms) and stabilize as these fixes were rolled out, making them much more deterministic. And as you can see, we have been consistently performant for almost a year now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zEqjL4392ryk8vSxZnXu1g.png" /><figcaption>A bar graph showing msApp for 90th Percentile. Jun 2022–194.8K, Jul 200–78.6K, Aug 2022–39.06K, Sep 2022–20.26K, Oct 2022–13.5K, Nov 2022 to May 2023 are all around ~11K. A sign of stability and consistency of data.</figcaption></figure><p>Fun fact, we did upgrade from react-native 0.63.5 to 0.70.6 sometime in December 2023. My incredibly talented teammate <a href="https://www.linkedin.com/in/karandikarmihir/">Mihir Karandikar</a> handled that migration for our app with ~300 screens. The adoption took ~4 months, during which he and <a href="https://www.linkedin.com/in/anupam-prakash-1a9aa4b7/">Anupam Prakash</a>, another exceptional developer, maintained two tracks of codepush, one for 6.x and other for 7.x versions of our app. This meant, most of the business logic had to deployed twice, for both android and iOS. Luckily, we have a layer of separation between our business logic (ui-screens) and app shell (udaan-fe/app), so it was as simple as updating a version in package.json of the two git branches (maybe we should write a blogpost on the same).</p><p>As you can imagine, this was a huge collaborative effort between release managers and developers, and we finally made it by April 2023 when both iOS and Android apps had reached ~95% adoption. We benefited a lot by modernizing our codebase and several third party dependencies. This added much more polish to otherwise neglected parts of our app. It was definitely much needed, as 0.63.5 was released more than 2 years ago at the time of the upgrade.</p><p>However, simply updating react-native didn’t really translate into startup performance substantially (~400ms). This only validated my initial gut feeling that simply updating package.json dependencies ain’t gonna cut it. Hermes was definitely the exception though.</p><h3>Part 3: Sometimes perception can matter more than reality</h3><p>The proverbial hotel elevator story comes to my mind when we talk about perceived performance. This is how it goes;</p><blockquote><em>A hotel manager was receiving complaints from guests that the elevators were running too slowly. She looked into speeding them up and installing destination dispatch, a multi-elevator optimization system, but the cost prohibited her from implementing either. The complaints continued to pour in and she was at a loss for what to do. She knew that she had to come up with a solution before the guests started leaving negative reviews. After much thought and consideration, she finally came up with an idea. She installed mirrors in the elevator. The guests, busy admiring themselves, actually were quite satisfied by the elevator’s speed, in fact they felt it was a bit too fast, if at all.</em></blockquote><p>I don’t know the validity of this story, but it seems reasonable. In fact, it is common almost everywhere you have to wait. Magazines at the Dentist’s, cheery music in office lobbies, useful tips and player stats, or sometimes even squeezing through tunnels in video games as the engine loads up the next level.</p><p>Softwares usually mask loading using splash screens and animations. This was quite evident in BlinkIt’s startup timeline. Kudos to their team for doing a fantastic job. Though BlinkIt’s actual startup time is slower in absolute terms, the experience actually feels quite delightful and reasonably fast.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2FdQn-d7tsiH8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3DdQn-d7tsiH8&amp;image=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fi.ytimg.com%2Fvi%2FdQn-d7tsiH8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e044b7c8737b0db3b9aa73008b76c8a1/href">https://medium.com/media/e044b7c8737b0db3b9aa73008b76c8a1/href</a></iframe><p>I teamed up with our design head, Gaurav Sharma, and we deployed a simple yet effective startup animation. The effort was primarily in fine tuning the durations. We kept it long enough to cover our P75 startup duration, with an extended loading screen in case even more time elapsed. Apologies for using an emulator for the comparison and for minor stutters in the video, I couldn’t find time to find the old APK to do side by side comparisons on same resolution on real device, but you get the idea I guess.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2FoQTfEJKXYfE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3DoQTfEJKXYfE&amp;image=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fi.ytimg.com%2Fvi%2FoQTfEJKXYfE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4b163dc563fcba8734c8fb675ff39a6/href">https://medium.com/media/c4b163dc563fcba8734c8fb675ff39a6/href</a></iframe><p>It’s really hard to measure impact of perceived performance for it’s purely subjective, but general consensus between the team was that the app felt really smooth and fast after this change. One of our Program Manager shared this with me.</p><blockquote><em>“The startup animation is really slick. The app genuinely feels so much faster. This was a great change!” </em>— A happy udaan user</blockquote><p>I think there’s a lot one can do with perceived performance. As we saw above, some of the apps loaded a second or two later than udaan, but still the perception was that udaan app feels slower. Fixing this bias is very difficult, but there’s definitely a strong argument to be made here that investing time in better loading experience can pay better dividends than oozing out a few 100ms using complex engineering. At the same time, it doesn’t mean it’s a silver bullet. Ajio Business, for example, tries to mask its ~10s startup time with an elaborate animation, and I wonder how less than ideal that could be for someone opening the app multiple times a day.</p><p>Coming back to udaan, we achieved the above by converting After Effects animation into an Animated Vector Drawable on Android along with <a href="https://github.com/zoontek/react-native-bootsplash">react-native-bootsplash</a>. You can actually use different splash screens for different android versions, by simply naming your “values” folder differently. As a web developer I found this pattern to be pretty cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*1NpwQhQu2fLazwSWYK8bAA.png" /><figcaption>A screenshot of VS Code’s folder tree view. It shows two expanded folders named “values” and “values-v31”. Both of them contain a “styles.xml” file. “values” folder has 2 other files “colors.xml” and “strings.xml”, implying these are used by default, and “styles.xml” from “values-v31” overrides the “styles.xml” from “values” when API_31 is detected, i.e. on Android 12 and above “values-v31/styles.xml” is used and on Android 11 or below “values/styles.xml” is used.</figcaption></figure><p>Here’s a part of our styles.xml for android. Pretty straightforward. If and when we wish to improve this animation, all we’ve to do is update the drawable/animated_logo.xml file and push a native release. It would be fully backwards compatible and wouldn’t require segmenting users.</p><pre>&lt;!-- values-v31/styles.xml on Android 12 and above, use .avd file --&gt;<br>&lt;style name=&quot;BootTheme&quot; parent=&quot;Theme.SplashScreen&quot;&gt;<br>    &lt;item name=&quot;windowSplashScreenBackground&quot;&gt;@color/bootsplash_background&lt;/item&gt;<br>    &lt;item name=&quot;windowSplashScreenAnimatedIcon&quot;&gt;@drawable/animated_logo&lt;/item&gt;<br>    &lt;item name=&quot;windowSplashScreenAnimationDuration&quot;&gt;3000&lt;/item&gt;<br>    &lt;item name=&quot;postSplashScreenTheme&quot;&gt;@style/AppTheme&lt;/item&gt;<br>&lt;/style&gt;<br><br>&lt;!-- values/styles.xml on Android 11 and below, use a PNG --&gt;<br>&lt;style name=&quot;BootTheme&quot; parent=&quot;Theme.SplashScreen&quot;&gt;<br>    &lt;item name=&quot;windowSplashScreenBackground&quot;&gt;@color/bootsplash_background&lt;/item&gt;<br>    &lt;item name=&quot;windowSplashScreenAnimatedIcon&quot;&gt;@mipmap/bootsplash_logo&lt;/item&gt;<br>    &lt;item name=&quot;postSplashScreenTheme&quot;&gt;@style/AppTheme&lt;/item&gt;<br>&lt;/style&gt;</pre><h3>What’s next?</h3><p>There’s a lot that we can still do, though I think we were lucky to discover the above pipeline optimization.</p><p>For starters, we have a lot of cleanup to do. Fast paced and high velocity culture naturally accumulates a non-significant amount of tech debt. As previously mentioned, we’ve roughly ~300 screens, though not all of those might be in use, or they could be clubbed together and refined. Such tasks usually have high cost but with seemingly low impact, but doing it for ~100s of screens definitely adds up. Reducing JS bundle should make the JS VM init times faster. Reducing number of screens should also improve &lt;NavigationBuilder /&gt;s performance (react-navigation). Lazy loading those screens might help us further.</p><p>Similarly, using TurboModules should in theory lazily initialize every single native package that isn’t part of the critical path. Imagine a QR Code scanner package that’s buried 5 screens deep after launch. The 330ms was only for non-autolinked packages, the auto linked ones are in the majority.</p><p>Streamlining all the necessary network calls (auth session and data for first screen for example) can also help us a lot. I am not sure how fragile moving this to native would be, coz we suddenly lose the benefits of colocating data requirements and UI/business logic, but it is definitely something to think about.</p><p>And we haven’t touched any third party logic and business logic yet. What if we looked closely at how CodePush works and optimized its code paths? What if we explored even better way to register our screens with priority (critical screens are registered immediately and rest are registered after the fact)? What if udaan’s first page wasn’t an infinitely loading feed but a “launcher” screen, akin to what BigBasket or Swiggy does? What if the feed is pre-populated with cached data so that the user instantly gets to use our app? There’s so much one can do!</p><h3>Closing Thoughts</h3><p>We have reached the end. I started with poor understanding of React Native and am now left with substantially faster startup times with minimal business logic changes, reliable deployment via experiments, and even a non-broken telemetry system with consistent reporting. So if you too are scratching your head trying to improve your app’s performance, I hope this article shares some insights as to how to tackle this problem beyond the general “enable this flag, use that package, delete that code” advice. All of this was achieved by an intimidated and scared web developer who simply added log statements all over the place to understand where all the time was spent.</p><h3>Here’s your tl;dr</h3><ol><li>Comparative analysis suggested that our app wasn’t actually that slow to begin with, but it “felt” slower.</li><li>Major bottlenecks were found in the JS side of our react-native app by simply adding logs, everywhere from MainActivity to first screen we rendered.</li><li>2 of those were ~500ms long each asynchronous tasks that were running way too late than they could’ve.</li><li>Moving them to run right at the very start of JS’s control flow and reusing “cached” promises helped us reorder the startup pipeline. This is more akin to preloading assets in a network waterfall on a website. The change was ~100 lines without impacting any business logic.</li><li>Math.random() was used to segment user sessions on device, for a reliable, safer and gradual rollout. The improvement were pushed as CodePush updates, without any native release.</li><li>Several issues in the telemetry were found by analyzing hourly data for a city at P90. High peaks were causing large P90s;</li><li>CodePush was skewing our startup times due to rerunning JS while native timers were still intact.</li><li>Push Notifications were messing up with our startup times as the “start” and “end” were happening when the notification was sent and when the user actually opened the app (sometimes days later) respectively.</li><li>We were recording startup telemetry even in the debug mode, adding noise to high percentile figures.</li><li>Perceived performance was improved by using animated splash screen. Argument can be made that this is more important if not as important, as you start seeing diminishing returns after a certain threshold.</li></ol><p>I also wanted to say that this wasn’t possible without the environment created by my peers. I learned to build things in a way we can measure, to release things behind experiments, to do cost-benefit analysis before jumping to code, to problem solve one step at a time, to be driven to excellence and to use first principles, only due to the tech culture created by the folks of udaan. If I wasn’t pushed in the right direction (shout out to <a href="https://www.linkedin.com/in/kaushikm21/">Kaushik Mukherjee</a> for the same), we might have blindly gotten into blackhole tasks without any meaningful improvements. So if you are in a position to lead others, make sure you create a safe place where your peers can work and learn by experimentation without fear of judgement and come up with tangible, measurable solutions that don’t require you to perform an engine transplant while the car is still running.</p><p>Finally I wanted to exclaim how awesome Web Development tooling is. You can just drop any URL to <a href="http://web.dev/measure">web.dev/measure</a> and come up with more solutions than you can count with your hands in matter of seconds. While React Native tooling may not be as robust as Web Development, it’s only improving thanks (<a href="https://flashlight.dev/">FlashLight</a> is the mobile Lighthouse-equivalent) to the <a href="https://www.youtube.com/watch?v=XO8O1iL4Rxg">efforts</a> by team behind Maestro and other community members. I don’t have any tool to share but I hope the caveats and general approaches I shared might help you to solve problems with your app, and maybe even build a tool for the same!</p><h3>Appendix</h3><p>Here’s the raw data for all the Gantt Charts above. Note the absolute values don’t matter much. The order and relative length of tasks is critical in identifying spots for optimization.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9c31571aff437e612041b69fb730f96/href">https://medium.com/media/b9c31571aff437e612041b69fb730f96/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7f791bfaa6753e602a75c5e4500e487/href">https://medium.com/media/d7f791bfaa6753e602a75c5e4500e487/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/815b679bcabe951b898e6ecb6d948fc6/href">https://medium.com/media/815b679bcabe951b898e6ecb6d948fc6/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/916cdba0d5ebedbd951aef28a53a430c/href">https://medium.com/media/916cdba0d5ebedbd951aef28a53a430c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=854f8a4850fd" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/reacting-to-change-tale-of-a-web-developer-improving-startup-performance-for-a-large-react-native-854f8a4850fd">Reacting to Change: Tale of a Web Developer Improving Startup Performance for a large React Native…</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deviations from the norm]]></title>
            <link>https://udaan.dev/deviations-from-the-norm-209aa36c4f14?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/209aa36c4f14</guid>
            <category><![CDATA[metrics-and-analytics]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[anomaly]]></category>
            <category><![CDATA[analysis-tools]]></category>
            <dc:creator><![CDATA[Kaushik Mukherjee]]></dc:creator>
            <pubDate>Sun, 13 Aug 2023 02:29:37 GMT</pubDate>
            <atom:updated>2023-08-13T05:44:15.336Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>An object at rest will stay at rest, and an object in motion will stay in motion with a constant velocity unless acted upon by an external force.<br></em>- Newton’s first law of motion</blockquote><p>An external stimulus is often necessary to change the status quo. Sometimes deviations occur without impetus, because of environmental triggers — intensified competition, political upheaval, a pandemic — they are all examples of such extraneous impulses. Organizations tend to depend heavily on “metrics” to make sense of these changes. However, the purist in me is not always fully convinced with the attributions. Attributions are sometimes incomplete and on occasion, incorrect or misleading. This coupled with our need to interpret metrics based on our biases can compound the problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w6mzbAxsnn-NKJzrfZRzcw.png" /><figcaption>Deviation over a timeline</figcaption></figure><p>For instance, while environmental awareness has increased in the past century, so has global warming. Does that mean a growth in environmental awareness increases the likelihood of global warming? Correlations tempt us to believe that actions lead to consequences (causation). Comprehensive evidence-based attributions are necessary to lead to sufficiently deterministic conclusions. Not convinced? Here’s another example: If you launch a new feature on your app that replaces an existing feature in a similar real estate (say the top section of the app), just by virtue of it being new, the feature will end up getting a lot more engagement. That does not imply that the feature is inherently better than the one it replaced. Over time, it is quite possible that the new feature’s engagement tapers off as the novelty wears off, and it becomes as good or worse than the feature it replaced. This phenomenon represents a <a href="https://builtin.com/data-science/regression-to-the-mean">regression towards the mean.</a></p><p>While it is easy to pontificate, it is in fact incredibly hard to accurately identify and attribute a root cause to a change. In this context, would it not be easier if a framework or tool could unravel some of these vagaries?</p><h3>An illustration</h3><p>Imagine this simple usecase of adding an item to the cart in the context of an e-commerce app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k3Djx0Yx_0UGwNEzpqLMKA.png" /><figcaption>Different paths to get to the cart</figcaption></figure><p>The illustration above considers a destination like the cart and the various paths through which one can get to it . In this case p1 is the busiest or the most popular path, followed by p2 and p3 hence p1&gt;p2&gt;p3. Furthermore, regardless of what the external circumstances were, the norm would continue to be p1&gt;p2&gt;p3. There could be of course changes in the ratios, but the overarching relationship would not change.</p><p>Now imagine a change was introduced in the system that deviated from this norm, for example, if the relationship p1&gt;p2&gt;p3 no longer held true or the ratios of p1:p2:p3 changed. Such deviations are usually very hard to identify let alone attribute unless they are obvious. The obvious ones would be removing the add to cart button from the search page or an outage on the product page. Maybe there was an additional path p4 that was introduced?</p><p>While there are <a href="https://www.predictiveanalyticstoday.com/top-anomaly-detection-software/">tools</a> available that can figure out the anomalous patterns with some degree of accuracy, the attribution as to why this occurred or what caused this change needs analysis that is almost always very time consuming.</p><h3>Further dissections</h3><p>Despite the advances in software technology, AI, networking, data engineering…we still do not have efficient mechanisms to make attributions conclusive. It’s not as though the benefits of proper attributions are not understood. Yet, we uneasily accept the output metrics, often relying on our intuition to tell us if the analysis done was sufficient. In my view, the reasons behind this could be the following:</p><p>1. Lack of proper coverage when it comes to instrumentations</p><p>2. Incomplete data governance</p><p>3. Limited analytical tools that focus on the problem of attributions</p><h3>A possible solution</h3><p>Given the problem statements above are fairly universal, even more so in an ecommerce organisation where there are many different influencing factors, both internal and external, udaan considered building a tool that attempted to reduce some of these ambiguities.</p><p>The way we went about doing it is to figure out event-based dependencies and have them both instrumented and observed. For instance, if an event like tapping a button led to adding to the cart, the source of that event generator would be captured. As a result, attributions started to become clearer. Later relationships were graphed and pictorially represented. The next logical step was to integrate all of this into a tool . We realised there wasn’t a tool which addressed all of these concerns that I had listed and we went about building something in house. We called it <a href="https://perceptinsight.com/"><strong>percept insight</strong></a><strong> </strong>.</p><p>I will perhaps discuss percept insight (pi) in a separate blog later as this isn’t about pi . What pi would help with though in this context was to show the variances in relationships as new features got introduced. We would see some features cannibalising existing ones while the net result remained unchanged. While this was no doubt interesting, what this also told us is that no specific feature alone can move the needle significantly. That it takes time for habits to build, for features to build acceptance and for other features to wear out. But we already knew all of that, didn’t we? pi also showed us exactly how those feature sets changed over time and allowed clear attributions to form, leading to more specific actions.</p><p>For example: Let us assume that we start seeing a sudden dip in orders placed from a certain geography. This could be because of a plethora of reasons<br>Was there a sudden change in pricing? (internal or external factor) <br>Are the warehouses in that region not operational? (external factor) <br>Did the tech infrastructure in that geography have issues? (internal factor)<br>Was there a new feature or workflow that got introduced recently? (internal factor)</p><p>There could be others as well….</p><p>pi is powered by <strong>netra, </strong>udaan’s observability platform. What is built on top of it are data structures that allow for specific attributions that lead to better explainability. How? That is a topic for later. <br>For now though I happy to have a little more clarity into what is actually causing the deviations from the norm.</p><h3>In conclusion</h3><p>In an environment where variances are large it becomes important to have leaf level events instrumented and observed. Also the<em> input metric definitions</em> should add up to <em>macro output metrics</em> such that deviations can be observed and attributed accurately. While it is good to conduct A/B experiments and such, there are inherent issues in looking at metrics in isolation. Also unless it is a long running A/B the attributions can be suspect due to recency biases. <br>Lastly, a tool or framework that can take care of both instrumentations , visualisation and detection of these deviations helps in ensuring proper explainability.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=209aa36c4f14" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/deviations-from-the-norm-209aa36c4f14">Deviations from the norm</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PerceptInsight — Intelligent Insights Platform | Release]]></title>
            <link>https://udaan.dev/perceptinsight-intelligent-insights-platform-release-23c057d7d0fe?source=rss----bd0ab722bd7b---4</link>
            <guid isPermaLink="false">https://medium.com/p/23c057d7d0fe</guid>
            <category><![CDATA[pi]]></category>
            <category><![CDATA[analytics-platforms]]></category>
            <category><![CDATA[insights]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Sai Sharan Tangeda]]></dc:creator>
            <pubDate>Wed, 14 Jun 2023 10:29:21 GMT</pubDate>
            <atom:updated>2023-06-14T12:31:19.794Z</atom:updated>
            <content:encoded><![CDATA[<h3>PerceptInsight — Intelligent Insights Platform | Release Note</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vku8cXSFcNFdHn_h-KRGig.png" /></figure><p>PerceptInsight (or <strong>pi</strong>) is an <strong>Intelligent Insights Platform</strong>, that provides real-time insights across various cuts and dimensions of your customer’s journey. <strong>pi</strong> enables you to not only understand your users, but allows you to take actions near real time basis insights and data.</p><h3>Why pi? What sets us apart?</h3><p>There are multiple other alternatives/competitors in this market. So why did we have to come-up with another product?, what sets <strong>pi</strong> apart?</p><ul><li><strong>Performance — pi </strong>is upto <strong>2x</strong> faster than the other competitors</li><li><strong>Data Availability — </strong>Unlike the existing competitors we are available across all major cloud providers and cloud regions in the world.</li><li><strong>Security</strong> — We take data security very seriously, and to that end we ensure that our enterprise customers have visibility into where we store the data. We take pride in our “Control Plane — Data Plane” architecture which allows our customers to have data in their cloud or on-premises there by avoiding any compliance risks.</li><li><strong>Affordability</strong> — We are very competitive in pricing and to that end we ensure that our pricing is affordable by all start-ups. Having fine-grained control over scale of events allow start-ups to leverage our <strong><em>pay-as-you-scale</em></strong> model.</li><li><strong>Intelligence — </strong>We are ahead of the curve in leverage cutting-edge technology to provide better and more seamless experience to our customers. To that end, our first milestone is beta release of <strong>“Interact” capability (Check more about it below).</strong></li></ul><h3>Vision</h3><p>Our vision is to create an affordable, easy to use, cutting edge, real-time analytics platform for everyone. We aim to truly bring the power of analytics to the decision makers and domain experts.</p><p>For data administrators, our constant effort is toward improving the governance of the analytics eco-system, providing simpler ways to instrument, manage and publish events from any application.</p><p>With the dawn of new AI era, lot of previously complex problems are now solvable with the LLMs, hence we are leaving no stone unturned to improve the analytics experience for our customers.</p><h3>Features</h3><h4>1. Insights</h4><p>Insights help our customers understand the trends over various dimensions and cuts.</p><p>Not only trends, but Insight also enable easy visualisation of data with powerful charting library.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fembed%2F7mHUTE9v-4k&amp;display_name=YouTube&amp;url=https%3A%2F%2Fpoe.shuhuigeng.workers.dev%3A443%2Fhttps%2Fwww.youtube.com%2Fwatch%3Fv%3D7mHUTE9v-4k&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=google" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/77cda235c9bda59e9c2f4b13d673a02c/href">https://medium.com/media/77cda235c9bda59e9c2f4b13d673a02c/href</a></iframe><h4><strong>2. Funnels</strong></h4><p>Funnels is the simplest way to understand the user conversion at each step. With integrated breakdown, you have visibility into user journey at different demographies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4EmPHF4fzMelbVi5oSk2w.png" /><figcaption>Funnels</figcaption></figure><h4>3. Cohorts</h4><p>Segment your users based on any property to build sophisticated user cohorts. Cohorts are evaluated in real-time based on the filter or condition thus keeping you up-to-date about the user behaviour.</p><p>Cohorts make experimentation on group of users very easy, with integration of cohorts into Insights. You can easily monitor the trends for a single cohort of users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L14Z0mvyirh6cQEguXgVMA.png" /><figcaption>cohort builder</figcaption></figure><h4>4. Dashboards</h4><p>Dashboards is designed to streamline collaboration and enable efficient access to critical data, making it the ultimate one-stop destination for all your reporting needs.</p><p>Dashboards will enable you to create stories about user behaviour and improve data driven business decisions.</p><h4>5. Interact (Private Preview)</h4><p>Interact is our cutting-edge and most recent capability that revolutionises the delivery of reports.</p><p>Interact enables real-time generation of Insights from Natural Language!. Yes, that’s right. All you have to do is ask the platform, and we get your reports.</p><p>We strongly believe that power of interacting with data using natural language will improve the visibility and decision making power for business and ops teams, and interact is the first step towards that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*wuqFpdvGt7rTvscbMN5uWA.png" /><figcaption>Example of Interact</figcaption></figure><p>Apart from the ones we have already released, we have more exciting features in the pipe that are dedicated to providing more seamless analytics experience for our customers.</p><h3>Check it out!</h3><p>Visit our website(<a href="https://perceptinsight.com">https://perceptinsight.com</a>) to know more about PI.</p><p>Try out our platform at <a href="https://demo.perceptinsight.com">https://demo.perceptinsight.com</a>.</p><p>Reach us at <em>sales@perceptinsight.com</em> for more information or free demo.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23c057d7d0fe" width="1" height="1" alt=""><hr><p><a href="https://udaan.dev/perceptinsight-intelligent-insights-platform-release-23c057d7d0fe">PerceptInsight — Intelligent Insights Platform | Release</a> was originally published in <a href="https://udaan.dev">engineering-udaan</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>