Where should a URL shortener cache frequently accessed short_code to long_url mappings for low-latency redirects?

6 year of experience System Design URL Shortener Bitly URL Shortener Bitly Medium Single Correct Pyq Inspired

Question

Where should a URL shortener cache frequently accessed short_code to long_url mappings for low-latency redirects?

A
In an in-memory cache between the application service and the database
B
Permanently in the user's browser local storage
C
Hard-coded inside the write service source code
D
Only inside the analytics database

Explanation

An in-memory cache like Redis or Memcached should be placed between the application service and database.

For read-heavy redirect traffic, checking the database for every request can become expensive and slow. An in-memory cache such as Redis or Memcached can store popular short_code to long_url mappings. On a cache hit, the service can redirect quickly without touching the database. On a cache miss, it can read from the database and populate the cache.

Related Questions

Why should a URL shortener maintain an index or primary key on the short_code column?

URL Shortener Bitly

View Question

A short URL has expired. What should the redirect service ideally return when the short co...

URL Shortener Bitly

View Question

Why is Base62 commonly used for short URL codes instead of Base64?

URL Shortener Bitly

View Question

Which short-code generation strategy best guarantees uniqueness without collision checks f...

URL Shortener Bitly

View Question

Why is using the first few characters of the long URL as the short code a bad approach?

URL Shortener Bitly

View Question

Which database constraint is most important for preventing two different long URLs from ge...

URL Shortener Bitly

View Question

Related Resources

Related learning resources will appear as content grows.