Requirements

  • TikTok is a mobile app
  • User can upload a video
  • User can have feed of videos
  • User can follow other users
  • User can perform actions on videos:
    • Like them
    • comment on them
  • Videos:
    • length: can be 30s to 1 min
    • metadata: tags/description/comment/caption
  • User Feed:
    • only videos from the people I follow?
    • videos from recommendation algo?
    • trending videos?
    • mix of the above?
  • Non-Functional Requirements:
    • Availability: Highly available (99.999% — 5 9s)
    • Latency??
    • Scale: million daily active users (DAUs)

Estimates

  • 60min video ~ 5 MB
  • Each user uploads 2 videos per day 10MB per day per user
  • User metadata: 1k per user per day

Design

  • Endpoints:
    • uploadVideo
      • Need some Blob Storage like S3 or Az Blob Storage
      • store in DB + Blob Storage
    • viewFeed
      • read data from cache
    • userActivity
      • to perform likes, comments
  • Table:
    • userId: uuid
    • video_link: url
    • video_id: uuid
    • meta: string
  • DB: relational database
    • Postgres or Mysql
  • We can make use of cache like redis to store the top 10 from news feed
  • We will have a pre-cache service, which will get the data from DB
    • scheduled
    • on demand
  • system is read-heavy, so we might need a read worker which will be read only database
  • Table:
    • userId: uuid
    • following: fk
    • likes: fk

Followups

  • If scale is 10x
  • generally scaling need to consider for example if somebody famous with lots of followers send out a video
  • Services bottleneck:
    • Regions and geolocating and cdn to improve latency
    • Load Balancer
  • Database bottleneck:
    • Sharding when doing writes
      • based on region? or some other parameter?
    • use of read replica
    • autoscaling