-first api (POST): has a text box, after user enter a link then return a short link on screen.
-second api (GET): if the user enter the short link on browser, api return and redirect the original link
Traffic Estimation:
Storage Estimation:
Memory Estimation (for Caching):
Bandwidth Estimation:
Key Considerations:
Create short link
-URL: /shorten
-method: POST
-header:
.Authorization: Bearer
-body: {
originalLink: string
}
-Response:
+Success: status code 200
{
success: boolean,
alias: string
}
+Fail: Unauthorized => status code 401
+Fail: invalid url => {success: false, errorMessage: "invalid url"}
Get original link
-URL: /
-method: GET
-Response:
+success: return original link and redirect
+error:
.Not found => return a default page with not found error message
.Link expired => return to error page with expired error message
Additional url (Furture improvement)
-POST /custom/
Client:
-A website that allow user to login, register
-Has a text box for user to pass their link and receive short url
Api gateway:
-Could use Kong to load balancing, authenticated for whole system
Server:
-Use to check if the url is exist or not then query the data from database or caching service
Database:
-Store the User and Short link data
Caching service:
-store the short link that already query by get method to reduce work load for the server
Cleaning service: use to clean up database or cache
Consider sequence diagrams
Client:
API gateway:
Shorten service with some main functionality listed below:
Query Service:
Analytic Service:
Caching service:
Cleaning service: work as a cron job to deactivate all expired url or inactive user. this cron job could run 1 or 2 a day. when the service found an expired link, it will remove the alias from caching service as well
Database:
Client
-ReactJS: simple, fast development, large support community but performance is not the best
-Angular: Full-featured framework with everything included but its don't have good performance compare to the other
=> I will chose React js because this time we should aiming for fast development. We only need a simple UI so it pretty good enough
Server-Main Service:
-Node JS: simple, easy to develop, great concurrent handling but don't have good support for micro-service
-Azure Dotnet: Great supportive for micro-service but quick complicated for development and deployment
=> I will chose Node JS with the same reason i choose for Frontend side. Furthermore, both FE and BE use the same language can help team to easier to hire fullstack developer.
Database and Caching Service
-Relational database like PostgreSQL: have great performance, support indexing for fast query.
-No SQL database like MongoDB: high scale and performance, but its suitable for store document more than a simple string
-DynamoDB: highly scalable, fully managed but higher cost
-Redis: Great performance, simple, in-memory caching
=> I will chose Redis for my caching service solution and DynamoDB to store the data for better scaling performance
Microservice or monolith:
-Microservice: provide better scalability, suitable for complex system, flexibility but introduce complexity in development, deployment and harder to maintain
-Monolith: Simple, easier to learn and fast development, but harder to develop complex system.
=> I will choose Microservice for our current requirements to support better for scale in each service
-Sever is down and cannot return the original link to the user: should use horizontal-scale server strategy like kubernetes to avoid zero downtime.
-Server over-flow in peak time: using auto scaling like kubernete and circle breaker t
-Database is down: should use database cluster or replica read data to avoid database down
-Hackers try to abuse our query service: we all ready implement various of rate limiting methods to protect it
-Some special peak time could overflow our server. For example, some company have chrismas event, propose their million of users click on a same link at a same time
-Adding analytic service to analyze user data
-Switch load balancer layer to API gateway for better management, rate limiting and authentication for api
-Split server layer to 2 separated services for shortening URL and Query URL for better scalability
-Chose better hash algorithm