Knowledge Guide
HomeDatabasesNormalization

Designing an Instagram

Instagram is a platform where users share content, interact with others through likes, comments, and messages, and manage their profiles. This guide will model its core functionalities in a step-by-step fashion, ensuring efficient and scalable database design.

In this case study, we’ll design a database for Instagram using Entity-Relationship (ER) modeling and map it to a relational schema. By the end, you’ll have a clear understanding of how Instagram’s core functionalities are structured through database design.

Requirements Analysis

For our case study, let's outline the key functionalities that the HMS should support:

Step-by-Step ER Diagram Creation

We will build the ER diagram for the Hospital Management System through the following four steps.

Step 1: Identify Entities

Entities represent objects or concepts in the system that have data stored about them.

  1. User
  2. Post
  3. Comment
  4. Like
  5. Direct_Message
  6. Notification
  7. Group
  8. Profile_Info
  9. Profile_Dashboard
Entities for an Instagram
Entities for an Instagram

Step 2: Detailing Attributes

1. User

2. Post

3. Comment

4. Like

5. Direct_Message

6. Notification

7. Group

8. Profile_Info

9. Profile_Dashboard

Attributes for an Instagram System
Attributes for an Instagram System

Step 3: Defining Relationships

1. User and Post

2. Post and Comment

3. Post and Like

4. User Follows Other Users

5. User and Comment

6. User and Like

7. User and Direct_Message

8. User and Notification

9. User and Group

10. User and Profile_Info

11. User and Profile_Dashboard

Here is the final ER diagram.

ER Diagram for Bank Management System
ER Diagram for Bank Management System

Mapping the ER Diagram to a Relational Schema

When converting the ER diagram into a relational schema for an instagram, we need to carefully handle various components to ensure data integrity and optimal performance. Here are the key considerations:

Here is the final relational schema diagram for Instagram.

Relational Schema Diagram for the Instagram
Relational Schema Diagram for the Instagram

Now, let's translate the ER model into SQL tables.

1. User Table

CREATE TABLE User ( User_ID INT PRIMARY KEY, Username VARCHAR(50) UNIQUE, Full_Name VARCHAR(100), Email VARCHAR(100), Phone_Number VARCHAR(15), Date_Joined DATE, Profile_Picture VARCHAR(255) );

2. Post Table

CREATE TABLE Post ( Post_ID INT PRIMARY KEY, Caption TEXT, Post_Date DATE, User_ID INT, FOREIGN KEY (User_ID) REFERENCES User(User_ID) );

3. Comment Table

CREATE TABLE Comment ( Comment_ID INT PRIMARY KEY, Text TEXT, Comment_Date DATE, User_ID INT, Post_ID INT, FOREIGN KEY (User_ID) REFERENCES User(User_ID), FOREIGN KEY (Post_ID) REFERENCES Post(Post_ID) );

4. Like Table

CREATE TABLE Like ( Like_ID INT PRIMARY KEY, User_ID INT, Post_ID INT, FOREIGN KEY (User_ID) REFERENCES User(User_ID), FOREIGN KEY (Post_ID) REFERENCES Post(Post_ID) );

5. Follow Table

CREATE TABLE Follow ( Follow_ID INT PRIMARY KEY, Follower_ID INT, Followed_ID INT, FOREIGN KEY (Follower_ID) REFERENCES User(User_ID), FOREIGN KEY (Followed_ID) REFERENCES User(User_ID) );

6. Direct_Message Table

CREATE TABLE Direct_Message ( Message_ID INT PRIMARY KEY, Message_Text TEXT, Sent_Date DATE, Sender_ID INT, Recipient_ID INT, FOREIGN KEY (Sender_ID) REFERENCES User(User_ID), FOREIGN KEY (Recipient_ID) REFERENCES User(User_ID) );

7. Notification Table

CREATE TABLE Notification ( Notification_ID INT PRIMARY KEY, Notification_Text TEXT, Notification_Date DATE, User_ID INT, FOREIGN KEY (User_ID) REFERENCES User(User_ID) );

8. Group Table

CREATE TABLE Group ( Group_ID INT PRIMARY KEY, Group_Name VARCHAR(100), Description TEXT, Created_By INT, FOREIGN KEY (Created_By) REFERENCES User(User_ID) );

9. Group_Member Table

CREATE TABLE Group_Member ( Group_ID INT, User_ID INT, Join_Date DATE, PRIMARY KEY (Group_ID, User_ID), FOREIGN KEY (Group_ID) REFERENCES Group(Group_ID), FOREIGN KEY (User_ID) REFERENCES User(User_ID) );

10. Profile_Info Table

CREATE TABLE Profile_Info ( User_ID INT PRIMARY KEY, Bio TEXT, Website VARCHAR(100), Number_of_Posts INT, Number_of_Followers INT, Number_of_Following INT, FOREIGN KEY (User_ID) REFERENCES User(User_ID) );

11. Profile_Dashboard Table

CREATE TABLE Profile_Dashboard ( User_ID INT PRIMARY KEY, Total_Likes INT, Total_Comments INT, Total_Groups_Joined INT, Total_Posts_Shared INT, FOREIGN KEY (User_ID) REFERENCES User(User_ID) );
🤖 Don't fully get this? Learn it with Claude

Stuck on Designing an Instagram? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Designing an Instagram** (Databases) and want to truly understand it. Explain Designing an Instagram from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Designing an Instagram** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Designing an Instagram** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Designing an Instagram** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes