Distributed TinyURL Architecture: How to handle 100K URLs per second

Distributed TinyURL Architecture: How to handle 100K URLs per second


Related discussions:

“Build a tinyurl clone” remains one of my favorite interview questions. You then ratchet it up by introducing constraints.

This would rack up quite the DynamoDB bill

I developed a short url solution for my company back in 2009.

I emphasized reliability and consistency for CRUD operations. Majority of updates were from users themselves via UI, with an offline bulk processs for large changes.

Speed was the primary consideration for the main functionality (redirects .. which supported both short urls and vanity domain names .. with options for a landing pahe with a timer, or automatic redirect without any delay). The UI also allowed searches, with some basic categories and key words which were allowed in the meta data.

I used a homegrown in memory cache for storing the top 10000 hits with a default TTL of 1 day for each entry (and ability to refresh, either by owner of the shortcut or admin).

Back then, there was no autosclaling or serverless, and the solution was deployed on regular hardware (GTM, LTM, Apache HTTPD reverse proxy, Tomcat/Java and Sun Directory Server Multi-Master as a data store (:sweat_smile: … long story but it worked great for this application which ran active/active across multiple locations). Today, I would probably use Cloudfront/API Gateway and a combination of Lambda and ECS/Fargate. I would use a low cost database and ElastiCache … or even DDB with DAX, if cost was not a major concern.

This shit again lol

I think cloudfront support redirects?

Really nicely written article. I really enjoyed reading it

Sustained 100k TPS for API Gateway would be very expensive.

I’d setup an S3 bucket as a public website and use their website redirects (or empty objects with Location: headers). Use a csv in source control for state management. github action for automated updates. S3 server access logging (or cloudfront logs) for analytics tracking.

I really don’t know why it is so over engineered and dynamo cost would be outrageous.
A load balancer with ECS would probably be enough. For database choose a key-val. Use CloudFront for cache.

Majority of requests would be cached and handled at Cloudfront, if configured right. If not API Gateway (which comes with rich API features), ALB could be used. I presume there will be some type of monetization. If the solution indeed reaches 100K TPS, it would be a good problem to have.

100k write TPS, not reads.

This feels over engineered because of the weird requirements:

  • Every long URL must have a single unique short URL. Why?? Just create a new one every time, or worst case do a non consistent lookup before creating and accept the occasional non uniqueness.
  • Users must be able to create a batch of 100k short urls in a single request in 1s. Why??? So much of this could be simplified by setting a reasonable request limit, say 1000, and having callers make parallel requests. I can’t think of a reasonable situation where we really need to create this many URLs in a synchronous call but there are almost certainly workarounds that allow for simpler infrastructure.

This is some crazy expensive overengineered solution.

Would love to know the costs of this architecture

Cool, now simplify it.

If they are cached then you don’t get the analytics.

Process with while loop, a state machine with a 120fps frame rate and chug them out… progressively add features based on features… stick to single machine, single core, single thread. Squeeze all the performance you can… after all that, you can start thinking about all the mostly infra related stuff… most importantly, HA.

Even the most popular url shorteners don’t see writes anywhere close to that

Can be obtained from Cloudfront logs, if required.