Designing a Database for Social Media Platform (original) (raw)

Last Updated : 4 Dec, 2025

Social media platforms are now essential for networking, content sharing, and communication. A complex database design for Social Media Platforms has been created to manage enormous volumes of data with optimal performance and scalability.

In this article, We will explore the key elements and recommended procedures for creating a solid database that is suited for social media platforms in this extensive tutorial.

A social media platform database needs to manage various entities such as users, posts, comments, likes, friendships, and messages. It should support functionalities such as user authentication, content sharing, real-time updates, notifications, and personalized recommendations.

By designing a database that addresses these requirements, social media platforms can provide a seamless user experience and facilitate meaningful interactions among users.

Entities serve as the building blocks of our database, representing the fundamental objects or concepts that need to be stored and managed. Attributes define the characteristics or properties of each entity. Let’s explore each entity and attribute in detail

User: Represents individual users registered on the platform.

Post: Represents individual posts shared by users on the platform.

Friendship: Represents mutual friendships between users.

Message: Represents private messages sent between users.

follows: Represents the following relationship between users.

Relationships Between these Entities

User – Post Relationship

User – Like Relationship

Friendship Relationship

User – Message Relationship

User – follows Relationship

Entities Structures in SQL Format

CREATE TABLE User ( UserID INT PRIMARY KEY, Username VARCHAR(50) UNIQUE, Email VARCHAR(100) UNIQUE, Password VARCHAR(255), Name VARCHAR(100), Bio TEXT, ProfilePicture VARCHAR(255) );

CREATE TABLE Post ( PostID INT PRIMARY KEY, UserID INT, Content TEXT, MediaType VARCHAR(20), MediaURL VARCHAR(255), Timestamp TIMESTAMP, FOREIGN KEY (UserID) REFERENCES User(UserID) );

CREATE TABLE Comment ( CommentID INT PRIMARY KEY, PostID INT, UserID INT, Content TEXT, Timestamp TIMESTAMP, FOREIGN KEY (PostID) REFERENCES Post(PostID), FOREIGN KEY (UserID) REFERENCES User(UserID) );

CREATE TABLE Like ( LikeID INT PRIMARY KEY, PostID INT, CommentID INT, UserID INT, Timestamp TIMESTAMP, FOREIGN KEY (PostID) REFERENCES Post(PostID), FOREIGN KEY (CommentID) REFERENCES Comment(CommentID), FOREIGN KEY (UserID) REFERENCES User(UserID) );

CREATE TABLE Friendship ( FriendshipID INT PRIMARY KEY, UserID1 INT, UserID2 INT, Timestamp TIMESTAMP, FOREIGN KEY (UserID1) REFERENCES User(UserID), FOREIGN KEY (UserID2) REFERENCES User(UserID) );

CREATE TABLE Message ( MessageID INT PRIMARY KEY, SenderID INT, ReceiverID INT, Content TEXT, Timestamp TIMESTAMP, FOREIGN KEY (SenderID) REFERENCES User(UserID), FOREIGN KEY (ReceiverID) REFERENCES User(UserID) );

CREATE TABLE follows ( following_user_id INT, followed_user_id INT, created_at TIMESTAMP, FOREIGN KEY (following_user_id) REFERENCES User(UserID), FOREIGN KEY (followed_user_id) REFERENCES User(UserID) );

Social_Media_DB