OiO.lk Blog SQL How to design database schema for sharing user content (eg tumblr reblogs)
SQL

How to design database schema for sharing user content (eg tumblr reblogs)


I’m trying to create a clone of tumblr and I want to recreate their reblog feature. However, I’m having trouble coming up with an efficient way of storing reblogs. On tumblr, users can add content to posts that they reblog. If the original poster edits the post, it does not alter the content of the reblogged posts. What’s more is that reblogs seem to form different trees. Example:

User A creates a post saying, "I like cats!"
User B reblogs this post from User A, adding, "Me too!"
User C reblogs this post from User A, adding "I do not". 
*User C's post does not include the content User B has added, only showing User A and User C's content*

It doesn’t make much sense to create two separate tables for posts and reblogs when reblogs are just posts. But I can’t figure out an efficient way to approach database design that doesn’t involve outright making copies of post content when people make reblogs while preserving the reblog behavior described above. Here’s what I have so far.

If I go the route of using one table and copying post content every time someone reblogs a post:

Posts
===
- id integer
- content string
- type enums[text, image, audio, video]
- parent_id integer
- author_id integer (only if the post is a reblog)
- created_at date



You need to sign in to view this answers

Exit mobile version