Open In App

Designing TikTok | System Design

TikTok, the globally acclaimed video-sharing platform, enchants audiences with its short, captivating content. Behind this phenomenon lies a sophisticated system meticulously designed to handle vast user-generated videos, likes, and personalized recommendations. From video uploads to tailored feeds, TikTok’s design weaves together smart technologies and algorithms, ensuring a seamless experience.



1. What is TikTok?

TikTok is a social Media Platform that is used to make a variety of short-form videos, from genres like dance, comedy, and education, that have a duration of 15 seconds to one minute. The app, developed by the Chinese company ByteDance, gained widespread popularity for its user-friendly interface and the ability to easily create and share engaging content.



2. Requirements for TikTok System Design

2.1 Functional Requirements for TikTok System Design

2.2 Non-Functional Requirements for TikTok System Design

3. Capacity Estimation of TikTok System Design

To estimate the scale of the system and to get the idea about the storage requirements, we have to make some assumptions about the data queries and the average size of videos uploaded.

3.1 Traffic Estimate

Monthly Active Users (MAU): 1 billion
Daily Active Users (DAU): 50% of MAU = 500 million
Daily Video Uploads: 50 Million
Requests Per Second (RPS): 500 million/ 24*60*60 = 5,787
Peak RPS: 2*RPS: 11,574.

Assuming each active user uploads one video per day on average is 500 million daily active users * 30 days 15 billion videos per month

3.2 Storage Estimation

Average user profile size: 1MB
Total User Profiles Storage: 1 billion * 1 MB = 1 Petabyte (PB)
Average Video Metadata: 500 KB
Daily Video Metadata Storage: 50 million * 500 KB = 25 Terabytes (TB)
Monthly Video Metadata Storage: 25 TB * 30 days = 750 TB
Average Video size: 20MB.
Total Video Streams Storage: 50 million * 20 MB = 1 Petabyte (PB) daily
Monthly Video Streams Storage: 1 PB * 30 days = 30 PB

3.3 Interactions Data

Likes, Comments, Shares: Assuming an average interaction size of 100 bytesEstimated Interactions Storage, Considering 10 interactions per video view:

Daily Interactions Storage: 500 million * 10 * 100 bytes = 500 GB
Monthly Interactions Storage: 500 GB * 30 days = 15 TB

3.4 Bandwidth Estimation

Assuming Average Video Size: 20 MB (high-definition content)
Daily Video Streaming Bandwidth: 50 million * 20 MB = 1 PB daily
Monthly Video Streaming Bandwidth: 1 PB * 30 days = 30 PB

4. Use Case Diagram for TikTok System Design

For the TikTok-like application, there are two distinct user scenarios:

TikTok is a complex platform with additional features, such as comments, likes, sharing, following, and various discovery mechanisms.

5. Low-Level Design(LLD) for TikTok System Design

Designing the low-level architecture for TikTok involves multiple components working together to deliver the desired functionalities efficiently. Here’s an outline of the low-level design:

5.1 User Authentication:

5.2 User Profile Handling:

5.3 Video Upload:

5.4 Comment and Interaction:

5.5 Cache:

5.6 Content Optimization:

5.7 Notification:

5.8 Messaging:

5.9 Recommendation:

Utilizes machine learning models to predict user preferences and curate personalized feeds for users.

5.10 Feed Generation:

5.11 Structured Database:

5.12 NoSQL Database:

5.13 Moderation Services:

5.14 Security Measures:

This low-level design encompasses various services, databases, and components working cohesively to handle user interactions, content management, optimization, and security measures within the TikTok-like platform.

6. High Level Design for TikTok System Design

At a high level, the design should handle two main tasks.

6.1 Video Uploading Process:

6.2 Video Streaming Process:

We’ll need the following components:

7. Database Design for TikTok System Design

Database Design for TikTok System Design

Below is the explanation of the above database design:

7.1 Users Database




{
UserID (Primary Key)
Username
Email
Password (Hashed)
Profile Picture URL
Bio
Registration Date
}

7.2 Social Graph




{
UserID (Primary Key)
Follower IDs (Array/Map)
Following IDs (Array/Map)
Additional Graph Information
}

7.3 Videos Database




{
VideoID (Primary Key)
UserID (Foreign Key to Users)
Title
Description
Upload Date
Views Count
Duration
Other Metadata
}

7.4 Interactions Database




{
LikeID (Primary Key)
UserID (Foreign Key to Users)
VideoID (Foreign Key to Videos)
Timestamp
Additional Like Information
}




{
DislikeID (Primary Key)
UserID (Foreign Key to User)
VideoID (Foreign Key to Video)
Timestamp
}




{
CommentID (Primary Key)
UserID (Foreign Key to Users)
VideoID (Foreign Key to Videos)
Comment Text
Timestamp
Additional Comment Information
}

8. Types of Databases used in TikTok Design

8.1 Relational Databases (PostgreSQL):

Usage: PostgreSQL databases are utilized for storing structured data, such as user profiles, relationships, and video metadata.

Significance: Relational databases ensure data consistency and integrity, making them ideal for handling transactional data and maintaining user-related information efficiently.

8.2 NoSQL Databases (Cassandra and Redis):

Usage: NoSQL databases, likeRedis and Cassandra, are utilized for handling unstructured or semi-structured data, such as user interactions (likes, comments, shares) and scalable storage of videos.

Significance: NoSQL databases excel in scalability and flexibility, allowing TikTok to handle vast volumes of user-generated content and interactions while ensuring high performance.

8.3 Blob Storage (Cloud-based Object Storage):

Usage: Cloud-based object storage solutions like Amazon S3 or Google Cloud Storage are employed for storing video content in its original form.

Significance: Blob storage offers scalable and durable storage for multimedia content, ensuring that videos are stored securely and can be accessed reliably.

9. API Used for Communicating with the servers in TikTok System Design

The RESTful API stands as an ideal choice within TikTok’s system due to its suitability for distributed, scalable, and diverse interactions across a myriad of functionalities. It’s flexibility aligns perfectly with TikTok’s dynamic nature, accommodating diverse client devices, scaling to handle the platform’s exponential growth, and offering a reliable foundation for handling the vast array of user interactions and content deliveries.

9.1 User Management

User Registration

Create a new user account with username, email, password, etc.




Endpoint: 'POST /api/users/register'




{
  "username": "Salik_Alim",
  "email": "user123@example.com",
  "password": "securePassword123"
  // Other user details
}

9.2 User Authentication

User Login

Authenticate user credentials and generate a token for access.




Endpoint: 'POST /api/users/login'




{
  "email": "user123@example.com",
  "password": "securePassword123"
}

9.3 Video Handling

Video Upload

Upload a new video with metadata and content.




Endpoint: 'POST /api/videos/upload'




{
  "title": "Funny Moments",
  "description": "A hilarious compilation",
  // Other video metadata
}

9.4 Video Interaction

9.4.1 Like

Allow users to like a specific video.




Endpoint: 'POST /api/videos/:videoID/like'




{
  "user_id": "987654"
}

9.4.2 Dislike

Allow users to dislike a specific video.




Endpoint: 'POST /api/videos/:videoID/dislike'




{
  "user_id": "987654"
}

9.4.3 Comment

Post a comment on a particular video.




Endpoint: 'POST /api/videos/:videoID/comment'




{
  "user_id": "987654",
  "text": "Great video!"
}

9.4.4 Video Retrieval

Get details and metadata of a specific video.




Endpoint: 'GET /api/videos/:videoID'

Retrieve videos uploaded by a specific user




Endpoint: 'GET /api/videos/:userID'

9.4.5 Fetch trending videos




Endpoint: 'GET /api/videos/trending'

9.5 Social Interactions

9.5.1 Follow a specific user




Endpoint: 'POST /api/users/:userID/follow'




{
  "follower_id": "456"
}

9.5.2 Unfollow a user




Endpoint: 'DELETE /api/users/:userID/unfollow'




{
  "follower_id": "789"
}

9.5.3 Messaging: Send a message to another user.




Endpoint: 'POST /api/messages/send'




{
  "sender_id": "123",
  "recipient_id": "456",
  "message": "Hey, how are you?"
}

9.6 Content Discovery

9.6.1 Feed Generation

Retrieve personalized feed for a user.




Endpoint: 'GET /api/feed/:userID'

Fetch recommended content based on user preferences.




Endpoint: 'GET /api/discover'

10. Microservices used in TikTok System Design

Microservices Used in TikTok System Design

10.1 Authentication Services

It authenticates user identities and assigns unique userIDs upon successful verification, enabling personalized experiences within the platform.

10.2 Video Upload Services

The request for uploading videos is directed to Video Upload Services.Leveraging WebSocket connections, this service allows real-time progress tracking during uploads, providing users with immediate feedback on their upload status.

Which Technologies we use for Video Upload in TikTok?

For instance, technologies like Socket.IO facilitate bidirectional communication, ensuring continuous updates on upload progress. This seamless experience ensures users can monitor and engage with their uploads more effectively.

10.3 Primary Storage (Blob Storage):

The original video is then stored in the Primary Storage, which uses blob storage systems to efficiently and securely store uploaded videos. Employing cloud-based solutions such as Amazon S3 or Azure Blob Storage, it ensures scalability and reliability in storing vast amounts of user-generated content.

Example:

Videos are stored as objects in Amazon S3 buckets, ensuring durability and accessibility across the platform. Upon successful upload, notification is sent to the user about the upload.

10.4 Encoder/Transcoder Services:

Encoder Services play a vital role in optimizing videos for seamless streaming. Utilizing tools like FFmpeg, it converts uploaded videos into various formats and bitrates suitable for different devices. These services ensure that videos are transcoded effectively, enabling smooth playback across a range of devices and network conditions.

10.5 Recommendation Services:

At the heart of personalized content delivery lies the Recommendation Services. Powered by machine learning algorithms, these services curate tailored content feeds for users based on their preferences and interactions. These algorithms analyze user behavior and preferences, employing collaborative filtering or content-based recommendation systems to suggest videos that align with user interests.

10.6 Fanout Services:

Fanout Services are responsible for efficiently distributing uploaded videos to users’ feeds, ensuring a personalized experience. Employing a hybrid strategy combining push and on-demand models, TikTok ensures effective content distribution. Technologies like Kafka or RabbitMQ aid in distributing video notifications based on user activity, ensuring timely and relevant content delivery.

10.7 Cache (Redis):

The Cache services play a crucial role in optimizing content delivery by storing personalized feeds, metadata, and trending content. Utilizing Redis as an in-memory data store, it caches frequently accessed data, reducing latency for users accessing personalized feeds and trending videos.

11. Scalability in TikTok System Design

Scalability in TikTok’s design is facilitated through various mechanisms:

This scalable architecture enables TikTok to accommodate growing user bases and surges in activity while maintaining a responsive and efficient platform.


Article Tags :