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
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
we will have 2 endpoints:
- Post - api/v1/url/longUrl?www.xyz.com
- GET - api/v1/url/shortUrl?xyz1221
first one we'll send long url by queryParameter abd i am also using URL versioning so that future updates doesn't cause problem to exsisting users, and this api will return 201 and short url
second url is to send short url and in response we'll get 302 and long url for redirection
High-Level Design
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.
when user will send long url we'll use hashing to create a hashcode which will be used to generate short key , as short key will have some prefix eg. xyz{hashcode} and they'll be stored in relational db.
now as our user will keep on increasing and we need to make sure low latency then we need to add caching.
as users will go even high we need to make sure no malious attack cause trouble to our system so we must restrict user with some request limit in given time frame so we'll use a API gateway in front of our server.
with load we need to increase our server strength so we might initialy go for verticle scaling and eventually after that threshhold is reached we can create multiple instance of server
same with db need to scale it horizontal and we'll shard our db using shortUrl with ranges store and we'll use hashing consistency to make sure data is consistent and our main priority will be making our system available most of the time
now with multiple server we need a load balancer which will manage the traffic
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.
we will use caching but it wont sit in from of our database instead we'll utilize CDN for caching as we will be using CDN for low latency for global user so we'll use Write along caching starategy with Cache eviction based on TTL
API gateway will be utilized for rate limiting where we can use sliding window timeframe with bucket approach where it will assign user with some set of tokens in bucket and on each request one token will be used and we'll use IP based rate limiting as we ain't have any authentication requirement
Load balancer will be there to distribute traffic among all instance of servers. we will make our system fault tolerant and available most of time
tradeoff : we are compromising consistency as being available is more important that some user getting stale data, and to make it fault tolterant we will use passive load balancer and passive API gateway with multiple instance of CDN and db sync will be based on hashing constiency which will make sure in case of any node failure it will be re distributed 2