URLs to shorten - 200/sec
Redirection traffic - 20000 redirects/sec
Each entry is 144B, rounding off to 256B
Total data to be stored - 200 * 60 * 60 * 24 * 256 = 4.4 GB per day
Within 5 years, it will be 4.4 * 365 * 5 = 8TB of data
Including cache, it will be ~15TB of data
shortenURL()
input: long URL, user id
output: short URL
redirect()
input: short URL, user id
output: redirection to long URL
We need a simple long to short URL mapping. We won't need any complex queries for this system.
However, it requires string consistency.
DynamoDB would be a good choice. It is horizontally scalable and can be configured for strong consistency.
We can also provide secondary index like userid to quickly look urls created by given user
Client
API gateway
Shortening service:
Redirection Service:
Analytics Service:
Authentication Service:
DynamoDB:
Cache:
Shorten URL: Client sends long URL for shortening. Service shortens URL. Store long-short URL in DB and update cache
Redirect: Client sends request with short URL. Access short URL from cache. If not present in cache, get it from database
Authenticate user: Authentication service verifies user and sends request to shorten service
Database and cache should be partitioned for improved scalability.
We can use short url as partitioning key. Since users will be using short url more often, it will be a good choice as it will ensure data is distributed evenly.
Other partitioning keys won't be able to give this advantage.
Fault Tolerance
Scalability for shorten service