Design a Fitness Tracking App
0%
Editorial Solution
System requirements
Functional
Capacity estimation
Traffic
API design
Activity Upload
Database design
PostgreSQL: Core Entities
High-level design
Request flows
Activity Upload Flow
Detailed component design
Offline Sync Engine
Tradeoffs
SQL vs. NoSQL for Activity Storage
Failure scenarios
S3 Unavailability During Activity Upload
Future improvements
Social Features and Challenges
Table of Contents
System requirements
Functional
Capacity estimation
Traffic
API design
Activity Upload
Database design
PostgreSQL: Core Entities
High-level design
Request flows
Activity Upload Flow
Detailed component design
Offline Sync Engine
Tradeoffs
SQL vs. NoSQL for Activity Storage
Failure scenarios
S3 Unavailability During Activity Upload
Future improvements
Social Features and Challenges
A fitness tracking app seems straightforward: record a workout and show stats. The real complexity surfaces when millions of users stream GPS coordinates every second during their morning runs, when phones lose cellular signal mid-workout, and when the system must reconcile data from wearables, phones, and web clients without losing a single data point. This is not a CRUD app with a map; it is a high-throughput sensor data pipeline with offline-first semantics.
Functional
Activity tracking: Users record running, cycling, and weightlifting workouts. Activities can be logged manually (entering time and distance after a gym session) or captured automatically via GPS and wearable sensors. The system stores the full sensor stream: GPS coordinates, heart rate, cadence, and elevation at per-second granularity.
The capacity numbers for a fitness tracking app are driven by one insight: the data volume per user is moderate, but the peak concurrency of live workout streams creates the real scaling challenge. Designing for average throughput means the system degrades precisely during morning and evening rush hours.
Traffic
10 million registered users, 1 million DAU: A Strava-scale platform. Not every user works out daily; roughly 500,000 activities are completed per day (some users log multiple).
The API surface covers four core operations: uploading activities, retrieving activity data, managing goals, and streaming live GPS during a workout. Every endpoint requires authentication via OAuth 2.0 bearer tokens because all data is personal.
Activity Upload
1POST /v1/activities
2Headers: Authorization, X-Idempotency-Key (client UUID)
3Body: {
4type: "running" | "cycling" | "weightlifting",
5start_time: ISO-8601,
6duration_seconds: number,
7distance_meters: number,
8calories: number,
9heart_rate_avg: number,
10heart_rate_max: number,
11gps_track: base64-encoded compressed binary (optional),
12source: "manual" | "phone_gps" | "apple_watch" | "garmin"
13}
14Response: 201 Created { activity_id: string, status: "saved" }The data model splits across three storage systems, each chosen for the access pattern it serves. The interesting decision is not the schema itself but why a single database cannot serve all three workloads efficiently.
PostgreSQL: Core Entities
1users
2user_id UUID Primary Key
3email VARCHAR Unique, indexed
4name VARCHAR
5password_hash VARCHAR
6created_at TIMESTAMP
7
8activities
9activity_id UUID Primary Key
10user_id UUID Foreign Key -> users
11type VARCHAR (running, cycling, weightlifting)
12start_time TIMESTAMP Indexed (user_id, start_time DESC)
13duration_sec INTEGER
14distance_m INTEGER
15calories INTEGER
16hr_avg SMALLINT
17hr_max SMALLINT
18gps_storage_key VARCHAR (S3 key for GPS track)
19source VARCHAR (manual, phone_gps, apple_watch)
20idempotency_key UUID Unique, indexed
21created_at TIMESTAMP
22
23goals
24goal_id UUID Primary Key
25user_id UUID Foreign Key -> users
26goal_type VARCHAR (weekly_distance, weekly_frequency)
27target_value INTEGER
28start_date DATE
29end_date DATE (nullable for recurring)
30created_at TIMESTAMPThe architecture separates three distinct workloads: real-time GPS ingestion (high-concurrency, low-bandwidth writes), activity storage (batch writes with relational queries), and dashboard reads (high frequency, cache-friendly). Each workload has different scaling characteristics, and the event bus (Kafka) connects them without tight coupling.
Mid-level: draw the API Gateway, Activity Service, and a single database. Mention caching for dashboard reads.
Senior: separate the GPS ingestion path (WebSocket, Redis buffer, S3 flush) from the activity upload path (REST, PostgreSQL) and the dashboard read path (Redis cache). Explain why Kafka decouples these paths.
Staff: design the GPS ingestion scaling strategy for 500K concurrent workouts, reason about backpressure when Redis buffers fill faster than S3 flushes, and explain partition key choices for the Kafka activity topic.
Two request flows define the system's behavior: the activity upload flow (writing a completed workout) and the dashboard read flow (displaying stats and history). Understanding each step reveals why the architecture is structured the way it is.
Activity Upload Flow
The core engineering challenge (the GATE of this problem) is building a reliable offline-to-online sync pipeline that handles intermittent connectivity, duplicate uploads, and concurrent multi-device edits without losing or corrupting workout data. Every component in this section exists to solve some aspect of that challenge.
The GATE insight: the fundamental difficulty is that the client, not the server, is the source of truth during a workout. The phone records data for an hour with no server contact, then must sync reliably when connectivity returns. This offline-first inversion drives the idempotency design, conflict resolution, and the entire sync protocol.
Offline Sync Engine
Every architectural decision involves a trade-off. Understanding these trade-offs, and being able to articulate them in an interview, demonstrates deliberate design thinking.
SQL vs. NoSQL for Activity Storage
PostgreSQL (our choice) provides ACID transactions, rich query capabilities (joins for goal evaluation, aggregations for dashboards), and strong consistency for activity records. The trade-off: vertical scaling limits throughput to roughly 10K writes/sec on a single primary. At 500K activities/day (6/sec average, 100/sec peak), PostgreSQL handles this comfortably.
The system's reliability depends on graceful degradation: each component can fail independently without losing user workout data. Every failure scenario maps to a specific architectural decision.
S3 Unavailability During Activity Upload
Scenario: S3 returns errors during a burst of activity uploads after a popular evening workout window.
These improvements extend the platform without changing the core architecture. Each builds on the existing event-driven pipeline.
Social Features and Challenges
The activity_created events in Kafka enable a social feed without modifying the Activity Service. A new Social Service consumes events, generates feed items for the user's followers, and stores them in a fan-out feed table. Challenges (such as "run 100 miles this month with friends") are implemented as shared goals evaluated by the Goal Service across multiple user_ids.
Try this problem yourself
Reading a solution is not the same as producing one under interview pressure. Design it on the whiteboard and get scored feedback.
0%
Editorial Solution
System requirements
Functional
Capacity estimation
Traffic
API design
Activity Upload
Database design
PostgreSQL: Core Entities
High-level design
Request flows
Activity Upload Flow
Detailed component design
Offline Sync Engine
Tradeoffs
SQL vs. NoSQL for Activity Storage
Failure scenarios
S3 Unavailability During Activity Upload
Future improvements
Social Features and Challenges
Table of Contents
System requirements
Functional
Capacity estimation
Traffic
API design
Activity Upload
Database design
PostgreSQL: Core Entities
High-level design
Request flows
Activity Upload Flow
Detailed component design
Offline Sync Engine
Tradeoffs
SQL vs. NoSQL for Activity Storage
Failure scenarios
S3 Unavailability During Activity Upload
Future improvements
Social Features and Challenges