You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-30Lines changed: 60 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,43 @@
1
1
# URL Shortener
2
2
3
-
A production-style distributed URL shortener demonstrating caching, rate limiting, load balancing, and horizontal scalability. Built with a FastAPI backend, React frontend, PostgreSQL, Redis, Docker, and CI (GitHub Actions).
3
+
Production-style distributed system with stateless FastAPI services, Redis-backed caching and rate limiting, PostgreSQL persistence, and Nginx load balancing.
4
+
5
+
## Why This Project
6
+
7
+
This project demonstrates how production-grade backend systems handle scalability, caching, rate limiting, and fault tolerance beyond basic CRUD applications.
8
+
9
+
Key goals:
10
+
11
+
- Design a scalable API with clear request/response contracts
12
+
- Introduce caching and rate limiting as core system-level concerns
13
+
- Support multiple runtime environments (local, Docker, cloud)
14
+
- Ensure reliability through automated testing and CI validation
15
+
- Provide end-to-end interaction through a lightweight frontend
16
+
17
+
## Key Achievements
18
+
19
+
- Reduced database load for hot URLs using Redis caching, reducing redirect latency and eliminating repeated database queries for hot URLs (~`10-32 ms` to `8-11 ms` locally)
20
+
- Built horizontally scalable stateless FastAPI services behind an Nginx load balancer
21
+
- Implemented distributed rate limiting across replicas using Redis
22
+
- Designed and deployed a distributed system with stateless services and shared infrastructure (PostgreSQL + Redis)
23
+
- Deployed the React frontend and FastAPI backend to Render
curl -X POST "https://url-shortener-gfp0.onrender.com/shorten" \
40
-
-H "Content-Type: application/json" \
41
-
-d '{"original_url":"https://www.google.com"}'
42
-
```
43
-
44
-
## Why This Project
45
-
46
-
This project was built to simulate a production-style distributed system incorporating real-world backend and system design principles, rather than a simple CRUD application.
47
-
48
-
Key goals:
49
-
50
-
- Design a scalable API with clear request/response contracts
51
-
- Introduce caching and rate limiting as core system-level concerns
52
-
- Support multiple runtime environments (local, Docker, cloud)
53
-
- Ensure reliability through automated testing and CI validation
54
-
- Provide end-to-end interaction through a lightweight frontend
55
-
56
59
## System Design Summary
57
60
58
61
- Stateless FastAPI services behind an Nginx load balancer
62
+
- Stateless design eliminates the need for sticky sessions, enabling seamless horizontal scaling
59
63
- PostgreSQL as the single source of truth for durability and consistency
64
+
- Enforced strong consistency for URL creation using PostgreSQL uniqueness constraints under concurrent requests
60
65
- Redis used for shared caching and distributed rate limiting
66
+
- Designed for fault tolerance with Redis treated as optional; system falls back to PostgreSQL on cache failures
61
67
- Rate limiting uses the first `X-Forwarded-For` address when requests pass through a reverse proxy or load balancer
62
68
- Horizontal scaling achieved via multiple stateless application replicas
63
69
- Graceful degradation when Redis is unavailable
64
70
71
+
### Scalability Characteristics
72
+
73
+
- Stateless services enable horizontal scaling without sticky sessions
74
+
- Designed to handle high read throughput workloads by offloading repeated requests to Redis cache
75
+
- Shared Redis keeps caching and rate limiting behavior consistent across replicas
76
+
- PostgreSQL ensures strong consistency and durability for URL creation under concurrent requests
77
+
78
+
## Design Tradeoffs
79
+
80
+
- Tradeoff: prioritized read performance via caching while accepting eventual consistency for cached redirect data
81
+
65
82
## Features
66
83
67
84
- Create short URLs via API (`POST /shorten`) or through the frontend UI
@@ -95,9 +112,22 @@ Example results:
95
112
96
113
- Cache miss latency: ~10–32 ms
97
114
- Average cache hit latency: ~8–11 ms
98
-
- Approximate speedup: ~1–3×
115
+
- Reduced repeated database queries for hot URLs
116
+
117
+
While latency improvement is modest in local testing, Redis caching reduces repeated database queries and improves scalability for read-heavy workloads.
118
+
119
+
## Quick Test
120
+
121
+
- Frontend:
122
+
- Open the web UI: https://url-shortener-frontend-av1x.onrender.com
99
123
100
-
This demonstrates that Redis caching significantly reduces redirect latency and minimizes repeated database queries in read-heavy workloads.
0 commit comments