URL Shortener

Oct 13, 2024

How I created a serverless url shortener on AWS with Rust, TypeScript & NextJS

URL Shortener

I was inspired to make this project after reading a system design book and a URL shortener was an example.

I used NextJS & TypeScript for the front end, with TailwindCSS for styling. I also used TypeScript for the CDK. I wrote the Lambdas in Rust.

github-repo.png

Here is the home screen, where you can enter a url to shorten:

home-page.png

And here is the output:

output.png

AWS Architecture

I used AWS Amplify to host and deploy the NextJS front end. While I used TypeScript CDK to deploy the API Gateway, two lambda functions and the DynamoDB table. The Lambdas were written in Rust.

aws-architecture-diagram.png

DynamoDB

I used DynamoDB for this project because it is a key-value store so it fits this use case. And also it is serverless, which is great for this project that it can scale to zero to keep costs low.

Trade-offs of counter decision

My URL Shortener uses a counter in base 16 as the shortened url. For example, the third url shortened will be '3' and the tenth will be 'A'.

This has an advantage of being the shortest URL possible but it means someone could increment the shortened URL to find all the URLs in the application and the total.

If a hash was used instead the shortened URL would be longer, but it would not be possible to increment the URL to find all the URLs in the application.


Contact