List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
Define what APIs are expected from the system...
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
Table
`shortUrl` -> (shortURL(PK), longURL(Unique))
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
When a client submits a URL to be shortened via the POST /long/{url} endpoint, the service follows a specific sequence of operations to ensure that the URL is effectively stored and a short URL is returned. The sequence is as follows:
urlMap database table to see if the long URL already has an associated short URL.urlMap table.Below is the sequence diagram that illustrates these steps:
```mermaid
sequenceDiagram
participant C as Client
participant S as URL Shortening Service
participant DB as Database (urlMap)
C->>S: POST /long/{url}
S->>DB: Check if long URL exists
alt URL Exists
DB->>S: Return existing short URL
S->>C: Respond with short URL
else URL Does Not Exist
S->>S: Generate random 8-char short URL
S->>DB: Store new entry (shortURL, longURL)
DB->>S: Ack storage
S->>C: Respond with new short URL
end
```
When a client requests to retrieve the original long URL corresponding to a short URL via the GET /short endpoint, the service follows this sequence of operations:
urlMap database table for an entry matching the given short URL.Below is the sequence diagram illustrating these steps:
```mermaid
sequenceDiagram participant C as Client participant S as URL Shortening Service participant DB as Database (urlMap) C->>S: GET /short S->>DB: Fetch (shortURL, longURL) from urlMap alt Short URL Exists DB->>S: Return long URL S->>C: Respond with long URL else Short URL Does Not Exist DB->>S: Return not found S->>C: Respond with 404 Not Found end
```
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?