bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/System Design/Design a URL Shortener
System Design•Design a URL Shortener

Design a URL Shortener: API & Data Model

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

EndpointPurpose
POST /linkscreate a short code
GET /{code}redirect to the original URL
GET /links/{code}/statsclick count

Entities

EntityKeys / 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.

Previous

Design a URL Shortener: Capacity Estimation

Next

Design a URL Shortener: High-Level Architecture