URIMetadata table
URIMapping table
URLActivity table
We can index the longuri and short uri in the mapping table so look up on either will be fast.
The system will contain a
It is a read-heavy Vs write-heavy system so we will have one leader and multiple replicas. The replicas will serve read requests while write will be done to the leader.
This will promise eventual consistency but higher availability and performance. Caching, load balanced micro-services and leader-follower database models will provide for eventual consistency, higher performance, scalability and higher availability.
Caching layer can use a simple memcache as the data structure is not complicated and its a simple key-value pair.
Monitoring and observability can be enhanced based on the urlactivity table
GenerateURL API flow
Redirect URL
GenerateURL service will
RedirectURL Service will check if mapping exists and redirects user to the long url.
Because we are generating alphanumeric based aliases, we can distribute the data in the database using on consistent hashing of these aliases - range based distribution.
Caching layer can be REDIS but might be an overkill given we know the data structure ahead of time and its simple.
Database can be MongoDB as it is known to provide better concurrency via more effective locking methods and a leader-follower algorithm built-in.
We will be trading immediate for eventual consistency, so we can have high availability and performance.
Using hashing to generate short url can still be done by adding userid to the hash or to the url to maintain unique short urls for same long url for different users.