a long URL and receive a shortened URL
after which they no longer work.
In terms of database and storage:
Total size per URL = 20 + 10 + 10 = 40 bytes
If we expect that each request to the URL shortening service would require:
POST /shorten{ "longUrl": "http://example.com/some/very/long/url", "customAlias": "myCustomAlias" // optional}{ "shortUrl": "http://short.ly/abc123"}GET /{shortCode}GET /analytics/{shortCode}{ "shortUrl": "http://short.ly/abc123", "clickCount": 150, "createdAt": "2023-01-01T00:00:00Z", "lastAccessedAt": "2023-01-15T12:00:00Z"}PUT /shorten/{shortCode}{ "longUrl": "http://example.com/new/long/url"}{ "message": "URL updated successfully"}DELETE /shorten/{shortCode}To visualize the flow of using these APIs, consider the following sequence diagram:
sequenceDiagram
participant U[User] participant S[API Server] participant DB[Database] U->>S: POST /shorten S->>DB: Store longUrl and generate shortCode DB-->>S: Response with shortCode S-->>U: Return shortUrl U->>S: GET /{shortCode} S->>DB: Retrieve longUrl DB-->>S: Return longUrl S-->>U: Redirect to longUrl U->>S: GET /analytics/{shortCode} S->>DB: Get URL analytics DB-->>S: Response with analytics data S-->>U: Return analytics data
This diagram shows the interaction between the user, API server, and database during URL shortening, redirection, and analytics retrieval.
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...
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...
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?