Design a service that turns long URLs into short links, redirects on access, and reports click counts.
How to approach it
Design the API and data model from the user’s actions, not from the database. Name the few core endpoints, the entities and their keys/indexes, and — critically — which data must be strongly consistent versus eventually consistent. The access pattern (how you read the data) should drive the storage choice, not the other way around.
Core APIs
| Endpoint | Purpose |
|---|---|
| POST /links | create a short code |
| GET /{code} | redirect to the original URL |
| GET /links/{code}/stats | click count |
Entities
| Entity | Keys / indexes |
|---|---|
| Link (code, long_url, created_at, owner_id) | PK(code), index(owner_id) |
| Click (code, ts, ip_hash) | append-only, rolled up async |
Note
Code→URL must be read-your-write on create; click counts can be eventually consistent.