System Design
10. API Design and ManagementAnimated
API Caching
Reusing responses to cut load.
The idea
Use Cache-Control, ETag and server caches so repeat requests are cheap.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current message
- earlier
- failure or attack
The user is routed to the nearest edge location.
- step:
- 1/6
- from:
- User
- to:
- CDN edge
1/6
Time runs downward. Solid arrows are requests, dashed arrows are replies.
Step by step
- 1Server sets cache headers
- 2Client or CDN stores the response
- 3Next request revalidates with an ETag
- 4304 means reuse
Where it is used
Read-heavy APIs.
Watch out for
Never cache private data in shared caches.