Caching: keep a copy close

The same page is asked for again and again. How do you answer without doing the work every time, and what's the catch?

System design · about 5 minutes

A cache keeps a copy of an answer, so the next person gets it without the slow trip to the database. That part is easy. The hard part is deciding how old a copy is allowed to be before you throw it away.

Picture: a timeline for one story page kept by Vercel, fresh for 5 minutes, then old but still served for up to an hour more while a new copy is fetched, then gone; not drawn to scale