Invental/Review lessons/Writes that span systems

Writes that span systems

Re-check the owner after a remote create

When creating a remote resource takes time, the owner can disappear in the meantime. Re-check that the owner still exists after the create returns, and undo the create if not. A disconnect hook can't delete what it can't see yet.

01 · Before and afterThe pattern

TypeScript
// before: create, store, done
const sub = await graph.createSubscription(token);
await kv.set(key, sub);
// after: the owner may have gone during the call
const sub = await graph.createSubscription(token);
await kv.set(key, sub);
if (!(await connectionStillExists(accountId))) {
  await graph.deleteSubscription(token, sub.id);
  await kv.delete(key);
}

02 · Run it on your appThe check

If a user disconnects an integration in the second your app is still setting it up, is anything left running on the third-party side?

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.