<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shaswat Kumar</title>
    <description>The latest articles on DEV Community by Shaswat Kumar (@shaswat_kumar_6e172cbd811).</description>
    <link>https://dev.to/shaswat_kumar_6e172cbd811</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4004021%2F9b62b9b3-56c2-4499-8454-9e7eae44aace.png</url>
      <title>DEV Community: Shaswat Kumar</title>
      <link>https://dev.to/shaswat_kumar_6e172cbd811</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shaswat_kumar_6e172cbd811"/>
    <language>en</language>
    <item>
      <title>How I'd Design Uber in a System Design Interview (Full Breakdown)</title>
      <dc:creator>Shaswat Kumar</dc:creator>
      <pubDate>Fri, 26 Jun 2026 12:38:20 +0000</pubDate>
      <link>https://dev.to/shaswat_kumar_6e172cbd811/how-id-design-uber-in-a-system-design-interview-full-breakdown-4mhk</link>
      <guid>https://dev.to/shaswat_kumar_6e172cbd811/how-id-design-uber-in-a-system-design-interview-full-breakdown-4mhk</guid>
      <description>&lt;p&gt;System design interviews are hard because they're open-ended. Here's exactly how I'd walk through designing Uber's ride-sharing platform in 45 minutes — the same approach that helped me clear my interviews.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Framework (5 phases, 45 minutes)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Phase&lt;/th&gt;
&lt;th&gt;Time&lt;/th&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Requirements&lt;/td&gt;
&lt;td&gt;5 min&lt;/td&gt;
&lt;td&gt;Scope it down to 3 functional + 3 non-functional&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Entities + API&lt;/td&gt;
&lt;td&gt;5 min&lt;/td&gt;
&lt;td&gt;5-6 entities, one endpoint per requirement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Architecture&lt;/td&gt;
&lt;td&gt;15 min&lt;/td&gt;
&lt;td&gt;Build incrementally, one FR at a time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deep Dives&lt;/td&gt;
&lt;td&gt;15 min&lt;/td&gt;
&lt;td&gt;Bad → Good → Great for 2-3 hard problems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Wrap-up&lt;/td&gt;
&lt;td&gt;5 min&lt;/td&gt;
&lt;td&gt;Summarize tradeoffs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Requirements I'd Pick
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Functional (top 3):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Riders request a ride → get matched with nearest driver in &amp;lt;30s&lt;/li&gt;
&lt;li&gt;Real-time location tracking — drivers send GPS every 3-5s&lt;/li&gt;
&lt;li&gt;Drivers accept/decline, navigate, complete trip&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Non-functional:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;500K location writes/sec (2M drivers × 1 ping/4s)&lt;/li&gt;
&lt;li&gt;No double-booking (strong consistency on driver assignment)&lt;/li&gt;
&lt;li&gt;99.99% availability during peak&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Architecture (built incrementally)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Matching a Rider with a Driver
&lt;/h3&gt;

&lt;p&gt;The first question: how do you find the nearest driver?&lt;/p&gt;

&lt;p&gt;You can't query Postgres with &lt;code&gt;WHERE distance &amp;lt; 3km&lt;/code&gt; at 500K writes/sec. The answer: &lt;strong&gt;Redis Geo&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Redis Geo stores coordinates using geohash encoding. &lt;code&gt;GEORADIUS&lt;/code&gt; returns all drivers within a radius in O(N+log M) time — sub-millisecond at scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flow:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rider taps "Request Ride" → hits API Gateway&lt;/li&gt;
&lt;li&gt;Matching Service asks Redis Geo: "drivers within 3km of pickup"&lt;/li&gt;
&lt;li&gt;Ranks by ETA (not raw distance — a driver 500m away in traffic is worse than 1.2km on a highway)&lt;/li&gt;
&lt;li&gt;Locks the best driver with &lt;code&gt;SET NX EX 20&lt;/code&gt; (atomic distributed lock with 20s TTL)&lt;/li&gt;
&lt;li&gt;If lock acquired → send ride offer. If not → try next driver.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2: Real-Time Location Streaming
&lt;/h3&gt;

&lt;p&gt;2M drivers × 1 ping/4s = 500K writes/sec. No disk DB survives this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Architecture:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Driver → Location Ingestion (stateless fleet) → Redis Geo (spatial index) + Kafka (event stream)&lt;/li&gt;
&lt;li&gt;Kafka → WebSocket Gateway → Rider's app (live map update)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key insight: Redis entries have a 15-second TTL. If a driver crashes, their entry auto-expires. No ghost drivers in matching results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Preventing Double-Booking
&lt;/h3&gt;

&lt;p&gt;Two riders see the same driver as "nearest." Without protection → double booking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Redis &lt;code&gt;SET driver:{id}:lock {rideId} NX EX 20&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;NX&lt;/code&gt; = only set if not exists (atomic)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;EX 20&lt;/code&gt; = auto-expire in 20s (prevents deadlock)&lt;/li&gt;
&lt;li&gt;Backstop: Postgres unique constraint on (driver_id, status=ACTIVE)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Deep Dive: Surge Pricing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bad:&lt;/strong&gt; Fixed prices. At peak demand, riders wait 10+ minutes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good:&lt;/strong&gt; Simple 2x/3x multiplier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Great:&lt;/strong&gt; H3 hexagonal zones with real-time supply/demand signals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;City divided into ~5km² hexagons&lt;/li&gt;
&lt;li&gt;Every 30s: &lt;code&gt;demand_score = requests / available_drivers&lt;/code&gt; per zone&lt;/li&gt;
&lt;li&gt;If &amp;gt; 1.5 → surge kicks in, capped at 3x&lt;/li&gt;
&lt;li&gt;Drivers see heat map → incentivized to relocate to high-demand zones&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Full Design
&lt;/h2&gt;

&lt;p&gt;This is a condensed version. The full breakdown (with Mermaid diagrams, sequence diagrams, ride state machine, 5 deep dives, technology choices table, and cost analysis) is here:&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;a href="https://systemcraft.in/Uber" rel="noopener noreferrer"&gt;Full Uber System Design on SystemCraft&lt;/a&gt;&lt;/strong&gt; (free, no signup)&lt;/p&gt;

&lt;p&gt;I've also written 15 other designs (Netflix, Instagram, Zomato, Google Docs, WhatsApp, etc.) in the same format at &lt;a href="https://systemcraft.in" rel="noopener noreferrer"&gt;systemcraft.in&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;What system would you like me to break down next? Drop it in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
