Templates/Social & community

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

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.