Design a home timeline (Twitter/Instagram style) that shows recent posts from accounts a user follows.
How to approach it
Design the API and data model from the user’s actions, not from the database. Name the few core endpoints, the entities and their keys/indexes, and — critically — which data must be strongly consistent versus eventually consistent. The access pattern (how you read the data) should drive the storage choice, not the other way around.
Core APIs
| Endpoint | Purpose |
|---|---|
| POST /posts | publish a post |
| GET /feed | fetch the home timeline (paged) |
| POST /follow/{userId} | follow an account |
Entities
| Entity | Keys / indexes |
|---|---|
| Post (id, author_id, body, created_at) | PK(id), index(author_id, created_at) |
| Follow (follower_id, followee_id) | index(follower_id), index(followee_id) |
| Timeline (user_id, post_ids[]) | precomputed per user (fan-out cache) |
Note
A post may appear in followers’ feeds a few seconds late — eventual consistency is fine.