Invental/Review lessons/Writes that span systems

Writes that span systems

Run every rejecting check before any write

Do every check that can reject a target before you write anything for that target; otherwise a retry against a different target succeeds and leaves the first one with an orphaned “in progress” record that nothing will ever finish.

01 · Before and afterThe pattern

Admit, then persist; and keep effect dependencies to the data the effect reads.

TypeScript
// before: createReceipt('preparing'); createDoc(); if (file.size > limit(ws)) return 'too-large';
if (file.size > limit(ws)) return 'too-large';           // reject before any write
const blobId = await blobs.put(ws, file);                 // can fail without side effects
await createReceipt(ws, attemptId, 'preparing'); await createDoc(ws, { blobId });

useEffect(() => loadPreview(item.id), [item.id]);         // not [item.id, onWorkspaceChangedCallback]

02 · Run it on your appThe check

If an import fails in one destination and the user retries in another, can the first destination end up with a half-created 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.