Good progress! Let's analyze your high-level design so far:
API Design
Your API endpoints make sense conceptually:
shortenURL(String longURL, String apiKey) ✅
redirectToOriginalURL(String shortURL, String apiKey) ⚠️
Quick note on the second endpoint: In practice, redirection wouldn't typically be an API call with parameters. Instead, it would be implemented as a web server route that handles HTTP GET requests and returns 301/302 redirects. Users would simply click on or enter the short URL in their browser.
Example: GET https://tinyurl.com/abc123 → HTTP 302 → Original URL
Database Design
Your choice of a key-value store like DynamoDB is excellent for this use case:
- You correctly identified that ACID transactions aren't critical here
- The 1:1 mapping nature fits perfectly with key-value stores
- DynamoDB offers high throughput and scalability needed for this service
Interviewer follow-up:
"Good database choice! Now let's get into a critical part of the system: How exactly would you generate the short URL? What algorithm or approach would you use to convert a long URL into a short one? Consider uniqueness, collision prevention, and URL length."
Think about:
- Fixed vs variable length short URLs
- Character set considerations
- Random generation vs deterministic approaches
- Hash functions vs counters