(userId, activityId) or (deviceId, eventId) as a unique key. Retries won’t create duplicates.”Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
post /activities(user, activity) return success
POST /activities/bulk return tracker inProgress/success/error
get user/{id}/activites return list of activites
get /activities/{activity_id} return activity requested
notification post/notficications get/notification
message queue handles asycn process DB operation
get Goals /user/{id}/goals -- return goals like weight, step count,
get stats /user/{id}/stats -- return stats like workout done ,calories counted
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
Calculateion -
user id 16 bytes, workout type- 20 bytes , duration - 8 bytes, caloires bured 4 bytes,distance 0 8 bytet, heatrate- 4 bytest, timestamp 8 byte -- 200bytes
2kb * 1m== 2gb per day - 700gb per year
peak 10gb per day
5 Year 3.5 tb
Let me try to put down things
Main Database (OLTP)
Time series Database
Goal serive.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Idempotency -
large upload-
How will you handle out-of-order or noisy GPS data?
. GPS data - we will store raw gps data but won't rely on it
Encoding routes- i won;t store the full latitude and longitude i will store the differnce and try to convert it into stirng and then use some library like google poly line, basicallly store the first lat and then just store the diference ,
Have you considered how to ensure async enrichment won't block user interactions :-
this will be fire and forget,When ever new activity will come it will create an event, activiy create, updated,deltered - via kafka/sqs + sns , anaylics service will substribe to this mertics\
How will you handle offline data buffering and merging on reconnect?
We will userID activity id stored in local storage and event will have to replay to sync
What approach will you take to ensure backlog/replay is safe?
Safe replay by using an outbox on the client 0-> unique eventid,activityy id , version/updaredby
on reconnecte we will process them in order and server will rpocess them idempotently if there is stale event we will miss it
also sends per event acknowledgmen so client can delete it after that