Social Media Database Schema database schema
The Social Media Database Schema database schema is a DB Planner template with 35 tables, 203 columns and 66 relationships, free to use. Core tables include blocks, bookmarks, comment_likes, comments. It can be opened as an interactive diagram or exported as PostgreSQL, MySQL, or MSSQL DDL.
- Tables
- 35
- Columns
- 203
- Relationships
- 66
- Category
- Social
- Exports
- DBML, SQL, C#
- Price
- Free
What this schema models
A social network database schema modelled on how real platforms are actually built. 35 tables, 13 enums and 66 relationships covering identity and sessions, a directed follow graph with blocks and mutes, threaded posts with media and hashtags, likes, reposts and bookmarks, comments, polls, expiring stories, group and direct messaging, materialised feeds, notification preferences, groups, and a full trust-and-safety pipeline. THE THREE RULES 1. The graph is DIRECTED. follows is one-way and mutual following is two rows. blocks and mutes are separate concepts with different semantics: a block is mutual invisibility that should also tear down the follow rows, while a mute is invisible to the muted user, leaves the follow intact, and only filters the feed. Getting this wrong is the single most common mistake in social schema design. 2. Engagement is a ROW, never a counter. post_likes, reposts and bookmarks are tables with composite primary keys, which makes a like idempotent, un-doable and auditable. The count columns on posts are explicitly denormalised caches, rebuildable from those tables. 3. The feed is MATERIALISED. feed_entries is written on fan-out rather than computed by joining the graph at read time, because a query that walks follows on every page load is exactly the thing that stops scaling. It also stores WHY a post is in the timeline (followed, reposted, group, recommended) plus the source user, which is what lets the UI explain itself. OTHER DETAILS WORTH STEALING - users holds the handle and credentials; profiles is a one-to-one split out because it is read on every profile view and written far more often. A rename never touches the auth row. - posts self-references for threads AND carries a nullable group_id, so one table serves the public timeline and every group. There is no separate group_posts table. - Comments are deliberately NOT posts: they are never independently followable and never enter fan-out. - Message read state is a high-water mark per participant, not a row per message, so unread count is a cheap range query. - Stories write expires_at at creation rather than inferring it, and the index on that column is what lets a sweeper reap expired rows cheaply. - A suspension is a row in moderation_actions with an expires_at, not a boolean flag on users, so the history survives an appeal. - Mentions and hashtags are extracted at write time, so the mentions tab and tag pages are plain index lookups instead of text scans. WHAT YOU GET Clean DBML that imports straight into DB Planner, plus a laid-out board with cards colour-coded by zone — identity, graph, content, engagement, ephemeral, messaging, delivery, groups and trust & safety — with sticky notes explaining each design decision and every table carrying its own Note. Postgres-flavoured types that port cleanly to MySQL or SQL Server. Useful for developers building a social app, students who need a realistic social network ER diagram for a DBMS project, and teams designing feed and notification infrastructure for the first time.
Tables (35)
| Table | Columns |
|---|---|
| blocks | 3 |
| bookmarks | 3 |
| comment_likes | 3 |
| comments | 9 |
| conversation_participants | 6 |
| conversations | 6 |
| feed_entries | 7 |
| follows | 4 |
| group_members | 4 |
| groups | 8 |
| hashtags | 4 |
| list_members | 3 |
| lists | 6 |
| message_attachments | 6 |
| message_reads | 4 |
| messages | 8 |
| moderation_actions | 9 |
| mutes | 3 |
| notification_preferences | 5 |
| notifications | 8 |
| poll_options | 4 |
| poll_votes | 3 |
| polls | 5 |
| post_hashtags | 2 |
| post_likes | 3 |
| post_media | 10 |
| post_mentions | 2 |
| posts | 14 |
| profiles | 9 |
| reports | 9 |
| reposts | 5 |
| sessions | 9 |
| stories | 7 |
| story_views | 3 |
| users | 9 |
Relationships (66)
blocks.blocked_id references users.idmany to oneblocks.blocker_id references users.idmany to onebookmarks.post_id references posts.idmany to onebookmarks.user_id references users.idmany to onecomment_likes.comment_id references comments.idmany to onecomment_likes.user_id references users.idmany to onecomments.author_id references users.idmany to onecomments.parent_comment_id references comments.idmany to onecomments.post_id references posts.idmany to oneconversation_participants.conversation_id references conversations.idmany to oneconversation_participants.user_id references users.idmany to oneconversations.created_by references users.idmany to onefeed_entries.post_id references posts.idmany to onefeed_entries.source_user_id references users.idmany to onefeed_entries.user_id references users.idmany to onefollows.followee_id references users.idmany to onefollows.follower_id references users.idmany to onegroup_members.group_id references groups.idmany to onegroup_members.user_id references users.idmany to onegroups.owner_id references users.idmany to onelist_members.list_id references lists.idmany to onelist_members.user_id references users.idmany to onelists.owner_id references users.idmany to onemessage_attachments.message_id references messages.idmany to onemessage_reads.conversation_id references conversations.idmany to onemessage_reads.last_read_message_id references messages.idmany to onemessage_reads.user_id references users.idmany to onemessages.conversation_id references conversations.idmany to onemessages.reply_to_id references messages.idmany to onemessages.sender_id references users.idmany to onemoderation_actions.moderator_id references users.idmany to onemoderation_actions.report_id references reports.idmany to onemoderation_actions.target_post_id references posts.idmany to onemoderation_actions.target_user_id references users.idmany to onemutes.muted_id references users.idmany to onemutes.muter_id references users.idmany to onenotification_preferences.user_id references users.idmany to onenotifications.actor_id references users.idmany to onenotifications.comment_id references comments.idmany to onenotifications.post_id references posts.idmany to onenotifications.user_id references users.idmany to onepoll_options.poll_id references polls.idmany to onepoll_votes.poll_option_id references poll_options.idmany to onepoll_votes.user_id references users.idmany to onepolls.post_id references posts.idmany to onepost_hashtags.hashtag_id references hashtags.idmany to onepost_hashtags.post_id references posts.idmany to onepost_likes.post_id references posts.idmany to onepost_likes.user_id references users.idmany to onepost_media.post_id references posts.idmany to onepost_mentions.post_id references posts.idmany to onepost_mentions.user_id references users.idmany to oneposts.author_id references users.idmany to oneposts.group_id references groups.idmany to oneposts.parent_post_id references posts.idmany to onereports.comment_id references comments.idmany to onereports.post_id references posts.idmany to onereports.reported_user_id references users.idmany to onereports.reporter_id references users.idmany to onereposts.post_id references posts.idmany to onereposts.user_id references users.idmany to onesessions.user_id references users.idmany to onestories.author_id references users.idmany to onestory_views.story_id references stories.idmany to onestory_views.viewer_id references users.idmany to oneusers.id references profiles.user_idone to one
How to use this template
- Open the diagram to see the tables and how they relate.
- Copy it into your workspace. You get your own editable copy.
- Export it as PostgreSQL, MySQL, or MSSQL DDL, or as C# models.
Frequently asked questions
- What is in the Social Media Database Schema schema?
- 35 tables and 66 relationships, across 203 columns. The table names and the full relationship list are shown on this page.
- Can I export it to PostgreSQL or MySQL?
- Yes. Every DB Planner template exports as DBML, PostgreSQL, MySQL, or MSSQL DDL, and as C# models.
- Is this template free?
- Yes. You can open it in the browser without an account, and copy it into your own workspace with a free DB Planner account.
- Can I change it after copying it?
- Yes. A copy is yours: you can rename tables, add columns, and export it. Changes the author makes later do not affect your copy.