My first instinct was a single map from follower to a set of followees, and the interviewer immediately asked how I'd get all followers of a given user efficiently.
Start by clarifying requirements and scale, then propose a graph-based data model with adjacency lists for both directions. Discuss trade-offs between in-memory and distributed storage, and outline core operations with their time/space complexities.
Pro tip: Demonstrate awareness of real-world constraints at Uber's scale by discussing sharding strategies and hot-key mitigation for celebrity users, showing you think beyond basic data structures.
Ask about expected scale (users, follows), read/write patterns, latency requirements, and consistency needs. Confirm if the system needs to be distributed or can be a single-node service.
Propose a graph model with two adjacency lists: one for following and one for followers. Discuss using hash maps or sets for O(1) average-time operations.
Outline methods: follow(userA, userB), unfollow(userA, userB), getFollowing(user), getFollowers(user), and isFollowing(userA, userB). Specify return types and error handling.
Compare in-memory vs. persistent storage, and discuss sharding, replication, and caching for scalability. Mention time/space complexity for each operation.
Explain how to partition data (e.g., by user ID) and handle hot spots (e.g., celebrity users) using techniques like consistent hashing or read replicas.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.