Practice/Amazon/Design Threads App
Object Oriented DesignMust
Design and implement a social media feed system where users can follow each other and view posts from people they follow. The system should support creating users, establishing follow relationships, creating posts, and generating personalized feeds.
Your implementation should handle the core operations of a social network: user management, follow/unfollow functionality, post creation, and feed generation. The feed should display posts from followed users in reverse chronological order (most recent first).
limit posts (default: 10)Example 1: Basic Follow and Feed
system = SocialFeedSystem() system.create_user("u1", "alice") system.create_user("u2", "bob") system.follow("u1", "u2") // Alice follows Bob system.create_post("u2", "Hello from Bob!") feed = system.get_feed("u1") // Returns: [Post(author="u2", content="Hello from Bob!")]
Example 2: Multiple Follows
system = SocialFeedSystem() system.create_user("u1", "alice") system.create_user("u2", "bob") system.create_user("u3", "charlie") system.follow("u1", "u2") system.follow("u1", "u3") system.create_post("u2", "Post from Bob") system.create_post("u3", "Post from Charlie") feed = system.get_feed("u1") // Returns posts from both Bob and Charlie, ordered by timestamp
Example 3: Unfollow
system = SocialFeedSystem() system.create_user("u1", "alice") system.create_user("u2", "bob") system.follow("u1", "u2") system.create_post("u2", "Message 1") system.unfollow("u1", "u2") feed = system.get_feed("u1") // Returns: [] (empty feed after unfollowing)