Scalability: using automatic scaling groups
Performance: vertical scaling and sharding of DB
Availability: using replicating the DBs
Security: using API gateway
Monitoring: using cloudwatch alarms
1M users
20% is DAU ~ 200000 users per day
let's say each user does 3 queries per day that makes it 6 QPS
so let's say maybe we'll have 3-5 EC2 instances.
For DB:
600000 write request per day with each url having
POST /v1/shortenUrl
request body= {url to be shorten }
response = 200 if successful else error codes 4xx,5xx
GET /v1/retriveUrl?shortUrl=url
Response: Long url
As we've 2 GB of data per day and this is mostly key value pair so we can use NoSQL here with replication factor 2, and for NoSQL we can Dynamo db maybe coz AWS handles all the servers and patching work saving devs time.
DB can have a key with long url and it's value as short url.
Client will be calling our api gateway which will be responsible for all the requests coming to single place, then also takes care of authorization and authentication for security.
Then request will come to Load balancer which will route to the appropriate server. We can also use scaling groups to manage traffic during peak hours.
Then the servers will be having the apis which will be calling the databases internally we can also use Cache here like redis.
Request will come to api gateway then to load balancer which will use routing algo to route to appropriate server which will see which API is called then it';ll shorten or retrieve the url. First it'll check in cache if not there then it'll bring it from db and update cache as well.
maybe to shorten the url we can use some algorithm like generating random urls using some prime numbers algorithm kind of a hash value.
RDBMS vs NoSQL here i feel nosql makes more sense coz we've a key value pair plus scaling can be handled by nosql dynamo db in this case.
we can use EC2 instances for servers as AWS can take care of the patching.
for LB we can use AWS ELB
and similarly we can use AWS Api gateway
bottlenecks could be if more traffic starts coming all of a sudden then we've to handle that with ASG.
For monitoring purpose we can set up alarms at various stages like in instances memory, time usage, request coming per second so that we can detect the anamoly.