Requirements


Functional Requirements:


  • Allow users to tweet messages up to 140 characters.
  • Enable users to follow other users.
  • Allow users to like tweets from other users.
  • Display tweets from followed users in the home feed.
  • Show top K popular tweets in the home feed based on likes and followers.



Non-Functional Requirements:


  • User facing surfaces must be minimally latency bound.
  • Privileged gateways/authentication for features
  • Graph based/ranking algorithm for feeds
  • Permission system for users (group based, rbac, etc)
  • Support high throughput/spikes during events
  • Event driven (another user likes tweet, the user who got liked should surface the notif, push based)
  • Durable persistence with hot storage


API Design

Rest Api for basic user functions

  • Authentication services (POST)
  • Session handling (cookie issuage, revokation, ttl)
  • Post tweet (POST)
  • Navigate to page/profile/tweet (GET)
  • Send like (POST)
  • Revise user profile (PATCH)
  • Follow (POST)

Event driven substrate

  • Pub sub triggers
  • Async handling/routing
  • Session heuristics (Notifs, messages, follows)
  • Media (chunking/sse, audio, etc)

For REST api, something like Django WSGI or even better Nodejs, or Golang would handle the immediate customer api surface. For system functional API, these are not interfaced directly by the user but are exposed and essential for clientside operations.


Serverside, websockets and SSE should be set up. Websockets for persistenc connections if needed, like chat communications etc. SSE is fine for push based events, such as surfacing a like.

These can be done either in Django WSGI facilitated by daphne or uvicorn for example.



High-Level Design

The initial customer serving api will be a designated service. This includes the API. Delegation of domain specific functionality will be routed via cache (redis) or something like NATS jetstream/kafka to the respective microservices.


  • Policy gateways (PDP/IAM) these are their own substrate.
  • Ranking algorithm for feed.
  • Tweet domain subsystems (persist and store tweet, likes + metadata on tweets, etc)
  • Graph service for follows and connectional heirarchy/recommendations.


Detailed Component Design

Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.