I will design the API using a python or TypeScript (in case I choose Next.js as a framework). The API will feature these endpoints:
The system architecture is very simple. At first, we can consider this architecture:
A central server that runs the API. The server is responsible for taking the POST request (/v1/url-shorten) from a client andreturnings the shortened URL from the GET request (/v1/get-short-url)
If the system needs to scale, we can use this structure:
At first, the client app will send a request to an ingress controller to manage the secure access from the outside. Then a load balancer is necessary to distribute traffic across different instances of the shortening URL service and the redirect service. The system will also feature a Redis cache to efficiently return the shortened link when the user requests it from the URL redirect service.
A single instance of the database (example: MongoDB) to handle the reads and multiple replicas to handle the writes.
Also, the system features a monitoring & analytics service to monitor the latency and the cpu and memory usage.
The client is a webapp based on Next.js with a typescript API. The database can be a postgresql or a mongodb or supabase if we need to handle replicas more efficiently or a simple appwrite database. The appwrite database uses MariaDB as a backend and can handle Auth/OAuth and Tables.
if we need to monitor the latency we can host the platform using vercel and use the observability tools that are also available with the free plans. Otherwise we can self host the platform using a VPS and some open source monitoring tools such as cilium or tetragon or datadog/dynatrace.
The observability pipeline will send the data using the OTLP protocol to a grafana dashboard where we can monitor the latency
in case we need to scale the system we can use two microservices:
both of the microservices can scale orizonthaly or vertically. The system will scale vertically if mutiple user logs at the same time. the system can also scale horizonthally if we need to manage multiple writes