=> Help pick the database strategy
/api/shorten{ "longUrl": "https://example.com/some/very/long/url"}{ "shortUrl": "https://short.ly/abc123", "expiration": "2023-12-31T23:59:59Z" // Optional, if you support expiration}/api/r/{shortCode}shortCode (e.g., abc123)For invalid URLs:
{ "error": "Invalid URL format"}
By following this structure, you can create a robust URL shortening API that is easy to use and understand. This design also allows for scalability and future enhancements, such as adding user accounts or custom short URLs.
The system has two main flows:
1. URL creation flow:
2. URL redirection flow:
The read path is optimised for:
latency and cache hit rate
The write path is optimised for:
durability and validation
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
Database
URL: { long_url: https://example.com/long/url/random,
short_url: short.com/abc123,
created_at: YYYYMMDD_HHMMSS,
created_by: user_id,
number_of_reads: X
}
user:
{ user_id: str,
username: str,
email : str
urls_created: list,
}
Database features:
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.