POST : GET /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: 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"];
B["Load balancers"];
C{"Database"};
D["API Gateway"];
E["URL Shortening Service"];
F["Redirection Service"];
H["Cache"];
A --> D;
D --> B;
B -->|"Write"| E;
B -->|"Read"| F;
F --> H;
H -->|"If needed"| C;
E --> C;
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:
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 |