Store copies of data closer to the user or app so responses are faster and backends do less work.
Store copies of data closer to the user or app so responses are faster and backends do less work.
Cache = a copy of data in a fast place. Instead of hitting the database or API every time, you read from the cache. If the data is there (hit), you get a fast answer. If not (miss), you fetch, then store in the cache for next time.
Why cache? Speed and cost. Less load on the source (DB, API). Lower latency for users. Trade-off: data in the cache can be stale until it expires or is invalidated.
What is a cache?
A copy of data in a fast place. Read from cache first; if miss, fetch then store for next time. Speed + less load on the source.
In-app / distributed
In-app = memory in your process (fast, not shared). Distributed = Redis, Memcached—shared across instances. Good for sessions, API responses.
Edge / CDN
Cache at the edge (CloudFront, Fastly). Static assets (images, JS, CSS) and sometimes API responses. Serves from a location close to the user.
When to cache
Read-heavy, same data often, a bit of staleness OK (e.g. product catalog). Set TTL; invalidate on write when you need freshness.
Cache = faster responses and less work for the backend. Trade-off: data can be stale until TTL or invalidation.
In-app = memory inside your process (e.g. a map or Redis next to the app). Fastest, but not shared across instances.
Distributed cache = Redis, Memcached. Shared across many app instances. Good for session data, API responses, or computed results.
Edge / CDN = cache at the edge (CloudFront, Fastly). Caches static assets (images, JS, CSS) and sometimes API responses. Serves from a location close to the user.
Cache when: read-heavy, same data asked often, and a bit of staleness is OK (e.g. product catalog, leaderboard).
Avoid or be careful when: data changes often, must be exact (e.g. balance after payment), or cache invalidation is hard. Set TTL (time-to-live) so old data expires; invalidate on write when you need freshness.
Related concepts
Explore topics that connect to this one.
Practice with these scenarios
Apply this concept in hands-on scenarios.
Test yourself: 1 challenge
Apply this concept with scenario-based Q&A.
Interview prep: 1 resource
Use these to reinforce this concept for interviews.
View all interview resources →Ready to see how this works in the cloud?
Switch to Career Paths for structured paths (e.g. Developer, DevOps) and provider-specific lessons.
View role-based pathsSign in to track your progress and mark lessons complete.
Questions? Discuss in the community or start a thread below.
Join DiscordSign in to start or join a thread.