Skip to content

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”.

const getUser = t87s.query((id) => ({
tags: [tags.user(id)],
ttl: '10m',
fn: () => db.users.findById(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.

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),
}));

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.