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.