Assuming that the average size of the URLs are 200 character, and we will store 8 length character strings along with them.
The storage requirement will be around 210 character, which is 210 Bytes.
If we store 1000.000 URLs in a given time (e.g we delete the expired ones) then we will have 210 * 1000_000 / (1024 * 1024) mb requirement which is 0.2 GB storage.
The application will be read heavy, therefore database will have replicas for the read operations.
POST - /url
body - param: long_url
response:
201 - CREATED - shortened url
403- Not authorized
401 - not authenticated
400 - bad request - invalid URL e.g
500 - internal server error
GET /url
requestParam - url - shortened URL
404 - not found
.... other response codes
table-name - urls
columns: long_url, short_url, created_at, last_access, expires_at, is_expired
We will us layered architecture here, client will call backend APIs and the backend will call database.
There will be in memory cache before the database to return "hot" URLs.
Client -> CDN
-> load-balancer -> backend -> cache -> database
The frontend will be running via React, the backend will be running on java/spring-boot and the database will be PostGres.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?