List the key functional requirements for the system (Ask the AI for hints if stuck)...
In Scope:
Out of Scope:
List the key non-functional requirements (performance, scalability, reliability, etc.)...
Based in the CAP theorem:
As a base we will have P because it's required to have partition tolerance
and as well for the base of the project we will have A from Availability
so this system design will be based in a AP solution
we will need:
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
Estimations:
Total Users: 10M
Daily Active Users: 500K (5% of total users)
Resources created daily -> 1 URL per day -> 500k writes/day
Read/write Ratio: 1:100 -> 50M reads/day
Register Sice: ~500B (key, original url, timestamp, overhead)
Trafic:
Writes: 500k / 86,400 = 6 QPS (queries per second)
Reads: 50M / 86,400 = 580 QPS avarage (queries per second) with spike ~3x = 1.7k QPS
High read required, low latency, high availability
Trafic Increase:
2x yearly in Daily Active Users
| Year | DAU | Writes/día | Reads/día |
| 1 | 500k | 500k | 50M |
| 3 | 2M | 2M | 200M |
| 5 | 8M | 8M | 800M (~9.3k QPS) |
Storage:
With the trafic Increase in year 5 we will require around 2.8 TB of storage
In this case we will be expecting to have database sharding, because this table can be increasing all the time, we will never delete any data in the database
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
The base for this design based in the functional requirements are two base actions
create resource
read and redirect to original resource
POST /api/v1/short
Payload:
Response:
Errors:
GET /api/v1/url/{key}
Response:
Errors:
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
For this especific case to make all more clear I will be using AWS as the Cloud Provider
Client will be the browser/device which is going to make the request
the request will be received by the api gateway, can be for AWS as well
the Load Balancer will help directly to hit first to Redis to see if the resource is already cached, if not will hit to the available Api Service to handle the request
the Api service will be a EC2 container with multiple replicas to allow multi AZ
And the database will be cassandra for example in order to help with the sharding, high horizontal scalability, millions of registers
POST roadtrip:
GET roadtring:
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
For this especific case I'm thinking that the database will be cassandra in order to help with the sharding, high horizontal scalability, millions of registers
The main entity will be something like 'shorted_url'
Out of this scope will be have an external entity that will be for the users in the platform
this in order to make the relation directly between the user and the short url created by the user
in that case I will add another property that will be created_by_user_id: uuid
the partition key that we will use is short_code
High considerations:
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Lets explain a little bit about both flows
We received a register for create a Short Url, the load balancer will call the Key Creator Service
This service will create the Key for that short URL, that can use a hash algorithm based in the timestamp and the long url for example or using an idempontent key
This one will require to generate a unique value
methods that i will avoid for that key:
What I'm thinking for this will be something like:
then convert it to Base62 of 8 characters
Once the key is created I will send a kafka event with the key, original URL
With this we own eventually read consistency, high creation consistency
then a short url service consumer will received the kafka event in order to save that data in to the cassandra database
based in the partition key will determine in which database we will be saving that
Also in this case Kafka as well can save the value directly in cache with a small TTL (5min)
In the reads we will be receiving the request, the main idea is that the latency will be very slow so I expect something like <20ms based in the standar
So once de request arrives to the load balances we will check the redis cache
if exits return it and redirect
if not we will hit the URL shorter service
we will ask to cassandra based in the PK from the key
once we validate it exists we will be async adding it to the cache layer
and making the redirect
it's important that the cache added step will be async to avoid adding more latency to the request