Track physical activity:
Set goals:
Monitor progress:
Other:
Out of scope:
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...
What data is created by the app?
// A workout is just a tuple (step_count, distance, start_time, end_time).
// We send these to the server periodically, rather than logging a continuous stream of
// events everytime the device picks up new data.
POST /v1/workouts
body: {
requestId: // for idempotency
start_time: int64
end_time: int64
steps: int
distance: float (meters)
}
// Fetch workout data within a time range. Used to display the current day's progress and
// weekly timeline view. We may want to consider aggregating workouts on the server
// since the app is primarily interested in per-day aggregates, but let's come back to that.
GET /v1/workouts?start_time={}&end_time={}
Response:
[
{
workout_id: 1
start_time: 1234
end_time: 567
steps: 50
distance: 14.5
},
...
]
// Creates a new workout plan. For simplicity, it will just replace the existing one.
// We might support update_workout_plan in the future, so that user can modify their
// plan.
POST v1/create_workout_plan
Body:
{
requestId: // for idempotency
planName: String
startDate: String
weekly_goals: [
{
week: 0,
steps: 20000,
distance: 5000.0,
},
{
week: 1,
steps: 21000,
distance: 5100.0,
},
....
]
}
// Returns the current workout plan, along with workout progress.
GET v1/progress
Response:
{
plan: { .... } // same as above
currentWeek: Int
progress: [
{
week: 0
steps: 19000,
distance 4900,
}
]
}
// A convenience API to return a summary of the current progress, and some user stats.
GET v1/progressSummary
{
currentDayGoal: 5000,
currentWeek: 2
totalWeeksInPlan: 10 // How long is the plan? User can see how close they are to completion
planName: String
currentWeekSteps: [
4000, 3600, // Steps in last 7 days. Most recent first.
]
}
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.
Overview
We'll use a layered MVVM architecture, with UI layer being responsible for presentation, a ViewModel layer (ProgressViewModel) that holds UI state, and Model layer (ProgressDataSource) that handles backend and database connections and data integrity.
UI Layer
In this architecture Views are stateless and dumb. Mainly just configure presentation. There are two main screens:
ViewModel
Model Layer
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Handling high write load and traffic spikes
The nature of this app is write-heavy. It generates a lot of data over time, and only fetches a summary of that data. We need to ensure the write path is set up to scale. A few strategies:
Handling offline/remote merge conflicts
Live access to GPS and Accelerometer