Back to explorer
System Architectures• 45 Min

Design Strava (Fitness Tracking & Segment Leaderboards)

HARD

Design Strava (Fitness Tracking & Segment Leaderboards)

Strava processes millions of high-frequency GPS activity streams uploaded by athletes, automatically detecting when a user traversed a designated "Segment" (e.g. a steep hill climb) and updating competitive global leaderboards.


1. System Requirements

Functional Requirements

  1. Activity Recording & Upload: Ingest GPX / FIT files containing timestamped latitude, longitude, elevation, and heart rate telemetry.
  2. Segment Matching: Automatically detect if any portion of an activity polyline matches a crowdsourced segment.
  3. Real-time Leaderboards: Rank the fastest all-time efforts (KOM/QOM) on any segment with instant updates.
  4. Activity Feed & Kudos: Social feed showing friends' recent workouts.

Non-Functional Requirements

  1. High Ingestion Throughput: Process bursty uploads on Sunday mornings without backlog.
  2. Accurate Map Matching: Resilient against noisy GPS drift and signal drops under tree cover.
  3. Sub-Second Leaderboard Reads: Leaderboard queries must return in $< 50\text{ms}$.

2. Segment Detection Algorithm: Spatial Bounding & Polyline Frechet Distance

  1. Bounding Box Filter: Every segment has an entry bounding box and exit bounding box indexed by Geohash. If an activity doesn't intersect both, it's discarded immediately.
  2. Frechet / Hausdorff Distance: Measures similarity between the candidate GPS trajectory and the canonical segment path.
  3. Time Calculation: Interpolate exact timestamps at the start and finish lines to record elapsed time down to the hundredth of a second.

Key Architecture Trade-Offs & Decision Matrix

Decision FactorChoice AChoice BSelected Architectural Rationale
Communication ProtocolREST over HTTP/2WebSockets / gRPCUse REST for stateless CRUD APIs; use WebSockets for low-latency bidirectional streaming.
State ManagementCentralized Distributed StoreLocal Memory with Sticky SessionsCentralized Redis / Database state allows seamless container auto-scaling and zero-downtime rolling deploys.
Concurrency ControlOptimistic Locking (version column)Pessimistic Locking (SELECT FOR UPDATE)Optimistic locking delivers superior throughput for low-conflict consumer operations.