How to Pass the Swiggy SDE-2 Machine Coding Round

Swiggy's SDE-2 machine coding round is notoriously tough. It doesn't just test your basic logic. Instead, you're judged on how well you can turn vague requirements into clean, extensible, and thread-safe code while racing against the clock. You typically get exactly 90 to 120 minutes to design, build, and demonstrate a fully working system. Since this is a mid-level engineering role, the interviewer wants way more than a simple algorithm that spits out the right answer. They expect production-grade object-oriented design. If your code can't easily handle a brand-new business rule without ripping open the core logic, you're going to have a hard time passing.
The Swiggy SDE-2 Interview Process
Before you start writing code, you need to understand exactly what you're up against. Swiggy’s interview loop heavily favors practical, hands-on engineering skills. They care deeply about how you structure your code and design robust distributed systems.
| Round | Duration | Focus Area | Key Expectation |
|---|---|---|---|
| 1. Machine Coding | 90-120 mins | Low-Level Design & Clean Code | Working, extensible CLI application |
| 2. DSA & Problem Solving | 60 mins | Algorithms & Data Structures | Optimized solutions for medium/hard problems |
| 3. System Design (HLD) | 60 mins | Scalability & Architecture | Designing distributed systems at scale |
| 4. Hiring Manager | 60 mins | Behavioral & Past Experience | Cultural fit and engineering maturity |
Breaking Down the Machine Coding Round

Your main goal here is to deliver a working, modular, and extensible solution. You aren't building a web service, wiring up REST APIs, or hooking into a real database. Instead, you'll build an in-memory application. This usually runs via a simple command-line interface or a hardcoded set of test cases inside a main driver method. Time management is easily your biggest enemy. I've seen plenty of candidates fail simply because they wasted 40 minutes writing a massive input parser, leaving almost no time for the actual business logic.
- Read and clarify requirements (10-15 mins): Pinpoint the core entities and potential edge cases.
- Domain modeling and interfaces (15-20 mins): Map out your classes, repositories, and strategy interfaces on paper or in comments.
- Core logic implementation (40-50 mins): Write the actual business logic, tackling the most complicated parts first.
- Testing and edge cases (15 mins): Wire up your main driver class and prove the system works using hardcoded inputs.
The Problem: Designing a Surge Pricing Engine
Let's look at a classic Swiggy SDE-2 problem: designing a dynamic delivery fee and surge pricing engine. Your system has to calculate the final delivery cost using base distance, current weather conditions, the time of day, and real-time delivery executive (DE) availability within a specific zone. The real trick here is making sure your core engine stays completely untouched when new rules—like a sudden festival surge—are inevitably added later.
What are the core entities and relationships?
Every solid Low-Level Design (LLD) starts with identifying the right entities. You need to keep these strictly separated from your business logic. For a surge pricing engine, you'll have to model the geographical constraints, the various actors involved, and the transaction itself.
- Location: Represents a physical point (lat/lon) or a predefined Zone ID.
- Order: Holds the cart value, customer location, and restaurant location.
- Zone: Manages the geographical area while tracking the count of active versus busy delivery executives.
- PricingRule: An entity or configuration that stores the current multipliers for different conditions.
Architecture, Interfaces, and SOLID Principles
If you hardcode a bunch of if-else blocks for the weather or time of day, you'll fail the interview on the spot. Swiggy evaluators pay massive attention to the Open/Closed Principle (the 'O' in SOLID). You need to prove you can add a brand-new pricing rule, like a Late Night Premium, without touching the core calculation engine.
How do you implement the Strategy Pattern for pricing?
Start by defining an interface called PricingStrategy. Give it a single method that accepts an OrderContext and the currently calculated price, then returns the updated price. From there, you can implement concrete classes like DistanceBasePricing, WeatherSurgePricing, and DemandSupplySurgePricing. Think of the OrderContext as a data transfer object holding all the necessary metadata—like the weather enum, zone load factor, and distance. This way, you won't have to rewrite the interface signature if a future strategy suddenly needs entirely new data points.
Handling Concurrency and State Transitions
The absolute hardest part of this challenge is dealing with the dynamic nature of delivery executive availability. Imagine 50 orders drop simultaneously in the exact same zone. The available DE count plummets instantly, meaning the surge multiplier has to spike right away to reflect that low supply. Since you're building an in-memory application, your datastore absolutely must be thread-safe.
How do you track thread-safe capacity?
Rely on a ConcurrentHashMap for your in-memory repositories. Whenever an order gets assigned, the zone's available delivery executive count has to decrement atomically to avoid messy race conditions. If you try using standard integers here, they'll fail the second they hit concurrent load.
- Use a ConcurrentHashMap to store zone data, using the Zone ID as your key.
- Use an AtomicInteger to track availableExecutives inside your Zone class.
- When calculating the demand-supply surge, read that atomic value to figure out the ratio of active orders to available DEs.
- Only use synchronized blocks or ReentrantLocks if you need to perform compound actions—like checking if a DE is available and immediately assigning them in a single, atomic step.
Step-by-Step Implementation Strategy
Start by building out your models. Keep them anemic at first—just basic getters and setters—to save precious time. You can always move business logic into them later if it strictly belongs there, like having a Zone calculate its own load factor based on internal state. Next, build your in-memory repositories to hold the mock data. Finally, wire up the PricingEngine service to orchestrate all your pricing strategies.
Do not spend 30 minutes writing some complex input parser that reads from STDIN. Ask your interviewer right at the start if you can just hardcode the inputs in your driver class to save time. Almost all interviewers would rather watch you tackle the core logic instead of watching you split strings.
Testing and Edge Cases
A solution that compiles perfectly but completely fails on edge cases is still a failure in the eyes of a senior engineer. You need to prove that your code can handle weird boundary conditions gracefully without taking down the entire application.
What edge cases must be handled?
- Zero available delivery executives: This needs to trigger a maximum surge cap or throw a specific ServiceUnavailableException, rather than blowing up with a divide-by-zero error.
- Missing weather data: Your engine should gracefully fall back to a default multiplier of 1.0.
- Negative cart values or distances: Basic input validation should catch these before the pricing engine even gets invoked.
- Surge stacking limits: If it's raining, late at night, and demand is through the roof, the delivery fee shouldn't end up costing more than the food itself. Implement a hard maximum cap on the final calculated surge.
How to Use AcePrompt to Ace Your Live Swiggy Interview
Writing extensible, concurrent code while an interviewer stares at your screen is incredibly stressful. It's so easy to forget the exact syntax for atomic operations or the best way to structure a strategy pattern when you're under that kind of pressure.
That's where AcePrompt comes in as your real-time AI interview copilot. It listens to the live conversation and gives you structured, personalized guidance right on your screen. If the Swiggy interviewer suddenly throws a curveball—like asking, 'How would you ensure the surge multiplier updates in real-time across multiple instances?'—AcePrompt instantly suggests the architectural trade-offs between Redis Pub/Sub and Kafka. It keeps you calm, focused, and ready to answer articulately.
Frequently asked questions
What programming languages are allowed in Swiggy's machine coding round?
You can typically use any mainstream object-oriented language like Java, C++, Python, or C#. That said, Java is highly recommended because of its massive standard library for concurrency, collections, and well-established OOP patterns.
Do I need to connect to a real database during the interview?
Not at all. They expect you to build an in-memory application. Just use simple data structures like Maps and Lists to simulate your database tables and repositories.
Is it mandatory to complete the entire problem in 90 minutes?
While finishing everything is obviously the ideal outcome, interviewers actually prioritize clean, extensible design over a 100% complete but messy script. A beautifully structured core engine with a few mocked inputs will always beat fully working spaghetti code.
How important is thread safety in the machine coding round?
It's incredibly important for SDE-2 roles. Swiggy operates at massive scale, so proving you understand concurrent state modifications—like using atomic counters for driver availability—sends a very strong positive signal to the hiring manager.
Related comparisons
See AcePrompt in action
Watch how AcePrompt supports a real technical round - structured answers, tuned to your resume, in real time.
Stop freezing under pressure. Let AcePrompt guide you through your next live technical interview.
Get started