A7Intermediate

Caching Strategy Debate

30 minWhen encountering performance issues

Format: Given a scenario, decide what should be cached, for how long, and when to invalidate.

Scenario 1: News Website

- Homepage article list
- Article detail page
- User comments
- Trending rankings
- User profile info

Which should be cached? For how long?
If an editor changes an article's title, how should the cache be handled?

Scenario 2: E-Commerce Product Page

- Product info (name, description, images)
- Product price
- Inventory quantity
- User reviews
- Recommended products list

Can price be cached? Can inventory be cached?
What if a product is in a flash sale?

Core Concepts:

  • Cache hit rate: How often the cache is used. Too low means the cache is ineffective.
  • Cache invalidation strategy: TTL (expiration time) vs active invalidation vs write-through invalidation
  • Cache consistency: Cached data and actual data may be out of sync

Golden Rule: There are only two hard problems in caching β€” cache invalidation and naming.

My Notes