Backend / Data / Cloud
Monetized Link Shortener SaaS
A Node.js and Express URL-shortening service with PostgreSQL persistence, Redis caching and rate limiting, analytics, container setup, and AWS infrastructure configuration.
Repository evidence: src, database, Docker Compose, Dockerfile, AWS/IaC directories, API README, monitoring/security sections, and performance-test tooling. README sample metrics are excluded as results.
Engineering snapshot
What the repository demonstrates
- Short-code generation and collision handling
- Redis cache for redirect lookups and rate limiting
- PostgreSQL URL and analytics persistence
- Analytics, health, and metrics endpoints
- Container and AWS deployment configuration
01
The problem
A link shortener is read-heavy: redirects must be quick, short codes must be safe to generate, and analytics should not make the redirect path depend on a slow write. The repository separates cached redirect lookup, durable URL data, analytics, and management APIs.
02
Engineering requirements
Functional
- Create short URLs with optional expiration.
- Redirect from a short code.
- Read analytics for a short code.
- Soft-delete a short URL.
- Expose health and metrics endpoints.
Non-functional
- Cache-aware redirect path.
- Collision-safe short-code generation.
- Rate limiting and input validation.
- Containerized local setup and AWS/IaC configuration.
- Operational metrics and health checks.
03
System architecture
A client/frontend reaches the Node.js/Express backend. Redis stores short-code mappings and rate-limit counters; PostgreSQL stores durable URL and analytics data. Docker Compose supports local services, while AWS and IaC directories document deployment configuration.
04
Request and data flow
- 01A client sends POST /api/shorten with a URL and optional expiry.
- 02The service generates a Nanoid short code and checks collision behavior.
- 03The URL is written to PostgreSQL and cache state is updated according to the service strategy.
- 04A redirect request looks up the short code through Redis before falling back to PostgreSQL.
- 05Analytics are tracked and exposed through the analytics endpoint.
- 06Rate limits, validation, health, and metrics routes support the surrounding API.
05
Key engineering decisions
Redis for redirect caching
Why: Redirects are read-heavy and benefit from avoiding a database read on every request.
Trade-off: Cache invalidation and Redis failure behavior must remain correct.
PostgreSQL as source of truth
Why: URLs, expiration, soft deletion, and analytics need durable relational storage.
Trade-off: Writes and schema management are more involved than a cache-only design.
Nanoid over sequential IDs
Why: URL-safe random codes reduce simple enumeration and expose a bounded public identifier.
Trade-off: Collisions remain possible and must be checked/retried.
Asynchronous analytics path
Why: Redirect delivery should not be coupled tightly to analytics persistence.
Trade-off: Analytics may be eventually consistent or lost during failure unless buffered durably.
06
Deep technical challenge
Problem
The hardest problem is keeping the redirect path fast while preserving correct expiration, deletion, caching, and analytics behavior.
Why the naive approach fails
A naive implementation would query PostgreSQL for every redirect and update analytics synchronously before returning the redirect.
Implemented solution
The repository uses Redis mappings, PostgreSQL persistence, cache TTL/invalidation guidance, and an analytics path. The exact write-through and failure semantics should be verified in the source before promising a particular consistency guarantee.
Edge cases
Cache miss, stale cache after soft delete, short-code collision, expired URL, analytics write failure, malicious destination URL, and rate-limit exhaustion are key cases.
07
Database and API design
The repository includes database/schema.sql and documents URL persistence and analytics data. README evidence calls out indexes on short_code/original_url and soft deletion via is_active. Exact schema details should be checked against the SQL file when maintaining the case study.
| Method | Endpoint | Purpose | Auth |
|---|---|---|---|
| POST | /api/shorten | Create a short URL. | Not stated in verified README route docs |
| GET | /:shortCode | Redirect to the original URL. | Public |
| GET | /api/analytics/:shortCode | Read click and visitor analytics. | Not stated in verified README route docs |
| DELETE | /api/:shortCode | Soft-delete a URL. | Not stated in verified README route docs |
| GET | /api/health | Check service/database/Redis health. | Public/operational |
| GET | /metrics | Read performance metrics. | Operational |
08
Security
Implemented
- Rate limiting.
- Input validation.
- Helmet security headers.
- CORS configuration.
- Abuse detection.
- Parameterized SQL queries.
Potential improvements
- Verify destination URL allow/deny policy and SSRF implications.
- Protect analytics and metrics endpoints if they expose sensitive data.
- Add authentication/authorization policy documentation for management endpoints.
- Rotate and isolate AWS/database/Redis secrets.
09
Failure handling
Evidence
- Health checks for database and Redis.
- Cache fallback concept through database source of truth.
- Soft-delete state.
- Collision detection and retry guidance.
- Metrics and logging paths.
Remaining scenarios
- Analytics durability when Redis/database writes fail.
- Stale cache after expiration or deletion.
- Redis outage behavior under rate limiting.
- Abuse patterns that bypass simple URL validation.
10
Performance, scalability, and observability
Performance and scalability
- Redis caching and indexed lookup paths are implemented/documented.
- Performance-test scripts measure redirect latency, cache hit ratio, load, query execution, and rate limiting.
- Sample README figures are not treated as measured results without a run artifact.
- Connection pooling and horizontal stateless scaling are described in the repository.
Observability
- Health endpoint.
- Metrics endpoints and export/reset paths.
- Morgan/CloudWatch/container logging documented.
- Future: add trace IDs, cache-miss alerts, redirect error budgets, and analytics lag monitoring.
11
Testing and code quality
- The repository exposes npm test and coverage commands.
- Dedicated database/load/metrics test scripts are documented.
- The audit did not verify a current test report or coverage percentage.
12
DevOps and deployment
- Dockerfile and docker-compose.yml.
- AWS directories with deployment/IaC configuration.
- README documents ECS, RDS, ElastiCache, CloudFormation/Terraform paths.
- These artifacts show deployment intent; runtime deployment is not independently verified.
13
Engineering trade-offs
Cache versus database redirect reads: lower repeated-read cost, but invalidation complexity.
Nanoid versus sequential IDs: less enumeration, but collision retry needed.
Async analytics versus synchronous write: faster redirect response, but weaker immediate analytics durability.
Availability versus strong consistency: the README chooses a cache-friendly model, which should be tested around delete/expiry races.
14
What I would improve next
Short term
- Run and archive the database/load test results.
- Add tests for stale cache, expiry, deletion, collision, and analytics failure.
- Clarify authentication for management and analytics routes.
Medium term
- Add durable analytics buffering.
- Add destination validation/SSRF protection.
- Add CI for backend, database, and container smoke tests.
Production scale
- Validate Redis Cluster and multi-instance invalidation.
- Partition/archive analytics based on measured growth.
- Add tracing across redirect, cache, database, and analytics paths.
15
Key learnings
- A redirect service should keep its hot path small and explicit.
- Cache invalidation is part of correctness, not only performance.
- Short-code generation needs collision handling even with large keyspace.
- Performance claims should come from reproducible test artifacts.
16
Interview questions
- What happens on a Redis cache miss?
- How is a deleted URL removed from cache?
- Why use Nanoid?
- How are analytics decoupled from redirects?
- How would you prevent malicious destination URLs?
- What indexes support redirect and analytics queries?
- How would you scale Redis and invalidate multiple instances?
- What would you measure in a load test?
Why this project matters
Recruiter-facing summary
This project demonstrates practical backend trade-offs around a read-heavy service: cache design, relational persistence, identifier safety, rate limiting, analytics, containers, and cloud configuration. It offers a clear interview story without requiring unverified latency or uptime claims.