Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
ER Diagram
All Database Design templates

Social Media Data Model — Mermaid ER Diagram

ER diagram for a social media platform with users, posts, comments, likes, follows, and notifications.

What this diagram shows

This Mermaid ER diagram is a social feed. A user creates posts, writes comments, gives likes, initiates follows, and receives notifications. Posts have comments, likes, and tag links. Comments store parent_id so a reply can point at another comment. Likes and follows are their own tables with a timestamp, not a boolean on the post. Tags are a many-to-many through POST_TAG. Notifications store a type, a message, and is_read.

Use it when you are splitting a feed schema and someone wants to stuff likes into a counter column only. The template keeps both: POST.like_count and a LIKE row. The counter is a cache. The row is the source for who liked it. Follows are directional. follower_id and following_id are both user foreign keys, so the relationship is not a simple one user to one user.

parent_id on COMMENT is a self foreign key. Mermaid draws COMMENT as one entity; it does not draw a second box for replies. The column is how you know threads exist.

Mermaid syntax in this template

Most user relationships are optional one-to-many (||--o{). The tag join is a pair of many-to-one edges into POST_TAG rather than a single many-to-many line.

  • USER ||--o{ FOLLOW : initiates

    The verb is initiates because FOLLOW also contains following_id. One line cannot show both directions. Read the columns.

  • uuid parent_id FK

    Self reference for threaded comments. Null parent means a top-level comment. Mermaid has no separate notation for a self-FK beyond the column.

  • POST ||--o{ POST_TAG : tagged

    POST_TAG is the join table. TAG ||--o{ POST_TAG closes the many-to-many.

  • int like_count

    Denormalized on POST next to a real LIKE entity. If you delete the entity and keep the counter, you lose the list of users.

Variations and ways to customize it

Like comments as well as posts

LIKE currently points at post_id only. Add a nullable comment_id, or a separate COMMENT_LIKE table, if the product likes replies. A single target column with a type is the other option.

LIKE {
    uuid id PK
    uuid user_id FK
    uuid post_id FK
    uuid comment_id FK
}

Block and mute

Follow is not the inverse of block. Add BLOCK with blocker_id and blocked_id. Keep it off the FOLLOW table so a row means one thing.

USER ||--o{ BLOCK : creates
BLOCK {
    uuid blocker_id FK
    uuid blocked_id FK
}

Drop the cached counts

Remove like_count and comment_count from POST if you will compute them. Leave them if the feed query cannot afford the aggregate. The diagram should match the choice so the next reader does not maintain both by accident.

Diagram type

ER Diagram

Tags

social mediapostsfollowerslikesnotifications
Open in Editor

Frequently asked questions

How are comment replies stored?

COMMENT.parent_id references another comment. A null parent is a top-level comment on the post. The post_id is still set so you can load a thread without walking parents.

Why is there both a LIKE table and like_count?

The table records who liked a post and when. like_count on POST is a cached total for the feed card. Update the counter in the same transaction as the insert or the two will drift.

Can a follow row mean a mutual friendship?

No. One FOLLOW row is follower_id to following_id. A mutual follow is two rows. Add a separate FRIENDSHIP table with a status if the product is requests and accepts rather than one-way follows.

What is POST_TAG for?

It is the many-to-many join between POST and TAG. TAG.name is unique. The join stores the two foreign keys. Put extra columns there only if a tag on a post has its own data, such as who added it.

Related templates and guides

All Database Design templates