Although a full-fetched Fitness Tracking application would be able to do lots of different things, we'll concentrate on it's core functionality:
We'll need a storage for users, users' goals and users' workouts.
Assuming, 10k DAU at the start and up to 50k DAU in a year we can roughly estimate our storage requirements:
In total we'll need very modest 3*10^4 * 6*10^4 B = ~2 * GB of storage for the first year.
We'll need the following API in the system:
POST v1/goals/new - returns a status code and some metadata (id,
{
id: string,
user: string,
type: string,
created_at: timestamp
}
GET v1/goals/user/{user_id} - returns paginated set of a user's workouts
{}
POST v1/workouts/start - return a workout id
{
user: string,
started_at: timestamp
type: string
}
POST v1/workouts/{id}/readings - returns a status code
{
heart_rate: int,
coordinates:
...
}
POST v1/workouts/{id}/finish - returns a status code and some metadata
{
finished_at: timestamp
}
POST v1/workouts/new - returns a status code and some metadata
{
user: string,
type: string,
indicators: [ind1, ind2, ... ]
started_at:
}
GET v1/workouts/user/{id} - returns a paginated set of a user's workouts
We'll have a NoSql storage for all our entities, since we don't need strict consistency guarantees or relational queries. And also we can anticipate changes in the schemas, since we're in the early stages of development of our app.
We'll store the following entities:
Goal - supports only goals for a desired number of workouts per week
{
id: string,
user: string,
type: string,
target_value: int
}
Workout
{
id: string,
user: string,
duration: int,
indicators: [ind1, ...]
start: timestamp,
end: timestamp
}
We'll need the following indices:
We'll have a load-balancer with a rate limiter facing our system's clients requests. Right behind the load balancer will be an API Gateway routing user requests to the proper services:
Each service will have its' own dedicated storage. And all needed aggregation will be handled on the services level.
Let's take a closer look at managing workouts flow:
Let's focus on a workouts service, as it seems to be the service with the most load: