We should expect around 1 million daily active users.
For traffic:
For throughput:
Storage:
Tables:
API Gateway is connected to a load balancer that spreads traffic between the different instances of the create URL service and redirect service.
These 2 services are connected to the same database.
The database has a caching layer.
Redirect flow
Short URL flow
Bottlenecks will come from the read path of our system. This means the cache and the database will be hit with a ton of traffic.
Both services are stateless, so it is easy to scale them by adding more servers.
1) Database consideration
2) Cache consideration
3) Load balancing
1) We use Cassandra as our main analytics database since it can handle a lot of traffic for writing. Since it is write optimized, it is a lot better than a relation db since relation db uses b-trees and will have slower writes
2) Since we do sharding - we have to keep I mind that we can't join easily. Since we don't really need to join any data, it is a good choice
3) Since we do read replicas - we need to keep in mind the delay in updating the replicas.
Since we have a cache that we update and since the first is returned optimistically. it should be covered.
4) Since we have a few nodes/shards/replicas we need to know how to manage this system. A tool like Kubernetes can be used to make sure our nodes are up and running.
1) The load balancer is a bottleneck and could fail. We will have a backup loads balancer that is passive. Traffic will be redirected to it in case the main load balancer fails.
2) Nodes in the database and caches could fail. Since we are using Kubernetes, we rely on it to bring them back up.
3) Servers running the services could fail. Again, we rely on Kubernetes/ or other orchestration software to revive the services.
4) When a node in the Redis cluster fails, we could get a lot of cache misses. Since we use consistent hashing, we only get a minimal amount of keys that get affected since they are split between the nodes and virtual nodes.
5) Some database nodes could get too much traffic/data if the sharding is not done properly - a hot spot. We have to monitor this so that we can improve our key distribution. Sharding the large node should be enough to fix the issue temporarily.
1) Adding availability zones like the east and west coast. Adding data centers on multiple continents to get closer to users. This can reduce the load of the system since we balance the load among regions. Doing this also improves availability since now even if data centers or availability zones are down, we can redirect to other regions.
2) Improved algorithms when generating shortened URLS. Currently, we hash it ourselves. There is no causality, it is hard to order the shortened URLs. For this, we can use a technique like SnowFlake which integrates some of the bits in the returned value so we can have some order.
3) Using Terraform to manage the whole system. Since now there are a lot of moving parts, we need to use something that can make managing our system easier.
4) Using Redis Sentinel to manage our cache clusters can help us handle failure events.
5) We also need to discuss how our databases handle partition events. Like in primary/secondary where have to promote a secondary node to a primary. Voting mechanisms should be the new primary. How data is replicated among nodes. So we can gracefully recover from the backups/replicas.