Return the long URL associated with a given short URL.
Non-Functional Requirements:
Ultra low latency setup is not required here since it's not time sensitive.
Scalability - I assume this will serve thousands of users and will be designed accordingly.
API Design
Redirect service -
Lambda behind an API Gateway that listens to our short domain, such as short.ly/XXX where XXX is a random hash generated by the backend service. it will query the target URL from the dynamoDB using the hash from the URL (XXX) and returns a 302 redirect to the target URL.
Backend -
also a lambda behind APIGW but listens to short.ly/generate - generate endpoint will take the user's input from frontend, which is the target URL. the lambda will save the target URL along with a random hash generated specifically for this target URL. it will save those in a DynamoDB table with the hash as the primary key, and value being the target URL that the user want to shortened.
High-Level Design
Frontend -
React based on Cloudfront and S3 for static web storage
Redirect service -
Lambda behind an API Gateway that listens to our short domain, such as short.ly/XXX where XXX is a random hash generated by the backend service. it will query the target URL from the dynamoDB using the hash from the URL (XXX) and returns a 302 redirect to the target URL.
Backend -
also a lambda behind APIGW but listens to short.ly/generate - generate endpoint will take the user's input from frontend, which is the target URL. the lambda will save the target URL along with a random hash generated specifically for this target URL. it will save those in a DynamoDB table with the hash as the primary key, and value being the target URL that the user want to shortened.
Detailed Component Design
Frontend -
React based on Cloudfront and S3 for static web storage - cloudfront will handle scaling and we can attach a WAF for additional security, cloudfront can easily handle millions of concurrent requests. also this is a CDN which will reduce static file handling to edge locations around the world.
Redirect service -
Lambda with python runtime. all it does is take the hash from the URL, queries ddb table for the target URL value. lambda will have permissions only to that dynamoDB table and will scale on it's own being serverless, all we have to do (also applies to backend service) is to make sure we have enough concurrent lambda invocations in our AWS account quota.
Backend -
Lambda with python runtime. same pros as the redirect service. what it does is generate a 5-6 random hash string which it will store in dynamoDB along with the target URL. we'll set a TTL in that ddb record so we won't have inifite items in our DDB. we'll need ofcouse to adjust for provisioned writes/reads, we can start with on demand table and adjust as needed in terms of scale or use auto scaling.