Grace Periods
Grace periods let you serve stale data when the underlying source fails. Not unlike my middle-school lunch when New Jersey ran out of whatever crap they put between two pieces of “bread”.
The Problem
Section titled “The Problem”const getUser = t87s.query((id) => ({ tags: [tags.user(id)], ttl: '10m', fn: () => db.users.findById(id), // What if DB is down?}));@t87s.querydef get_user(id: str) -> QueryConfig[User]: return QueryConfig( tags=[tags["user"](id)], ttl="10m", fn=lambda: db.users.find_by_id(id), # What if DB is down? )Without grace: if TTL expires and DB is down, users get an error, then a refund, then a lawsuit.
The Solution
Section titled “The Solution”const getUser = t87s.query((id) => ({ tags: [tags.user(id)], ttl: '10m', grace: '6h', // Serve stale data for up to 6 hours if fn fails fn: () => db.users.findById(id),}));@t87s.querydef get_user(id: str) -> QueryConfig[User]: return QueryConfig( tags=[tags["user"](id)], ttl="10m", grace="6h", # Serve stale data for up to 6 hours if fn fails fn=lambda: db.users.find_by_id(id), )With grace: when TTL expires, t87s tries to refresh. If that fails and we have stale data within the grace period, we hold our nose and serve the stale data while retrying in the background.