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
Non-Functional
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 |
|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
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
@startuml
control DNS as dns
box India #LightCyan
actor User as u
end box
box Data Center
participant LoadBalancer as lb
participant AppServer as as
queue Kafka as kafka
participant Sender as sender
participant Fetcher as fetcher
database connDB as conndb
end box
box US #LightYellow
actor Friend as f
end box
participant 3rdPartyAPIs as 3rdapis #LightPink
note over sender
send location of
friend to user
end note
note over fetcher
Fetches friend
latt,long
using google APIs
end note
note over 3rdapis #LightPink
To get GPS location
Free Geolocation APIs
- OpenStreetMap OR
Android:
FusedLocationProviderClient OR
iOS:
CoreLocation framework
end note
u -> dns: amo.com
dns -> u: 1.2.3.4
u -> lb: HTTP GET\n/v1/get_location?friend_id=789
lb -> as: HTTP GET\n/v1/get_location?friend_id=789
as -> kafka: Topic(get_frnd_location)\nMsg(user_id=123,\nfriend_id=789)
kafka -> fetcher: Topic(get_frnd_location)\nMsg(user_id=123,\nfriend_id=789)
fetcher -> conndb: Get friend IP
conndb -> fetcher: friend's IP
fetcher -> f: Give permission to use GPS
f -> fetcher: done
fetcher -> 3rdapis: friend's IP
3rdapis -> f: GPS coordinates
f -> 3rdapis: corrdinates
3rdapis -> fetcher: long,lattitude
fetcher -> fetcher: Verify long,latt
note over fetcher #Cyan
CACHING
Since locations
are frequently
asked, we can
add a Cache layer
end note
fetcher -> kafka: Topic(frnd_location)\nMsg(long,latt\nfrnd_id=789,usr_id=123)
kafka -> sender: Topic(frnd_location)\nMsg(long,latt\nfrnd_id=789,usr_id=123)
sender -> conndb: User(123) IP?
conndb -> sender: x.y.z.f
sender -> u: long,latt (frnd_id=789)
note over u
Mobile App draws
a map using
Mapbox or
OpenStreetMap
for distance between
friends
end note
sender <-> u: sender keep sending location updates every 30 seconds
@enduml
|
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
|
|
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. |