Requirements
Functional Requirements:
- Create a short URL for a given long URL.
- Return the long URL associated with a given short URL.
Non-Functional Requirements:
- List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...
API Design
We need mainly 2 endpoints
- POST /urls which will create shortUrl based on onLongUrl
Request:
Authentication header for authorization of user
{
"url": "https://... "
"userId: "..."
}
Response:
201 Created
{
"shortUrl": "https://shortly.com/..."
}
401 if user is unauthotized
Another API for redirecting users to long url when short URL is providerd
GET /url
302 -> Moved to redirect url
404 -> if we receive invalid url or not found in our DB
High-Level Design
Designing a highly available system, We need to have write path and read path. Our traffic is more read heavy and expecting 100:1
API gateway is acts as entry layer and does middleware tasks like authentication , rate limitting and forwarding request to API layer,.
Write path:
client -> Load balancer --> Api gateway -> write API -> UUID Generator --> DB (Dynamo DB /Cassandra) --> Update Cache
Write path uses ID generator which will be create unique id based on unique ID, it should return base62 encoded string of 6 characters.
Each unique id is generated using timestamp + machineId + sequence Number to make to unique across machines and concurrent access. to keep it 6 character use last 32 bits and encode using base62
read path:
client -> load balancer -> api gateway -> read API --> check cache --> if cache miss read fromDB
Detailed Component Design
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.