POST/ shorten
Request: { longUrl }
Response: { shortUrl }
GET/{shortId}
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
stateless API server
Responsibilites
=> Handle incoming requests for URL shortening and redirection
=>communicate with cache, database, and id generator
=>ensure statelessness to support horizontal scaling
Why stateless?
easy horizontal scaling
fault tolerance
ID generator
Purpose
Generate unique short IDs for URLs in a distributed environment
Design choice
=> use snowflake style ID generation or atomic counter + Base62 encoding
Working
=> API server requests a new ID
=> ID generator returns a globally unique numeric ID
=> ID is encoded using Base62 to generate short URL
Benefits
=> prevents ID collisions
=> avoid database auto- increment bottleneck
=> supports high write throughput
Cache and Database layer
cache(Redis)
=> stores short URL -> long URL mapping
=> Read through cache strategy
=> TTL- based expiration with LRU eviction
=> Reduce database load and improve read latency
Database(Nosql)
=> persistent key value storage for URL mappings
=> schema: short_url_id -> long_url
=> Horizontally scalable via sharding
=> Replicated for high availability
Failure Handling
Cache miss -> fallback to database
cache failure-> direct database access