Requirements

Functional

There would be 2 entities(User & driver) which will use this system
User Requirements:
1. User can create his profile on system.
2. [READ] User should be able to see near by cabs on real time.
3. [Create] User can book the cab
4. [Delete] User can Cancel the ride after successful booking.
5. [Update] User can modify the ride
Driver's Requirements:
1. [Create] Driver can create his profile on system.
2. [Update] Location of driver is updated on real time.
3. [READ] Driver gets notification of near users asking for booking.
4. [Delete] Driver can cancel ride after booking.

BOE

Assumed. Users(300 Million) Drivers(1M). DAU(1M), DA Drivers(500k). Daily rides(1M)
Drivers update their location every 5 seconds.

QPS (Queries Per Second) User Queries: 1M / 86400 = 12 queries per second
Driver does not do queries, but updates are pushed to driver when driver is not on trip.
Bandwidth Estimates 1 User Requests for cab location size = 90 bytes. 12 x 90 = 1080 bytes/sec
TCP, IP, DL Header sizes

|App Hdr + (userlong, lat, userId, preference)|Transport TCP(src,dst port)|NW(src, dst IP)| DL Hdr(src, dst MAC) |
  20bytes         17bytes                       20 bytes                    20 bytes         14 bytes             => 90bytes 
          
Storage Estimates Not Huge. We need to store user's & drivers rides

APIs (CRUD)

User APIs

REST API?
REST API Versioning(v1,v2)

1. User Creates a booking

2. User gets all nearby cabs

4. User can cancel the ride


curl -X POST -H "Content-Type: application/json" 
-d '{"user_id": "", "driver_id": "", "to": "", 
"from": "", "initial_price": "", "duration": "", }' 
http://127.0.0.1:8080/v1/booking/create -vvv
          

curl -X GET -H "Content-Type: application/json" 
-d '{"user_id": "", "long": "", "lat": ""}' 
http://127.0.0.1:8080/v1/booking/read -vvv
        

curl -X DELETE -H "Content-Type: application/json" 
-d '{"user_id": "", "booking_id": ""}' 
http://127.0.0.1:8080/v1/booking/cancel -vvv
          

POST https://url/v1/booking/create   //url=uber.com
header {
  Authorization: {Bearer "API_KEY_TOKEN"},

  /*Mandatory added by HTTP Start*/
  Content-len: 0                        
  Host:        //Calculated when req is sent
  UserAgent: Postman
  Accept: */*       
  Accept-Encoding: gzip, deflate, br
  Connection: Keepalive
  /*Mandatory added by HTTP End*/
}
body {  //JSON
"user_id": "", "driver_id": "", "to": "", 
"from": "", "initial_price": "", "duration": "", 
}
        

// All free cabs near user
GET https://url/v1/get_cabs
header {
  Authorization: {Bearer "API_KEY_TOKEN"},
  ..other fields..
}
body {  //JSON
  "long": ""
  "lat": ""
}
        

// User cancels the ride
GET https://url/v1/cancel_cab
header {
  Authorization: {Bearer "API_KEY_TOKEN"},
  ..other fields..
}
body {  //JSON
  "user_id": ""
  "booking_id": ""
}
          

HLD

We will extend quadtree design of yelp here
Frequent Updates on quadtree:
Difference b/w Uber & yelp is there would be more frequent updates on quadtree wrt yelp. Since Drivers update their location(driver_id, lat, long) every 5 seconds, Will we update quadtree on every update?
No. We will create a local datastructure(Hash Table), which will store info of drivers and will send the information after 10-15 seconds. This will reduce frequent updates on system.

      Hash Table:
      key=driver_id(3 bytes), value={lat(8bytes), long(8bytes)} //19 bytes
    
      500k driver. 10Mbytes of storage