GET /urls/?url=
Status code: 302 redirect
{
"redirected_url":
}
POST
/urls/
{
"url": "long format url",
"short_code":
"expiry":
}
return {
"url":
}
short_code, the application validates it against a distributed Cuckoo Filter (which allows deletions) to quickly check for existence. If it passes, a strong database unique constraint handles final concurrency mitigation.[a-zA-Z0-9]) to guarantee zero distributed collisions.404 Not Found, protecting the downstream database from malicious invalid-link floods.302 Found (Temporary Redirect) status code instead of a 301. This forces client browsers to check the server on every hit, ensuring that URL expirations, metrics tracking, and rate limits are enforced in real time.To handle viral, cross-region traffic without cross-continental database latency loops, the system avoids strict geo-location IP pinning. Instead, it utilizes a Single-Leader, Multi-Region Replication topology. Writes are processed in a primary region and asynchronously replicated to read-replicas worldwide, ensuring ultra-low latency reads globally.
expires_at timestamp. Read operations evaluate this field inline; if the current time exceeds the expiration threshold, a 404 is returned immediately, and the associated Redis key is purged.VACUUM locks caused by mass row deletions, the database is partitioned by time (e.g., daily or weekly tables). Expired data blocks are cleanly removed using low-overhead DROP TABLE commands on older partitions.Availaibility perspective:
Since we have redis layer on top of it , it can scale to 1m req / s
Also cannot induce CDN since we want strong consistency
Tradeoffs:
No tradeoffs since we have extension in place to handle expiration.
Snowflake package to handle unique short code generation
Concurrency handling:
Concurrent calls will not usually collide since in packages like snowflake it used multiple parameters to create a hash Id
Thundering herd problem:
We might have issue of redis miss cache for multiple requests, hence we would be introducing rate limiting as well so that LB does not allow request above certain limit to exceed