Skip to main content

Data Model (Conceptual)

This section describes the conceptual data model. Field names, data types, and implementation details are intentionally simplified and do not reflect the private source code.

Entity-Relationship Diagram


Entity descriptions

User

Represents an application account and its public profile.

FieldPurpose
idUnique identifier
usernameUnique display name
emailLogin credential (unique)
passwordHashBcrypt-hashed password (never returned in API responses)
bioOptional short biography
avatarUrlReference to profile picture
createdAtAccount creation timestamp

Post

A top-level content item created by a user.

FieldPurpose
idUnique identifier
authorIdReference to the creating user
contentText content of the post
likeCountDenormalized counter for fast reads
replyCountDenormalized counter for fast reads
createdAtTimestamp used for feed ordering

Reply

A user's response to a post.

FieldPurpose
idUnique identifier
postIdThe post being replied to
authorIdThe replying user
contentText content of the reply
createdAtTimestamp

Follow

A directed edge in the social graph: follower → following.

FieldPurpose
idUnique identifier
followerIdThe user who follows
followingIdThe user being followed
createdAtTimestamp

A unique compound index on (followerId, followingId) prevents duplicate follow relationships.


Like

Records a user's "like" on a post.

FieldPurpose
idUnique identifier
userIdThe liking user
postIdThe liked post
createdAtTimestamp

A unique compound index on (userId, postId) ensures a user can only like a post once.


Indexing strategy (high-level)

CollectionIndexPurpose
Post(authorId, createdAt DESC)List posts by a user, newest first
Post(createdAt DESC)Global timeline (future)
Follow(followerId)Get all accounts a user follows
Follow(followingId)Get all followers of a user
Follow(followerId, followingId) uniquePrevent duplicates, fast follow-status lookup
Like(userId, postId) uniquePrevent duplicates, fast like-status lookup
Like(postId)Count/list likes per post

Feed generation pattern

To build the following feed for user U:

  1. Query the Follow collection for all followingId values where followerId = U.
  2. Query the Post collection for documents where authorId IN [followingIds], sorted by createdAt DESC, with cursor-based pagination.

This "fan-out on read" approach is straightforward and works well at the current scale. A precomputed timeline (fan-out on write) would be considered if read latency becomes a concern at larger scale — see Trade-offs & Future Work.