POST : /api/v1/url-> This is the API that accepts the original URL, service will generate a hash, this hash will be appended to the URL and the shortened URL will be returned.
GET: /api/v1/url/{shortUrl} -> To get short URL and respone to original URL
Database Choice:
ShortURLs table. This aligns with the requirement for a simple and scalable mapping from short URLs to long URLs, as it can handle high read and write throughput, can be configured for strong consistency, and provides automatic partitioning and replication features.flowchart TD
A["Client"]
D["API Gateway"]
B["Load Balancers"]
E["URL Shortening Service"]
F["Redirection Service"]
C["Database"]
H["Cache"]
I["Authentication Service"]
A --> |HTTP Request| D
D --> |Authorized Requests| I
I --> |User Authenticated| B
B --> |Distribute Load| E
E --> |Create/Lookup URL| C
E --> |Cache Short URL| H
F --> |Short URL Request| H
H --> |Cache Hit| A
H --> |Cache Miss| F
F --> |Redirect to Long URL| C
F --> |Return Long URL| A
sequenceDiagram
Client ->> API Gateway: POST /api/v1/url
API Gateway ->> Shortening Service: Forward request
Shortening Service ->> Database: Store short URL mapping
Database -->> Shortening Service: Acknowledge
Shortening Service -->> API Gateway: Return short URL
API Gateway -->> Client: Return short URL
Client ->> API Gateway: GET /api/v1/url/{shortURL}
API Gateway ->> Mapping Service: Forward request
Mapping Service ->> Cache: Check for short URL
alt Cache Hit
Cache -->> Mapping Service: Return long URL
else Cache Miss
Mapping Service ->> Database: Query long URL
Database -->> Mapping Service: Return long URL
Mapping Service ->> Cache: Update cache
end
Mapping Service -->> API Gateway: Send long URL
API Gateway -->> Client: Redirect to long URL
Caching Layers:
Eviction Policy:
Cache update strategy:
erDiagram
USER ||--o{ URL: "creates"
URL {
string id "Primary Key"
string shortUrl "Shortened URL"
string longUrl "Original Long URL"
date createdAt "Creation Date"
date expirationDate "Expiration Date"
string userID "Foreign Key referencing USER"
}
USER {
string id "Primary Key"
string name "User's Name"
string email "User's Email"
}
CACHE {
string shortUrl "Primary Key"
string longUrl "Cached Long URL"
}
URL ||--o{ CACHE: "stored in"
Database Partitioning:
Prioritize Availability + Partition Tolerance (AP):
sho.rt/abc123, and the DB is partitioned, return from cache or replica.Load balancer failure:
Scenario:
Mitigations:
✅ Use multiple LBs (HAProxy, AWS ELB, etc.).
✅ Enable health checks and auto-recovery.
Database Bottleneck or Outage
Scenario:
Mitigations:
| Area Examples | |
| Performance | Sharding, caching, replicas, CDN |
| Features | Custom aliases, analytics, geo targeting, TTL |
| Security | Link scanning, rate limiting, audit trails |
| DevOps | CI/CD, monitoring, infra as code, zero-downtime |
| UX/UX | User dashboards, previews, QR codes |
| APIs | Public developer API with throttling |