Design a Mobile Sleep-Tracking App

Mobile sleep tracking has gone from gimmick to mainstream — Apple Health, Fitbit, Oura Ring, Whoop, and dozens of dedicated apps capture sleep data nightly. The interview is multidisciplinary: sensor integration, signal processing, ML for sleep-stage classification, and the privacy / battery tradeoffs of always-on health monitoring.

Functional requirements

  • Detect when user falls asleep / wakes up
  • Track sleep stages (light, deep, REM)
  • Monitor heart rate variability
  • Show trends over time
  • Smart alarm: wake during light sleep window

Sources of data

  • Phone on bedside / under pillow: accelerometer detects motion; microphone detects sounds
  • Wearable (Apple Watch, Whoop, Oura Ring): motion, heart rate, skin temperature
  • Bed sensor (Withings, Eight Sleep): ballistocardiography from underneath the mattress

Wearables provide the richest data; phone-only is a degraded experience but accessible.

Sleep stage classification

Inputs combined to classify sleep stages:

  • Heart rate (lowest in deep sleep, fluctuating in REM)
  • Heart rate variability (HRV)
  • Motion (least in deep sleep, sometimes paradoxically still in REM)
  • Skin temperature (drops during sleep)

ML model (typically a time-series classifier) outputs stage every 30 seconds.

Smart alarm

User sets a target wake time and a window (e.g., 7:00–7:30 AM). Within the window:

  • Algorithm watches for transitions to lighter sleep
  • Wakes user during a light-sleep window — feels less groggy
  • Falls back to target time if no light-sleep window detected

Battery

For phone-on-nightstand tracking, battery during sleep:

  • ~20-30% of overnight battery on motion-only mode
  • More if microphone is active
  • Recommend charging during sleep

For wearable-based tracking: built for low power; minimal battery impact.

HealthKit / Health Connect integration

Write sleep data to platform health stores:

  • iOS: HKCategoryTypeIdentifierSleepAnalysis
  • Android: Health Connect SleepSessionRecord

This makes data available to other apps the user has authorized.

Visualization

Common patterns:

  • Hypnogram showing stages over the night
  • Weekly / monthly trend lines
  • Comparison vs your baseline
  • Correlations: how sleep affects mood, performance, illness

Privacy

Sleep data is highly personal. Considerations:

  • Default to local storage; opt-in to cloud sync
  • Don’t share sleep data with marketing partners
  • Make export and deletion easy (GDPR / CCPA)
  • Microphone-based tracking has additional privacy concerns

Common gotchas

  • User co-sleeps with partner — motion gets contaminated
  • Cat on the bed — motion gets contaminated
  • Phone falls off the bed — tracking corrupted
  • User wakes briefly to use bathroom — counted as awake

Robust apps handle these gracefully.

Frequently Asked Questions

How accurate are phone-based sleep trackers?

Total sleep time: pretty accurate (within 10–15 minutes typically). Sleep stages: less accurate without heart-rate data; mostly heuristic.

Why do sleep trackers disagree with each other?

Different sensors, different algorithms. No standardized ground truth. Polysomnography (clinical sleep study) is the gold standard but inaccessible.

What is the battery impact of overnight tracking?

For wearables: minimal. For phone: 20-30% overnight. Charge while you sleep.

Scroll to Top