Social Media Application System Design Explained With System Diagrams & Requirements

In the digital age, social media applications have revolutionized the way we connect and share information. Behind the scenes, these platforms rely on robust system designs to handle the immense user base, data storage, and real-time interactions. In this blog post, we will delve into the intricacies of designing a scalable and efficient system for a social media application. We will explore the key components, flow diagrams, functional requirements, and capacity management strategies necessary to build a successful social media platform.



system design for social media application


Requirements

Functional Requirements

Functional requirements define what a system or software application should do to meet the needs of its users.Here are the functional requirements for a social-media based system:
    • Post media
    • Like ,comment on others post
    • Follow/unfollow other users
    • User search
    • User Feed
    • Chat Feature

Non-Functional Requirements

Non-functional requirements specify the qualities or attributes of a system rather than its specific features. Here are some :
    • low latency
    • high availability
    • partition reference

Capacity

Traffic

  • 100 million downloads
  • 1M active users/day

Storage

  • Each user post twice a month
  • Size of each media file: 2MB
  • Total storage: 1M * 2MB = 2 * 10^7 MB = 2 TB/month 

High Level Design


Data Model Design 


Database schema for social media app

For brief explanation, I already have written one blog in which I have provided step by step explanation on designing such schema. Here is the (Link)..

Profile & Follower Services

In our system design, the Profile Service handles storing user information such as username, address, and age in the database. Other services can request user details from the Profile Service by passing the user ID as a parameter.

The Follower Service, on the other hand, manages the relationship between users. When a user follows another user, an API request with the user ID is sent to the Follower Service, which updates its own database. When accessing a user's profile, the Profile Service communicates with the Follower Service to retrieve the follower and following counts. Additionally, the Follower Service can retrieve user details by communicating with the Profile Service based on user IDs to display followers and following information.


Post Services & media management


Post management system arch


In a high-level design, we handle post management through three main API requests: 
  • /createPost (POST)
  • /getPost/:id (GET)
  • /updatePost/:id (POST)
These requests are routed through the API Gateway, which directs them to the Post Service. The Post Service saves the post content, user ID, and other relevant data in the database. Any accompanying files or media are uploaded to Amazon S3, a distributed object storage service. To optimize content delivery, we utilize CloudFront as a CDN layer in front of S3. The URLs of the uploaded files are stored in the database. Additionally, we can implement a URL shortener service to shorten the lengthy URLs generated by S3.

User Feed


user feed system arch



In our system, the User Feed Service is responsible for providing users with a relevant feed of posts. To achieve this, we follow a simple algorithm: we display the most recent posts from the users they follow, followed by recent posts from their followers and other relevant recommendations.

Handling millions of posts and loading thousands of posts directly in a user's feed would be costly and lead to high latency. To address this, we implement a pagination system. When a user scrolls down, the client makes an API request like /getUserFeed/:userId/?offset=10/?page=page_number, where the offset represents the number of posts to skip. By loading posts incrementally, we reduce the load on the server.

To optimize performance, we precompute the feed on the server and slice the data based on the client's request. This approach ensures that clients receive the most up-to-date posts without excessive server requests.

To keep users updated with recent posts, we establish a reference between the Profile Service and the User Feed Service. This allows us to sync user information and maintain a relevant feed.

To enhance scalability, we incorporate a distributed caching service using the Least Recently Used (LRU) cache model. The feed data is stored in the cache, and less frequently accessed posts are evicted from the cache. This approach ensures that minimal data is stored in the cache, improving system performance and scalability.


Search service

search service


Search services allows users to find other users based on their usernames. When a user makes a search request using the /search/:username API, the search service performs a search by matching the provided username with the usernames of the users the requesting user follows and their followers. Additionally, it includes other users in the search results.

To retrieve user details for the search results, the search service connects to the profile service. It fetches the necessary user information and incorporates it into the search recommendations.

To optimize performance and reduce database queries, we implement a caching mechanism. The search service stores the most frequently searched usernames in a distributed cache. This allows us to retrieve the usernames directly from the cache instead of querying the database every time, resulting in faster response times and improved efficiency.

Chat service

chat feature system design

Already wrote one article for chat based system design in which have provided brief & step by step explanation. Here is the link .



I have developed linkbook website by following similar system design.

In conclusion, designing a system for a social media application requires careful consideration of various functional components, including user management, chat functionality, post interactions, and more. By implementing scalable solutions such as API gateways, load balancers, distributed caching, and efficient database structures, we can ensure high performance, reliability, and scalability. Understanding the intricacies of system design is crucial for building a robust social media platform that can handle millions of users and their interactions seamlessly.




Post a Comment

0 Comments