Action: 301 (permanent) or 302 (temporary) redirect to original URL
No JSON — just HTTP redirect
✅ Good call including apiKey — this allows rate limiting, user tracking, and abuse control.
✅ Database Design Feedback
You said:
"I don't see any ACID requirements... better to go with key-value store like DynamoDB."
That’s mostly correct, but let’s be careful.
Do we need ACID?
Atomicity & Consistency: We must avoid two different short URLs for the same long URL if we want deduplication.
Isolation: Needed to prevent race conditions when multiple users shorten the same long URL at the same time.
Durability: Yes — we don’t want to lose mappings.
So while full relational ACID may be overkill, eventual consistency might not be acceptable if we want strong guarantees on correctness.
But yes — a scalable NoSQL key-value store is a great fit.
Your choice: DynamoDB — excellent choice!
Fully managed, scales well
Low-latency reads/writes
Can handle high traffic
Let’s define the schema.
📚 Suggested Table Schema (DynamoDB):
Field
Type
Purpose
shortKey
String (Partition Key)
e.g., abc123
longUrl
String
Original URL
createdAt
Timestamp
For analytics/expiry
clickCount
Number
Optional: for analytics
userId
String
Optional: if supporting users/apiKey
✅ shortKey → longUrl is the primary lookup (used during redirect).
✅ Query pattern is simple: "Get longUrl by shortKey" → perfect for key-value store.
🔍 Interviewer Follow-Up:
"Great. Now, how do you generate the shortKey (e.g., abc123) from the long URL? What properties should this short key have? And how do you ensure it's unique?"