Log workouts: Users can record activities (type, duration, distance, heart rate, GPS route).
View history & stats: Users can view past workouts and aggregated metrics (daily, weekly, monthly).
Sync across devices: Seamless state synchronization across mobile, web, and wearables.
High Availability & Reliability: The system must remain available even if individual components fail.
Low Latency (Writes): Logging real-time telemetry from wearables or phones must be fast and unobtrusive.
Eventual Consistency (Reads): It is acceptable if aggregated stats take a few seconds to update after a workout finishes.
Offline Support: The mobile client must allow logging workouts without an internet connection and sync when back online.
We will use RESTful APIs. For high-frequency telemetry data from devices, a WebSocket or gRPC stream could be considered, but REST with batched payloads is simpler and highly effective for standard mobile clients.
/v1/workouts{ "user_id": "123", "type": "RUN", "start_time": "...", "end_time": "...", "metrics": [...] }/v1/workouts?user_id=123&limit=20&offset=0/v1/stats?user_id=123&period=weekly/v1/goals{ "user_id": "123", "metric": "DISTANCE", "target": 10.0, "period": "WEEKLY" }The system relies on a microservices architecture to decouple the heavy write operations (workout telemetry) from the read-heavy operations (user profiles and aggregated stats).
1. Workout Ingestion & Storage (Write Path)
WorkoutCompleted event to Kafka.2. Stats Aggregation & Goals (Async Processing)
WorkoutCompleted topic.GoalAchieved event to Kafka, which the Notification Service picks up to send a push notification to the user.GET /v1/stats, the API fetches it from Redis in sub-millisecond time, falling back to PostgreSQL only on a cache miss.