<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Devansh Gupta on Medium]]></title>
        <description><![CDATA[Stories by Devansh Gupta on Medium]]></description>
        <link>https://medium.com/@devansh.gupta?source=rss-339b56fa6990------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1l-cF5zraZNxkK7E</url>
            <title>Stories by Devansh Gupta on Medium</title>
            <link>https://medium.com/@devansh.gupta?source=rss-339b56fa6990------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:42:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devansh.gupta/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[How It Feels to Learn AI in 2026]]></title>
            <link>https://medium.com/@devansh.gupta/how-it-feels-to-learn-ai-in-2026-17f8e39391e7?source=rss-339b56fa6990------2</link>
            <guid isPermaLink="false">https://medium.com/p/17f8e39391e7</guid>
            <dc:creator><![CDATA[Devansh Gupta]]></dc:creator>
            <pubDate>Sat, 01 Aug 2026 10:30:00 GMT</pubDate>
            <atom:updated>2026-08-01T10:30:00.296Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Inspired by </em><a href="https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f"><em>“How it feels to learn JavaScript in 2016” by Jose Aguinaga</em></a><em>. No language models were harmed in the writing of this article — though several were deprecated.</em></p><p><em>This piece is an opinion, and like any AI stack, it shouldn’t be taken too seriously — it’ll be outdated by the time you finish reading it anyway.</em></p><p>Hey, I got this new project, but to be honest I haven’t touched AI tools in a few years and I’ve heard the landscape changed a bit. You’re the most up-to-date person around here, right?</p><p><em>— The actual term is AI Engineer, but yeah, I’m your guy. I live and breathe this stuff.</em></p><p>Cool. I just need something that reads a support ticket and drafts a reply. I was thinking I’d just use ChatGPT for that.</p><p><em>— Oh, no one says “ChatGPT” anymore, that’s so 2023. You mean an LLM call. And you wouldn’t just “use” one, you’d pick a model.</em></p><p>OK, which model?</p><p><em>— Depends. For quick stuff you’d reach for a small fast model, but for anything with real reasoning you want a frontier model.</em></p><p>Sure, whichever is smartest then.</p><p><em>— Smartest is relative. Are we talking benchmarks, vibes, or price-per-token?</em></p><p>I… don’t know what that means.</p><p><em>— No one does at first. Look, you’ve got closed models and open-weight models. Closed ones you call through an API. Open ones you can self-host, if you enjoy pain.</em></p><p>I’ll take the API one.</p><p><em>— Good instinct. So you’ll need an API key, and you’ll want to pick a model version — not just the model family, the actual snapshot, because they update those.</em></p><p>Wait, the same model changes over time?</p><p><em>— Constantly. That’s why serious teams pin a specific version string instead of “latest,” or your whole app changes behavior overnight without warning.</em></p><p>That seems like a design flaw.</p><p><em>— It’s a feature, actually — no one asked you. Anyway, once you’ve got your model, you’ll want to give it structure. So you’ll write a system prompt.</em></p><p>Like… instructions?</p><p><em>— Right, but you don’t just write instructions, you engineer them. That’s prompt engineering. You’ll want examples, maybe some XML tags to organize it, and definitely a section telling it not to hallucinate.</em></p><p>Can you just tell it not to hallucinate and it stops?</p><p><em>— Sort of? Mostly you reduce it. For anything factual you’ll want to hook up retrieval so it’s not just guessing from memory.</em></p><p>Retrieval?</p><p><em>— RAG. Retrieval-Augmented Generation. You embed your documents into vectors, stick them in a vector database, and pull the relevant chunks in at query time.</em></p><p>I have documents. I don’t have “vectors.”</p><p><em>— You’ll need an embedding model for that. Different from your chat model, by the way. Don’t mix those up.</em></p><p>So now I have two models.</p><p><em>— Could be three if you want a reranker in there too.</em></p><p>OK, so I set up the vector database and —</p><p><em>— Oh, actually, don’t bother. Nobody really does RAG anymore, long context killed it.</em></p><p>You just spent five minutes explaining it to me.</p><p><em>— That was old-school RAG. Context windows got so big now you can just dump the whole knowledge base straight into the prompt. Why retrieve chunks when you can retrieve everything?</em></p><p>So I don’t need the vector database after all.</p><p><em>— You still kind of do, honestly, once you’re past a few million tokens, or if you want it fast and cheap instead of fast and expensive. Also, for anything relational — “who reports to whom,” that kind of thing — you’ll actually want a knowledge graph instead of flat chunks anyway.</em></p><p>A knowledge graph.</p><p><em>— Entities and relationships instead of text blobs. You build it, or you extract it automatically with — guess what — another model.</em></p><p>Another model.</p><p><em>— Another model. Anyway, once your context strategy is sorted, however you land on it, you’ll want your model to actually </em><strong><em>do</em></strong><em> things, not just talk. That’s tool use, or function calling depending who you ask.</em></p><p>Do things like what?</p><p><em>— Look something up, send an email, query a database. You define a schema, the model decides when to call it, you run the code, feed the result back in.</em></p><p>OK, so I write a schema for every tool I want it to use.</p><p><em>— You could, but honestly nobody writes their own tool integrations from scratch anymore, that’s what MCP is for.</em></p><p>MCP.</p><p><em>— Model Context Protocol. It’s a standard way for models to talk to tools and data sources — instead of hand-rolling a function for Slack and a function for your database and a function for email, you just plug in an MCP server for each and your model can use all of them.</em></p><p>So it’s like an API for connecting APIs to the AI.</p><p><em>— Don’t say it like that, but yes. There’s a whole registry of them now — servers for GitHub, servers for Google Drive, servers for your calendar. You just connect one and the model figures out when to call it.</em></p><p>That sounds like it should have existed from day one.</p><p><em>— It didn’t, but it does now, so.</em></p><p>Anyway, that sounds like I’m building the actual application myself and the AI is just… deciding when to run my code.</p><p><em>— Now you’re getting it. Although if you don’t want to wire all that up yourself, you could use an agent framework instead.</em></p><p>An agent.</p><p><em>— Right, an agent is a model that can plan, call tools, and loop until it thinks it’s done. Very exciting in 2026. Slightly terrifying in production.</em></p><p>Is there a specific tool for that or —</p><p><em>— Oh, dozens. Some people build agents with a lightweight framework, some people go heavier with orchestration graphs, some people just write a while-loop and call it an “agentic system” in the pitch deck.</em></p><p>I just wanted to reply to support tickets.</p><p><em>— Sure, sure, almost there. Actually, one more thing — you’ll want to give your agent skills.</em></p><p>I thought that’s what the tools were for.</p><p><em>— Different thing. A skill is more like a packaged bundle of instructions and reference material for doing a specific task well — how your company formats a refund email, say — that the model loads only when it’s relevant, instead of stuffing it all into the system prompt permanently.</em></p><p>So it’s a prompt, inside a folder, that the other prompt decides to read.</p><p><em>— Sort of, don’t say it like that either. Anyway, now you’ve got your model, your context strategy, your knowledge graph, your MCP servers, your tools, your skills, your agent loop — now you need to know if any of it actually works, so you’ll want evals.</em></p><p>Evals?</p><blockquote>— Tests, but for vibes. You run a set of inputs, score the outputs, usually with another model grading the first model.</blockquote><p>You use an AI to check if the AI is good.</p><p><em>— It’s called LLM-as-a-judge. Don’t overthink it. And before any of this you’ll have picked your model off a leaderboard, based on benchmarks.</em></p><p>Benchmarks?</p><p><em>— Standardized tests everyone runs their model against, so you can compare them. Coding benchmarks, math benchmarks, agentic-task benchmarks. Every lab tops a different one, so it evens out to meaningless, but you still have to check them.</em></p><p>Why check them if they’re meaningless?</p><p><em>— Because if you don’t, and someone asks “why’d you pick this model,” “vibes” is not an acceptable answer in a board meeting.</em></p><p><em>Anyway — and depending on your traffic, you’ll probably want to cache repeated calls, and definitely put a guardrails layer in front so people can’t jailbreak your support bot into writing poetry about your CEO.</em></p><p>People do that?</p><p><em>— People absolutely do that. So you’ll want input filtering, output filtering, maybe a moderation model as another layer.</em></p><p>Another model.</p><p><em>— Another model. And once it’s live, you’ll want observability — token usage, latency, cost per request — because these calls aren’t free and they add up fast.</em></p><p>How fast?</p><p><em>— Fast enough that “just call the biggest model for everything” is not a pricing strategy, it’s a cry for help. You’ll want model routing — small model for easy stuff, big model only when needed.</em></p><p>So now there’s a model that decides which model to use.</p><p><em>— Now you’re really getting it.</em></p><p>What am I watching for, once all this is running?</p><p><em>— The morning you find out what four thousand dollars of apology emails looks like, because a retry loop ran all night and nobody told it to stop.<br>Four thousand dollars.</em></p><p>Four thousand dollars??</p><p><em>— Yeah. It was very sorry. Two hundred times a minute. To the same customer.</em></p><p>Does anyone this actually work?</p><p><em>— Yeah, no none of this is stable. And by the way, whatever we just described will be “the old way” in about four months, so don’t get too attached.</em></p><p>…I just wanted to reply to support tickets.</p><p><em>— And you will! Eventually! Welcome to AI in 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17f8e39391e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How an Architectural Change Saved Thousands of Players from Rage-Quitting]]></title>
            <link>https://medium.com/@devansh.gupta/how-an-architectural-change-saved-thousands-of-players-from-rage-quitting-74ba806ae70e?source=rss-339b56fa6990------2</link>
            <guid isPermaLink="false">https://medium.com/p/74ba806ae70e</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Devansh Gupta]]></dc:creator>
            <pubDate>Wed, 10 Dec 2025 11:58:39 GMT</pubDate>
            <atom:updated>2025-12-10T12:01:45.090Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqO4bmRbZo2RP3yHYnR4BQ.png" /></figure><blockquote><em>Building India’s </em><strong>highest-grossing game</strong><em> comes with unique challenges. Here’s how we solved our biggest one.</em></blockquote><blockquote><strong>Want to build the future of cricket gaming with us?</strong> Drop us a line at <a href="mailto:careers@hitwicket.com">talent@hitwicket.com</a></blockquote><h3>The Problem: Almost 5% of Games Were Breaking</h3><p>In 2023, we launched PvP mode at Hitwicket — our SuperPower-infused cricket game — and players went crazy for it. Head-to-head battles, strategic depth, real-time competition. Our Youth Championship built on PvP became wildly successful.</p><p>But underneath the excitement, we had a ticking time bomb.</p><p><strong>One in twenty games crashed/stalled/disconnected!</strong></p><p>Games hung mid-match — players staring at frozen screens, unable to select anything. Reconnections failed catastrophically. Clients and servers disagreed on the score — your screen shows 36/2 while the server insists you’re 30/3. Players complained, wrote long discord posts, raised tickets and eventually lost trust &amp; quit. We were hemorrhaging users to technical issues.</p><p>We had to fix this, or watch thousands of players walk away.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*el_AcenLsPNeAG4YqTInTg.png" /></figure><h3>The Mission: Zero Tolerance for Failures</h3><p>We set three non-negotiable goals:</p><ul><li><strong>No hanging games.</strong> Users must always be able to proceed.</li><li><strong>Bulletproof reconnections.</strong> Disconnect and rejoin without any impact on gameplay. Critical since most of our users are on Mobile networks.</li><li><strong>Instant bug reproduction.</strong> If we can’t reproduce it, we can’t fix it.</li></ul><h3>The Old System: A House of Cards</h3><p>Our original architecture seemed reasonable on paper:</p><ul><li>Client and server each maintain game state</li><li>Client sends event → updates its own state immediately</li><li>Server processes and updates its state → forwards to opponent</li><li>Opponent receives event → updates state</li></ul><p><strong>The fatal flaws:</strong></p><ul><li><strong>Optimistic updates gone wrong.</strong> Clients updated state immediately without waiting for server confirmation. If the server didn’t process the event (validation failed, network hiccup, timing issue), the client and server diverged permanently. Game over.</li><li><strong>Spaghetti code.</strong> State updates and animation rendering were inseparably tangled. You couldn’t update the score without triggering the animation, and vice versa. This tight coupling made the codebase brittle and nearly impossible to test.</li><li><strong>The reconnection nightmare.</strong> When a player disconnected and rejoined, we’d send the entire game state from the server. Sounds fine, right? Except if there was an update happening <em>at that moment</em>, the reconnecting client would receive stale state. Instant desync. Corrupted game. Angry users.</li><li><strong>Debugging was impossible.</strong> Race conditions, network timing issues, state coupling — reproducing a bug report was like finding a needle in a haystack while blindfolded. Players would report issues, but we had no way to reconstruct what actually happened. Bugs piled up.</li></ul><blockquote><strong>We weren’t just fixing bugs. We were constantly fighting the architecture itself.</strong></blockquote><h3>Event Sourcing: The Game Changer</h3><p>We needed a paradigm shift. Enter Event Sourcing — a battle-tested pattern that’s been used in distributed systems for decades.</p><p><strong>The core insight:</strong> Stop syncing <em>state</em>. Start syncing <em>history</em>.</p><p>Don’t tell clients “The Score is 45/3 in Over 8.” Tell them “Ball 1: Six. Ball 2: Wicket. Ball 3: Dot Ball…”</p><p>Think chess notation. You don’t send board positions — you send the moves: “1. e4 e5 2. Nf3…” Given the moves, you can always reconstruct the board.</p><p><strong>The reason?</strong> Given the same events in the same order, you ALWAYS arrive at the same state. Not “probably.” Not “usually.” <em>Always</em>.</p><h3>What Changed</h3><p><strong>Reconnection:</strong> Instead of fetching full state (dangerous during active play), we simply ask: “Give me all events after event #X.” No race conditions. No missed updates. No possibility of desync. Just append the new events and process them in order.</p><p><strong>Client architecture</strong></p><p>We separated concerns ruthlessly. State update logic lives alone. Rendering lives alone. They only talk through a clean interface. And crucially — <em>nothing happens without server confirmation</em>.</p><pre>OnServerAcknowlegement(event):<br>    // FIRST UPDATE STATE<br>    UpdateStateBasedOnEvent(currentState, event)<br>    // THEN RENDER THE GAME<br>    RenderGame(currentState)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N0J0lk0ZSbeyx8AF2FqcaA.png" /></figure><h3>Every Problem, Solved</h3><p><strong>Optimistic updates causing desyncs?</strong> Gone. Clients wait for server acknowledgement before updating anything.</p><p><strong>Tangled state and rendering code?</strong> Decoupled completely. We can now test state logic without touching Unity animations and vice versa.</p><p><strong>Client-server mismatches?</strong> Mathematically impossible. Same events = same state. Period.</p><p><strong>Reconnection corruption?</strong> Solved. Send only the events that happened since disconnect. Process in order. Perfect sync guaranteed.</p><p><strong>Debugging nightmares?</strong> Now trivial. Bug reported at Ball 47? Load events 1–47 from the database, replay locally, reproduce instantly. We went from hours of guesswork to minutes of systematic debugging.</p><p><strong>The invisible benefit:</strong> Our QA process transformed. We could now write tests that verify entire match sequences. We could simulate edge cases by crafting specific event sequences. We could replay production issues in development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73aLYmcvpw0_F-P-89DS2g.png" /></figure><h3>The Results: 50x Improvement</h3><p>Corrupted games dropped from <strong>5%</strong> to <strong>under 0.1%</strong> — a 50x reduction. And we’re still improving.</p><p>Thousands of players who would’ve rage-quit stayed engaged. Player reports about technical issues dropped off a cliff. Confidence in PvP mode soared. Our Youth Championship could scale without the constant dread of technical meltdowns in the middle of the Finals.</p><h3>Bonus: Two Features We Got for Free</h3><p>Once you’re processing events sequentially, interesting doors open that have nothing to do with your original problem.</p><p><strong>Hitwicket TV (live spectating):</strong> Want to watch someone else’s match live? Just fetch their event stream and render it. Disable the input controls. Done. Live streaming became a natural extension of our architecture, not a separate feature requiring months of development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*93SUATM-bbeyKXJ7HOfesQ.png" /></figure><p><strong>Match Replay &amp; Highlights:</strong> Want to relive Ball 23 again when your star batsman hit a six? Load events 1–23, render the state, animate. Instant time travel through matches. Want highlights? Jump to specific ball numbers where wickets fell or sixes were hit. The event log gives you a perfect recording of every match ever played.</p><p>We built these features in <em>days</em>, not months. That’s the power of getting the architecture right.</p><h3>The Lesson: Architecture Compounds</h3><p>Great architecture doesn’t just solve your immediate problem — it unlocks capabilities you didn’t even plan for.</p><p>Event Sourcing gave us stability (50x error reduction), debuggability (instant bug reproduction), and two major player-facing features as side benefits. That’s the mark of solid foundational design.</p><p>The upfront cost? About three months of careful refactoring and a client-side overhaul plus a backend event storage system. The payoff? Incalculable. We can now ship PvP features with confidence, knowing the foundation won’t crumble.</p><p><strong>The broader principle:</strong> When you’re scaling to millions of users, technical debt isn’t just inconvenient — it’s existential. The right architecture isn’t a luxury. It’s survival.</p><p>Stay tuned for Part 2 where we’ll pull back the curtain on the real beast — the intricate technical architecture, thorny design decisions, and hard-won lessons from implementing Event Sourcing at scale for millions of users.</p><p><strong>Building something ambitious?</strong> We’re hiring game developers &amp; engineers who love hard problems. <a href="mailto:careers@hitwicket.com">talent@hitwicket.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74ba806ae70e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Swiggy Delivery Challenge (Part Two)]]></title>
            <link>https://medium.com/swiggy-bytes/the-swiggy-delivery-challenge-part-two-f095930816e3?source=rss-339b56fa6990------2</link>
            <guid isPermaLink="false">https://medium.com/p/f095930816e3</guid>
            <category><![CDATA[swiggy]]></category>
            <category><![CDATA[swiggy-delivery]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[swiggy-engineering]]></category>
            <dc:creator><![CDATA[Devansh Gupta]]></dc:creator>
            <pubDate>Wed, 08 May 2019 05:52:12 GMT</pubDate>
            <atom:updated>2019-05-09T14:10:18.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*NtEZ2jJ4Tucs55j3A_Ny-A.gif" /></figure><p><em>Some more of the complexities involved in becoming the number one Delivery business in India!</em></p><p>In <a href="https://bytes.swiggy.com/the-swiggy-delivery-challenge-part-one-6a2abb4f82f6">Part One</a>, you read what happens behind the scenes when a customer places an order on Swiggy. Now, we’ll take it a step further: what are the ways in which we can optimize the delivery? <em>More importantly, what are the challenges in doing so?</em></p><p>At the risk of sounding cavalier, food delivery is probably the hardest challenge in the Logistics space: a typical order is expected to be <em>assigned </em>to a Delivery Executive within minutes and delivered within an hour <em>at the most</em> (much less usually). Furthermore, the system should be able to respond to abrupt swings in demand and sudden dips in logged-in Delivery Executives and <em>still</em> adhere to the promise made to the customer.</p><p>The profitability and sustainability of Swiggy as a delivery platform depends largely on its efficiency in delivering orders <em>and</em> maintaining good customer experience. Building a robust system to optimize for both, while still being able to respond to <em>shocks</em> (rains, sudden logouts, sudden increase in demand, traffic congestion, etc.) makes food delivery assignment an extremely complex problem to solve.</p><p>For example, given the expectations of speedy assignment and delivery, simply assigning the closest Delivery Executive, while good customer experience for that order, is usually bad on a global scale, driving up delivery times and decreasing efficiency <em>overall </em>for the rest of the orders.</p><p>While there are many approaches to help solve these problems, I would like to describe three strategies Swiggy is using to optimize the Delivery times and costs</p><ol><li><strong>Just In Time Assignment (JIT):</strong> A way to minimize the time spent by the Delivery Executive at the restaurant waiting for the food to be prepared.</li><li><strong>Next Order Assignment (NOA):</strong> A way to minimize the time spent by the Delivery Executive waiting to be assigned to the next order and increasing the potential pool of Executives considered for an order.</li><li><strong>Batching:</strong> A way to increase the efficiency of Delivery Executives by delivering more than one order at a time.</li></ol><h3><strong>Just In Time Assignment (JIT)</strong></h3><p>As soon as an order is placed on Swiggy, two wheels are set into motion: on one side, the restaurant starts preparing an order and on the other side, the system searches for nearby Delivery Executives and assigns them so they can head to the restaurant and pick up the order.</p><p>But here’s the catch: food preparation usually takes much longer than it does for the Delivery Executive to reach the restaurant. For example, if food will be prepared within 15 minutes, and we find a Delivery Executive who will reach the restaurant within 5 minutes, this means the Executive ends up waiting at the restaurant for 10 minutes.</p><p>Why does this matter? Those are 10 minutes spent by the Executive waiting at the restaurant instead of being out there delivering an order. Over the course of the day, these small chunks add up, reducing the number of orders we can do per day per Delivery Executive.</p><p>Now, the naive approach would be to simply delay the assignment of an order by roughly the time taken to prepare the order minus the time taken by the Delivery Executive to reach the restaurant (aka <em>First Mile Time</em>).</p><blockquote>Assignment Delay = Estimated Prep Time - Avg. First Mile Time</blockquote><p>Like most simplistic approaches, this does help us in reducing the time spent by the Delivery Executive on the whole, but this approach is not nuanced enough. As we saw in the previous post, averages don’t work out well for us.</p><p>If the first mile time is shorter than average, then we have lost potential for optimization. If it is long er than expected, we have delayed the customers order. Furthermore, what if after delaying the order for 10 minutes in the above example, there are no eligible Delivery Executive to fulfill this order? Then the order gets delayed, impacting customer experience.</p><p>A second approach would be to go ahead and do assignment as normal for an order, but only dispatch the Delivery Executive <em>just in time</em>. Basically, earmark the Executive for this order (so he is no longer eligible to do other orders), but only dispatch him when we know he will arrive just in time to pick up the order.</p><p>While this approach will help us in cutting down the time spent waiting by the Delivery Executive as accurately as possible, it doesn’t <em>really</em> help us accept more orders. This is because the earmarked Executive is <em>de facto </em>assigned to the order, just that they don’t know it yet.</p><p>So how might this actually help us?</p><p>Consider this scenario. Say there are two eligible Delivery Executives A &amp; B for an order O1 that just came in. Executive A is preferred &amp; dispatched for Order O1 over Executive 2 (due to proximity). Now, a minute later, another order O2 comes in for which Executive B is very far. Assigning Executive A for O2 and and Executive B for order O1 for would have been much better, if he was not already dispatched for O1. This results in poor experience and delays for order O2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*Im82eLh2D_379kSoaTZ28w.gif" /></figure><p>In the above scenario, if we had just earmarked Executive A for O1 instead of dispatching him, we could have simply <em>swapped</em> the assignments around when O2 came in. This would allow us to deliver both orders efficiently rather than delivering one well and the other poorly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*v1VRS3oNL0zzz5NLDAVMxg.gif" /></figure><p>While this sounds simple, it’s a huge challenge at Swiggy’s scale where you have thousands of outstanding orders and Delivery Executive.</p><blockquote>Remember, unlike other e-commerce companies which can take days to optimize their routes, Swiggy has at best a few minutes. Correctly choosing which assignments to swap around can have a huge impact on our efficiency numbers.</blockquote><p>Furthermore, doing JIT has more challenges:</p><ol><li>What if, after delaying the dispatch, the Delivery Executive decides to reject the order? The order will get delayed since we need to find another Executive as soon as possible.</li><li>What if we overestimate the preparation time required by the restaurant?The dispatch gets delayed for a longer time than required which leads to degraded food quality because the order is simply sitting out, waiting to be picked up.</li><li>What if we underestimate the time required for the Executive to reach the restaurant? Again, the order might get delayed and food quality will suffer. This scenario will happen more often if the Delivery Executive is moving.</li></ol><h3><strong>Next Order Assignment (NOA)</strong></h3><p>If we consider Delivery Executives who are almost done delivering their current orders, we will increase the pool of eligible Executives which in turn increases our efficiency. This is what Next Order Assignment is all about.</p><p>For example, if a Delivery Executive will deliver order O1 within the next 10 minutes and is 5 minutes away from the restaurant preparing order O2 (where estimated preparation time for order O2 is 20 minutes), the Executive can clearly finish delivering O1 and then pick up O2 in time.</p><p>Not considering such “busy” Executives significantly reduces potential candidates, leading to sub-optimal assignments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*V2dYk_bqd-9WaA_HbciNhw.gif" /></figure><p>What’s more - selecting busy Executives <em>inherently</em> does JIT assignment by reducing the time spent by Delivery Executive at the Restaurant (since he will require some time to get free from the current delivery, and at the same time restaurant is preparing order).</p><p>However, while this is a great way to increase the pool of eligible Executives and at the same time reduce the wait times at the Restaurant, it largely depends on the accuracy of the prediction for when the Executive will get free. Because, if the Delivery Executive takes longer than what was estimated to get free, then the order is unacceptably delayed.</p><h3>Batching</h3><p>Batching is a simple concept — if a restaurant gets two orders at the same time from two customers located nearby, it makes perfect sense to dispatch a single Delivery Executive to deliver both orders.</p><p>This helps us to significantly increase the number of orders we can deliver with a fixed set of Executives (in fact, batching all orders will <em>double the capacity of the entire delivery fleet</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*7LbpyavVqyWG8gFvFg-iOw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*DzaIV4kERWGwGOUkNCrxSw.gif" /></figure><p>Before we even get into why batching is hard to do (how hard you ask? So hard that it’s <em>NP-Hard</em>), we need to decide what it means for two orders to be <em>batchable</em>.</p><blockquote>For two (or more) orders to be batchable, we need to calculate the new Delivery times of all the orders in the Batch and make sure they still adhere to the promise made to the customer.</blockquote><p>But if the promise is made based on time taken to prepare the food and time taken to go from the restaurant to the customer’s location, which is the <em>minimum time</em> required for an order to be delivered, then no order will be batchable in the first place (since batching an order will increase the time required to deliver the order).</p><p>However, increasing the promised delivery time (by a fixed buffer time) <em>for all orders </em>is not correct either, because we have seen that incorrectly increasing promised delivery times usually leads to fewer people ordering.</p><p>What we need is a way to detect which orders could be potentially batched (with an existing or future order) and only for those orders should we change the promised delivery time.</p><p>However, detecting which orders might be batched is tricky. <em>Batchability</em> relies on a few factors: <strong>concurrent orders</strong> and <strong>proximity of the customers</strong>. Basically, it’s those orders that are:</p><ol><li>Placed <em>within minutes</em> of each other by customers who are</li><li>Located <em>close</em> to each other and</li><li>To the <em>same or nearby</em> restaurants.</li></ol><p>But how can we define “within minutes.” Should it be 5 minutes or 10 minutes? Increasing this window means more potential for batching orders together. However, increasing the window also means that the first order ends up waiting even longer to be picked up, as the Executive needs to wait for the other orders to be prepared too.</p><p>Similarly, while increasing the distance between customers increases the amount of batching we can do, but it also results in poor customer experience because there is a higher risk of not delivering orders within the promised time.</p><p>Coming up with the <em>Goldilocks value</em> for batching, one that allows us to do enough batching but does not degrade customer experience in the process, is a very challenging problem. Especially because this value would vary with time (pre-dinner vs dinner) and space (dense areas vs sparse suburbs).</p><p>Furthermore, after we’ve decided what batchable orders mean, actually <em>finding</em> which orders can be batched together is extremely challenging too.</p><p>Simply iterating over all possible orders to see if they can be batched has exponential complexity, since we need to test all possible combinations of orders along with all <em>possible sequences of delivery</em> (for example, delivering order O1 before O2 may meet the promised delivery time for both orders, but delivering O2 first might violate O1’s promised delivery time).</p><p>The well-versed reader might realize this actually is a version of the <a href="https://en.wikipedia.org/wiki/Vehicle_routing_problem">Vehicle Routing Problem</a>, with the additional complexity of not just having one driver, but multiple. This problem has no known efficient solutions and most known approximations are also too time consuming to run (again remember, Swiggy has at best a few minutes).</p><p>Clever heuristics like choosing orders from nearby restaurants, difference between preparation times and calculating the proximity between customers can help to winnow down the set of possibilities, helping us correctly maximize batching while not requiring more than a few minutes to run our algorithms.</p><h3>Summary</h3><p>Not only is food delivery assignment a <em>theoretically</em> hard problem to solve, given the time constraints and abrupt changes in conditions it becomes an exceptionally complex problem to solve practically.</p><p>Furthermore, since <em>large scale on-demand food delivery</em> is such a new concept worldwide, there are no tried and tested solutions for this, requiring us to come up with innovative new solutions for the challenges we face.</p><p>Lastly, cracking the Food Delivery Challenge, not only requires us to come up with creative solutions to hard problems, but also requires us to get an in-depth understanding of how the entire ecosystem behaves in <em>the real world</em>, to ensure we make the right trade-offs.</p><blockquote>I’m Devansh from the Delivery team at Swiggy. If you enjoyed learning about this and would like to take a crack at solving some of the problems mentioned above, head to <a href="https://www.google.com/url?q=https://careers.swiggy.com&amp;sa=D&amp;source=hangouts&amp;ust=1538032601198000&amp;usg=AFQjCNFa2s5Zbi__HC--tn0Kie1ovprvyA">https://careers.swiggy.com</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f095930816e3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swiggy-bytes/the-swiggy-delivery-challenge-part-two-f095930816e3">The Swiggy Delivery Challenge (Part Two)</a> was originally published in <a href="https://medium.com/swiggy-bytes">Swiggy Bytes — Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Swiggy Delivery Challenge (Part One)]]></title>
            <link>https://medium.com/swiggy-bytes/the-swiggy-delivery-challenge-part-one-6a2abb4f82f6?source=rss-339b56fa6990------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a2abb4f82f6</guid>
            <category><![CDATA[swiggy-engineering]]></category>
            <category><![CDATA[swiggy-delivery]]></category>
            <category><![CDATA[swiggy-tech]]></category>
            <category><![CDATA[swiggy]]></category>
            <category><![CDATA[goldilocks-value]]></category>
            <dc:creator><![CDATA[Devansh Gupta]]></dc:creator>
            <pubDate>Thu, 27 Sep 2018 14:24:54 GMT</pubDate>
            <atom:updated>2019-06-02T18:14:49.603Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fE3JkGyzhWXlXApVnShDtw.gif" /></figure><p><em>The complexities involved in becoming the number one Delivery business in India!</em></p><p>While there are a lot of interesting problems (technical and non-technical) associated with becoming a top notch delivery app, the ones I want to describe here are to do with the challenges associated with building the Delivery side of the product.</p><h3>The Restaurant Listing and Delivery Time Promise</h3><blockquote>The one thing that most people don’t realize is that the role of delivery doesn’t begin when someone places the order, but as soon as they open the app.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v35_5EFq4ZQ-R4OK5mJ9Xg.png" /></figure><p>When a customer opens the app, the first call is made to the Delivery system to figure out:</p><ol><li>The restaurants that are actually serviceable to the customer, which means those from which a delivery is possible within some stipulated time (say, at most 60 minutes).</li><li>The expected delivery time of an order from a potential restaurant.</li></ol><p>An astute reader can already see the massive challenge.</p><p>First of all, how do we find <em>serviceable </em>restaurants? It’s the set of those restaurants where a customer could place an order and have it delivered within the maximum delivery time.</p><p>But how can we calculate that? We roughly show 300–500 restaurants to each customer and consider thousands more. If it isn’t shown within half a second, the customer will just leave the app.</p><p>Is it feasible to find all the restaurants such that a Delivery Executive can reach there, pick up the order and deliver it to the customer? To even begin to do that, we need to calculate:</p><ol><li><strong>Assignment Delay: </strong>How long before we can find a Delivery Executive who can fulfill this order<em>?</em></li><li><strong>First Mile: </strong>How long before they arrive at the Restaurant?</li><li><strong>Prep Time:</strong> How much time is required for the Restaurant to prepare the food?</li><li><strong>Last Mile:</strong> How much time is required for the Delivery Executive to reach the customer from the Restaurant?</li></ol><h3><em>The Central Delivery Equation</em></h3><p>Combining the components above, we arrive at the Delivery Time Equation:</p><blockquote><strong>Delivery Time = Max (Assignment Delay + First Mile Time, Prep Time) + Last Mile Time</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F7kNPFivN2PY4UJ6jrLZrQ.gif" /><figcaption>The Delivery Time Components</figcaption></figure><p>A quick note about the formula: Since the assignment delay and first mile happen in parallel with the restaurant’s food preparation, we take the maximum of the two times.</p><p>If we show too few, the customer will not place an order since his favourite restaurant may be unserviceable. At the same time, if we take too long to show the list of restaurants, they will leave the app.</p><p>If we show too low a delivery time and we don’t deliver within it, it leads to bad customer experience. If we show too high a delivery time, the customer may not order to begin with.</p><blockquote><strong>Everything in Delivery is about finding the </strong><a href="https://en.wikipedia.org/wiki/Goldilocks_principle"><strong>Goldilocks value</strong></a><strong>.</strong></blockquote><blockquote>It’s about finding just the right time to ensure delivery, but not too high to discourage the customer from placing an order.</blockquote><blockquote>It’s also about providing ample choice of restaurants to the customer, but just enough so we can calculate their delivery times as quickly as possible.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuWwjqBeYZOScwMi4PgkuQ.png" /></figure><h3>Estimating Last Mile Time</h3><p>Let’s start with the “simplest” of the problems: <em>Last Mile Time.</em></p><p>Last Mile is the time taken by the Delivery Executive from the Restaurant to the Customer’s location. Well, you might say, <em>“Can’t you simply use Google Maps?”</em></p><p>Well <em>no</em>, not at our scale. And here’s why.</p><ol><li>Google Maps is just too slow<em> </em>for the number of combinations we need to calculate.</li><li>Google Maps is prohibitively expensive.</li><li>Google Maps doesn’t accurately predict travel times for people on two-wheelers (which most of our Delivery Executives use).</li><li>Google Maps doesn’t predict how long it will take for the Delivery Executive to go from outside the society gates to actually reaching your door and handing over the package (<em>AKA the last </em>last <em>mile). </em>While this might not make a big difference for other kinds of deliveries, an additional 5 to 10 minutes in food delivery can significantly hamper customer experience.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o5Vxiff_XI_6goqGHIDypg.gif" /><figcaption>Predicting Last Mile Time</figcaption></figure><p>So short of building our own Maps that scale to our needs, how do we solve this? Well it requires:</p><ol><li><strong>Leveraging historical data:</strong> Swiggy, till date, has delivered millions of orders, and has a lot of data around how long a delivery can take on a two-wheeler from a particular Restaurant to a Customer.</li><li><strong>Enhancing historical data with real time signals:</strong> Thanks to Swiggy’s unparalleled hyperlocal density, we can leverage the travel time data of Delivery Executives currently doing orders to make predictions.</li></ol><h3>Estimating Preparation Time</h3><p>Another big chunk of the Delivery Time is the time a restaurant takes to prepare the food.</p><p>Estimating Preparation Time when the customer first opens the app is a really tricky concept, given that we don’t even know what or how much they might potentially order!</p><p>The <em>Prep Time</em> is driven by various factors:</p><ol><li><strong>Type of item:</strong> It takes much longer to make a pizza than it does to put a scoop of ice cream into a cup.</li><li><strong>Number of items:</strong> It takes longer to prepare ten Kathi Kabab rolls than just one.</li><li><strong>Load at the Restaurant:</strong> It takes longer to prepare an order if the restaurant is already busy serving many other orders than if it has none pending.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MuIYJDYFIjMOnDfYXTgn7Q.png" /></figure><p>Once again, we can leverage Swiggy’s rich data by looking at the restaurant’s and the customer’s order history to estimate how long it may take for an order to be prepared.</p><p>We also need to consider other dynamic factors such as current load on the Restaurant, how long are existing orders at that Restaurant are taking to be prepared, etc.</p><p>Predicting the Preparation Time is not only very important in showing an accurate Delivery Time, but it’s also important in ensuring that the Delivery Executive reaches the restaurant only when the food is prepared.</p><p>Because, if a Delivery Executive arrives at the restaurant before the order is ready to be picked up, they waste precious time waiting for food to be prepared instead of delivering other orders and, if they arrive too late, food goes cold and well, nobody wants that, either.</p><h3>Estimating Assignment Delay and First Mile Time</h3><p>Now comes the <em>really</em> tricky part. How long will it be before we can find a Delivery Executive who can deliver this order?</p><blockquote>You know those times when you try to get a cab and the app says 5 minutes, so you go ahead and book one, just for it to say, “Oh yeah no, it’s really 30 minutes.” Yeah it’s a hard problem.</blockquote><p>The challenge here is that the demand for Swiggy is very dynamic, given that far more people place orders between 8 PM to 10 PM than between 4 PM and 6 PM.</p><p>So, our Delivery Executives are far busier during the <em>Dinner Peak</em> than during the early evening hours. Thus, during peak times, it will take much longer to find a Delivery Executive who can fulfill the order.</p><p>So how do we estimate this?</p><p>Well, we track all the Delivery Executives and see their status. We can estimate how long it will take for them to be available and start a potential new order. Again, you can see the tricky problems associated with this.</p><p>To begin with, the sheer scale of the issue. We need to keep track of every single Delivery Executive, what they are doing, how long will they be delayed and then see their eligibility to deliver an order from the list of hundreds of restaurants.</p><p>Furthermore, we need to accurately predict how many customers will order at any given time to decide whom we should be serviceable to, given that we have a limited Delivery fleet and not everybody who opens the app ends up ordering.</p><p>For example, if we show the list of restaurants to 10 customers even though we only have 1 Delivery Executive, we will disappoint 9 customers who can’t place their order at checkout. However, if we reserve the Delivery Executive for one of those customers and don’t show the list of restaurants to the other nine, and the customer does not order, we’ve lost a potential order from one of the other nine.</p><p>Lastly, what if the Delivery Executive whom we have reserved, rejects the order?</p><p>You could say, “How about using historical data to get the average Assignment Delay and First Mile at a particular point of time?” Well, that would only be right <em>on average.</em></p><p>So you will end up disappointing half of the customers who are shown too low a value. But simply increasing it is not right either, since every increased minute, results in fewer people ordering. Again, the answer is to cleverly calculate the <em>Goldilocks value.</em></p><p>We need to make estimates based on the current load of the Delivery fleet in the <em>hyperlocal region </em>and the current distribution of fleet around the restaurants.</p><p>Lastly, we need to correctly trade off the <em>buffer </em>time to ensure that we show a high enough value not to give a misleading promise, but low enough not to discourage the customer from placing the order.</p><h3>Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5C2QRzISsgNBdVESYJ4b6Q.png" /></figure><p>Generating the list of restaurants for hundreds of people opening the app every second, and then accurately calculating the delivery time for each of the hundreds of restaurants is one of the most challenging problems we are solving at Swiggy.</p><p>As a data driven company, we religiously experiment with various strategies to get a sense of the trade-offs associated with each strategy to figure out the one which not only matches the business goals, but also ensures the best customer experience.</p><p>In the end, it’s all about the trade-offs and coming up with the <em>Goldilocks value</em>.</p><blockquote>I’m Devansh from the delivery team at Swiggy. If you enjoyed learning about this and would like to take a crack at solving some of the problems mentioned above, head to <a href="https://www.google.com/url?q=https://careers.swiggy.com&amp;sa=D&amp;source=hangouts&amp;ust=1538032601198000&amp;usg=AFQjCNFa2s5Zbi__HC--tn0Kie1ovprvyA">https://careers.swiggy.com</a>.</blockquote><blockquote>And if this hasn’t excited you yet, stay tuned for Part 2!</blockquote><blockquote>Update : Part 2 is now live <a href="https://bytes.swiggy.com/the-swiggy-delivery-challenge-part-two-f095930816e3">here</a>!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a2abb4f82f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swiggy-bytes/the-swiggy-delivery-challenge-part-one-6a2abb4f82f6">The Swiggy Delivery Challenge (Part One)</a> was originally published in <a href="https://medium.com/swiggy-bytes">Swiggy Bytes — Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>