Invental/Review lessons/Check, then act on stale state

Check, then act on stale state

Re-check eligibility at write time

When a job is queued from a snapshot of “who is eligible”, re-check eligibility at the moment you write the money row, not only when you build the queue.

01 · Before and afterThe pattern

TypeScript
// queue time: snapshot
const due = await db.membership.findMany({ where: { planId, status: "approved" } });
for (const e of due) await queue.dispatch({ memberId: e.memberId, planId });

// write time: re-check against current state
const e = await db.membership.findUnique({ where: { memberId } });
if (e?.status !== "approved" || e.planId !== planId) return skip("no longer eligible");
await db.credit.create({ ... });

02 · Run it on your appThe check

Do your scheduled payment or credit jobs re-check the member's current status right before they create the money record?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.