Tackling System Design Interview Problems
API Design
With the requirements clear, the next step is to define the inputs and outputs for the system. This involves outlining the API endpoints and their expected behavior. Doing so not only clarifies the data flow but also helps identify the system's read and write paths.
Short URL Service
shortenUrl()
- Input: a long Url
- Output: A shortened Url.
redirectUrl()
- input: shortened Url
- Output: HTTP 302 Redirect to the original URL.
postTweet()
- input: tweet
- output: timestamp, tweetId.
like()
- input: tweetId
- output: some kind of success message
homeFeed()
- input: userId
- output: an array of tweets
With inputs and outputs defined, map the system's read and write paths. These workflows outline how data is processed and provide a foundation for high-level design.
Short URL Service
Write Path:
- A user submits a long URL through the API.
- The system generates a unique short URL using hashing or a key-generation algorithm.
- The short-long URL mapping is stored in the database.
Read Path:
- A user accesses the short URL.
- The system queries the database to retrieve the corresponding long URL.
- The user is redirected to the original long URL.
Write Path:
- A user posts a tweet via the API.
- The tweet is stored in the database and indexed.
- The system propagates the tweet to followers’ home feed using some kind of fan-out mechanism.
Write Path:
- A user likes a tweet via the API.
- The system updates the database by increasing the like counter for that tweet.
Read Path:
- A user opens their home feed.
- The system fetches tweets from database.
- Tweets are returned to the user.
In a system, there can be multiple read and write paths, and clearly defining these is crucial for shaping the high-level design. While solutions from resources like books and blogs may provide exhaustive lists of API endpoints with detailed specifications, replicating this level of detail during an interview is neither practical nor necessary. With only 30–50 minutes to present your solution, focus on a few key API endpoints that are central to the system's functionality, especially if the problem includes a scalability challenge. Overly detailed API designs are unlikely to add value in this context.
This phase is your opportunity to analyze and understand the problem.