Activity feed (Cassandra) database schema
Each user's feed by time bucket, follower lists both ways, and like counters.
4 tables, 0 references
Opens as a new diagram you can change. Free.
Tables
feed_by_user
Posts fanned out to each follower's feed, a partition per month.
- user_iduuid not null
- buckettext not null
- posted_attimeuuid not null
- post_iduuid not null
- author_nametext
- previewtext
followers_by_user
Who follows a user.
- user_iduuid not null
- follower_iduuid not null
- sincetimestamp
following_by_user
Whom a user follows.
- user_iduuid not null
- followed_iduuid not null
- sincetimestamp
post_likes
Like counts: a counter table holds only its key and counters.
- post_iduuid not null
- likescounter
As CQL schema
The diagram also exports Sample rows (INSERT).
-- Activity feed (Cassandra): Cassandra / ScyllaDB schema.
CREATE TABLE IF NOT EXISTS feed_by_user (
user_id uuid,
bucket text,
posted_at timeuuid,
post_id uuid,
author_name text,
preview text,
PRIMARY KEY ((user_id, bucket), posted_at)
) WITH CLUSTERING ORDER BY (posted_at DESC)
AND comment = 'Posts fanned out to each follower''s feed, a partition per month.';
CREATE TABLE IF NOT EXISTS followers_by_user (
user_id uuid,
follower_id uuid,
since timestamp,
PRIMARY KEY (user_id, follower_id)
) WITH CLUSTERING ORDER BY (follower_id ASC)
AND comment = 'Who follows a user.';
CREATE TABLE IF NOT EXISTS following_by_user (
user_id uuid,
followed_id uuid,
since timestamp,
PRIMARY KEY (user_id, followed_id)
) WITH CLUSTERING ORDER BY (followed_id ASC)
AND comment = 'Whom a user follows.';
CREATE TABLE IF NOT EXISTS post_likes (
post_id uuid,
likes counter,
PRIMARY KEY (post_id)
) WITH comment = 'Like counts: a counter table holds only its key and counters.';
More Social & community templates
- Social networkProfiles, follows, posts with media, comments and likes.
- Discussion forumCategories, threads and posts with reactions and moderation reports.
- Chat / messagingDirect and group conversations, messages, attachments and read receipts.
- Dating appProfiles with photos, swipes, mutual matches, messages and blocks.
- Meetup groupsInterest groups with members, events at venues and RSVPs.
- Q&A siteQuestions, answers with votes, accepted answers and tags.
- Reviews & ratingsBusinesses reviewed by users, with photos, helpful votes and owner replies.
- Creator membershipsCreators offering paid tiers, supporters' pledges and members-only posts.
- GamificationPoints ledger, levels, badges and streaks for an engaged community.
- Mentorship programmeProgrammes matching mentors with mentees, sessions and feedback.
- Chat app (Firestore)Users, rooms with their members, and messages as a subcollection of each room.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.