What is Bump

Bump is location sharing Mobile App. Install bump on 2 phones(add as friends).
Phone1 can see location of Phone2 on bump. Helpful if someone is travelling alone in new area

Requirements (CRUD)

Functional

1. User can create Account on Bump
2. Read location of friend on bump app
3. Update self profile to include friends(whom you will follow)
4. Delete friend
5. Delete account

Non-Functional

1. Highly available
2. Secure
3. Reliable. Location given of Phone2 should be correct

BOE

Metric Description
QPS(Queries per second) Very low, as in when someone opens app then request is sent to system and system sends location back
BW Estimates
Storage Requirements Data to be stored for 1 user: < user_id(8 byte), longitude(8 bytes), lattitude(8 bytes), followed_by(8 * 50 bytes) >
Total storage required: 400 bytes(for 1 user)
100 Million users. 40G bytes(for 5 years)

API Design (CRUD)

REST API?
REST API Versioning(v1,v2)

1. User can create Account on Bump

2. Read location of friend on bump app

3. Update self profile to include friends(whom you will follow)

4. Delete friend

5. Delete Account


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

// data sent as query parameter
// instead of sending as json data
curl -X GET http://127.0.0.1:8080/v1/get_location?friend_id=friend_id
        

curl -X PUT -H "Content-Type: application/json" -d 
'{
  "user_id": "current_user_id", 
  "friends_to_follow": ["new_friend_id"]
}' 
http://127.0.0.1:8080/v1/update -vvv
        

curl -X DELETE -H "Content-Type: application/json" 
http://127.0.0.1:8080/v1/delete_friend
-d '{
  "user_id": "id1",
  "friend_id": "friend_to_delete"
}' 
        

curl -X DELETE -H "Content-Type: application/json" 
http://127.0.0.1:8080/v1/delete_account
-d '{
  "user_id": "id1",
}'
        

// Create account
//url=bump.amo.com
POST https://url/v1/create_account 
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_name": "",
  "lattitude": "",
  "longitude": ""
}
        

//Read Location of friends
GET https://url/v1/get_location
header {
  Authorization: {Bearer "API_KEY_TOKEN"},
  ..other fields..
}
body {  //JSON
  "my_username": "", 
  "friend_name": "",
}
          

// Add new friends to look
PUT http://url/v1/update
header {
  Authorization: {Bearer "API_KEY_TOKEN"},
  ..other fields..
}
body {  //JSON
  "my_username": "", 
  "friend_name": "",
}
        

// Add new friends to look
PUT http://url/v1/delete_friend
header {
  Authorization: {Bearer "API_KEY_TOKEN"},
  ..other fields..
}
body {  //JSON
  "my_username": "",
  "friend_id": ""
}
        

// Add new friends to look
PUT http://url/v1/delete_account
header {
  Authorization: {Bearer "API_KEY_TOKEN"},
  ..other fields..
}
body {  //JSON
  "my_username": ""
}
        

DB Schema

Graph DB

// user Table
| userid (pk) | username | creation_timestamp | initial_location (long, latt) |

// friends table
-> Would be stored on Graph DB
    

HLD

Design-1: Using Kafka to send events

Amo App
User Authentication: System authenticates user has permission to access friend's location or not

Push notifications(Web sockets): For lower latency and reduced resource usage. The server will push updates to the client only when there’s a significant change in location

Fetch user locations through Google APIs: Google APIs will collect GPS coordinates directly from the user's device via the user's permission.

Friend is Offline: retry will happen. Fetcher might put same msg on kafka queue and service after x time.

Reducing Latency:
Websockets can be used in place of pooling.
  Instead of Fetcher pushing data on kafka then sender sending the data, fetcher can directly send the data to user
  Replace Kafka with a lightweight event-driven architecture using WebSocket for real-time communication. Kafka is overkill for a relatively low-volume messaging use case like this.

Fetching Location: It not neccessary to use Google's API for location
  On Android we can use FusedLocationProviderClient API
  On iOS we can use CoreLocation API
  open-source or free geolocation services like OpenStreetMap or Here APIs for mapping and rendering user location.

Design using WebSocket AppServer

Amo App
Reduced Latency:
  In place of kafka, AppServer has became a Websocket server, which maintains connection open when client connects to server to get location of friend
  Removed Sender module, Now fetcher can directly send updates to AppServer.