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" }This highly available microservices architecture decouples heavy write operations from read operations while introducing stream processing and fault-tolerance mechanisms to ensure data integrity and system resilience.
1. Robust Workout Ingestion & Offline Sync (Write Path)
200 OK), the server safely ignores it without corrupting the user's data.2. Handling Out-of-Order Data (Stream Processing)
Workout Service no longer writes directly to the database. Instead, it pushes the raw, timestamped payload into a Kafka Raw Telemetry Stream.WorkoutCompleted event to the processed Kafka topic.3. Stats Aggregation & Goals (Async Processing)
Stats Service and Notification Service subscribe to the WorkoutCompleted Kafka topic.Stats Service asynchronously increments the user's running totals in PostgreSQL.GoalAchieved event, prompting the Notification Service to dispatch a push notification.4. Fault Tolerance & Service Isolation (High Availability)
User Service latency spikes or it crashes, the circuit breaker "trips," failing fast and immediately returning a 503 Service Unavailable instead of holding connection threads open.Stats Service experiences an outage, the API Gateway catches the failure. Instead of showing an error screen, it degrades gracefully by fetching the last known stale dashboard data directly from the Redis Cache, ensuring the user still sees a functional UI.