Skip to content

Commit e12bb6e

Browse files
committed
Polish README
1 parent 82c5ded commit e12bb6e

1 file changed

Lines changed: 60 additions & 30 deletions

File tree

README.md

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
11
# URL Shortener
22

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
424

525
## Live Demo
626

727
- Frontend: https://url-shortener-frontend-av1x.onrender.com
828
- Backend API: https://url-shortener-gfp0.onrender.com/docs
929

30+
## Key Metrics
31+
32+
- Cache hit latency: ~8–11 ms
33+
- Cache miss latency: ~10–32 ms
34+
- Supports horizontal scaling through stateless application replicas
35+
- Redis reduces repeated database queries for hot URLs
36+
- CI: automated backend tests on every push and pull request (GitHub Actions)
37+
1038
## Frontend
1139

12-
A lightweight React frontend provides a simple interface for:
40+
A lightweight React frontend enables:
1341

1442
- Creating short URLs
1543
- Viewing generated links
@@ -28,40 +56,29 @@ When the backend returns structured error details, such as rate-limit responses,
2856
- Environment-based configuration enables seamless switching between local, Docker, and cloud deployments
2957
- Frontend deployed as a static site on Render, providing a user interface for interacting with backend APIs
3058

31-
## Quick Test
32-
33-
- Frontend:
34-
- Open the web UI: https://url-shortener-frontend-av1x.onrender.com
35-
36-
- Backend API:
37-
```bash
38-
curl https://url-shortener-gfp0.onrender.com/health
39-
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-
5659
## System Design Summary
5760

5861
- Stateless FastAPI services behind an Nginx load balancer
62+
- Stateless design eliminates the need for sticky sessions, enabling seamless horizontal scaling
5963
- 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
6065
- 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
6167
- Rate limiting uses the first `X-Forwarded-For` address when requests pass through a reverse proxy or load balancer
6268
- Horizontal scaling achieved via multiple stateless application replicas
6369
- Graceful degradation when Redis is unavailable
6470

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+
6582
## Features
6683

6784
- Create short URLs via API (`POST /shorten`) or through the frontend UI
@@ -95,9 +112,22 @@ Example results:
95112

96113
- Cache miss latency: ~10–32 ms
97114
- 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
99123

100-
This demonstrates that Redis caching significantly reduces redirect latency and minimizes repeated database queries in read-heavy workloads.
124+
- Backend API:
125+
```bash
126+
curl https://url-shortener-gfp0.onrender.com/health
127+
curl -X POST "https://url-shortener-gfp0.onrender.com/shorten" \
128+
-H "Content-Type: application/json" \
129+
-d '{"original_url":"https://www.google.com"}'
130+
```
101131

102132
## Backend Highlights
103133

@@ -441,4 +471,4 @@ Nginx Load Balancer
441471
- Enhance rate limiting with sliding window or token bucket algorithms
442472
- Implement custom aliases and expiration policies
443473
- Build analytics aggregation pipeline for high-volume traffic
444-
- Deploy multi-instance setup to the cloud using container orchestration (e.g., Kubernetes)
474+
- Deploy multi-instance setup to the cloud using container orchestration (e.g., Kubernetes)

0 commit comments

Comments
 (0)