Detailed component design
• Hash-based ID algorithm such as base62 or random generation
- hash based generation with base 62
- CRC 32 generates 8 character hash
- Base 62 of 7 creates 3.5 trillion unique keys
- those are good to start
- hash key generates 8 character long , so take first 7
- Random generation using UUID - length of uuid is 128 bits
- converts typical in to 22 characters of base 62
- we dont need that many characters , we need to take first 7 charcters
- might have collisions UUID and high chance of first hash 7 collisions
- Better to generate from the given long url
• Collision detection
- considering the first 7 charter might create collisions
- Check data base for any collisions
handling collisions :
- Append user id with url and generate hash
- check again for Collision
• Distributed vs central generator
- Distributed generator as it requires local
• Edge CDN rationale
- not required its costly and of no help
• Data-center cache (Redis)
Cache the short url as key and long url as value
helps for faster look ups with defined ttl
• Eviction/TTL policy
- evict if any changes on short url
- TTL as 24 hours
• Per-IP or per-token policy
- Rate limit based on the ip address
• Burst handling/back-off strategy
- Increase the node//pods based on the incoming requests
Database design
- generate short url from uuid from long url string
- To scale the database need to higher capacity
- As the data is create only , we cna use nosql databases like cassandra
- Database design like : long url, short url ,created time stamp , expiry time stamp , user id
- User details : User id, user name , create time stamp, update time stamp
- Use normalization to refer to data about meta data like user , domain
- Partitioning Key as hash of short url , as hash of url are based on UUID , short url will be evenly distributed across shards, looks up also distribute across the shards
- Partitioning based on hash using crc 32
- Index on Short URL column help for faster look ups
- Eventual consistency is ok for this use case
- Data Normalization - use Normalization Users and URL