we assume we will have 10M requests to generate new URLs per day, which means 10M writes, and 1B reads when we redirect the user's request, write QPS will be ~115 and read QPS around 11500, for each URL we will need 500 bytes of storage and in a year 1.8 B
we will have one POST endpoint that creates the short URL accepts input with long url and ttl and returns 200 and another GET endpoint to resolve it and returns 301 with longurl as redirection, and 401 when it doesn't exist
the user communicate with the server via a load balander that will redirect the request to one of the servers and save the or retrieve from/to the database and in fornt of the DB we will have a redis cache
urls
----
short_key CHAR(7) PRIMARY KEY -- e.g. "aB3x9kQ"
long_url VARCHAR(2048) NOT NULL
user_id BIGINT NULL
custom_alias VARCHAR(32) UNIQUE NULL
created_at TIMESTAMP DEFAULT now()
expires_at TIMESTAMP NULL
click_count BIGINT DEFAULT 0
-- index for optional dedup lookup:
CREATE INDEX idx_long_url ON urls(long_url);
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.