KatInterview

Workout Tracker Backend: Live Routes, Period Rankings, Social Boards

System DesignModel answer
MediumModel answerSystem Designsystem-designleaderboardsredis

Last updated

Design the backend for a workout-tracking app with real-time route sharing to followers, top-workout queries over date ranges, and ranked boards of aggregated user stats.

You are asked to design the backend for a mobile app where people record runs and rides with GPS, and share them with the people who follow them.

The product must support three capabilities:

  1. Live route sharing. While a user is exercising, their followers can open the app and watch the route being drawn in near real time.
  2. Best workouts in a time window. A user can ask for the top workouts by a chosen metric (for example distance) within a date range, across different scopes: their own workouts, workouts by people they follow, or everyone.
  3. Ranked boards. Weekly, monthly and all-time rankings per sport and metric, viewable globally or restricted to people the user follows, including a "where do I stand" view.

What to cover in your answer

  • Clarifying questions, plus the functional and non-functional requirements you would assume.
  • A rough capacity estimate (users, concurrent workouts, write rate, storage).
  • API sketch and data model, including which store holds what.
  • A high-level architecture, then deeper dives on each of the three capabilities.
  • Correctness issues: retries, duplicate uploads, edited or deleted workouts, late offline uploads, time zones, cheating.
  • Privacy handling (visibility settings, hidden zones near home).
  • Trade-offs, failure modes, and how you would validate the design with tests and metrics.

Hints

Hint 1

The three capabilities have very different shapes: a high-rate write stream with few readers, a range query over history, and continuously updated per-user aggregates. Consider a different storage and freshness model for each.

Hint 2

For best single workouts in a date range, think about bucketing by day and merging bounded top-K lists. Ask whether the same trick still works when the ranking is based on a per-user sum.

Hint 3

For ranked boards, consider an in-memory sorted structure per period, and think about idempotent updates, edits and deletes applied as deltas, assigning the period by workout start time in the user's time zone, and a periodic rebuild from the source of truth.