I have a Nest.js application, and lately I've been thinking about how I can ensure that data is synchronized between two sources - my database and an external database.

For example - and to my question - is my database versus Stripe's database. I have plans with recurring payments, and I track how many licenses a customer pays for in my database. Of course, Stripe is the single source of truth for that data, so I like to make sure that my data matches Stripe's data.

Of course, in theory my backend will never get out of sync with Stripe's as long as I code everything correctly - but is that enough?

Lately, I've been wondering about some sort of health checks that happen OUTSIDE of the flow of some request handling that my server does.

For example, if a user goes to their "Members" screen, which is the screen from which new licenses may be paid, I "GET USER MEMBERS". Would it be appropriate to fire off an asychronous process and NOT await its response? Like so:

async getMembers(userId) {
    const members = await *the db call that gets members*;
    *some async process to sync data - note lack of await*;
    return members

Does this sort of behavior break anything? What if the non-awaited async process errors?

Thanks for any advice/opinions.

1 Answer 1


No it's a bad idea to fire off extra sync calls triggered by unrelated actions.

So I'm guessing from your question that your database, or at least this part of it is kind of a cache of the stripe data. You don't want to hit stripe every time so you store your copy and run queries against that instead, but there's no push of changes from stripe to trigger check events or anything so the only event you have is the user query.

But you can totally have a separate offline process unrelated to the user which does a sync check on a schedule or in response to other events.

Lets imagine a situation where you have 100 users, and you are pulling some sort of marketing report about who bought what.

  • The "offline process" loops through each user and makes the call to stripe. compares with the local data, updates if required and sends an alert if there is an unexpected difference. It makes 100 calls, one for each user, every day spread over the 24h

  • The "sync on button click" fires when a user logs in, queries stripe for that users data, updates as required and send an alert if different. It makes and average 3 calls a day, spread over the same 20 active customers, during office hours. Sometimes it makes hundreds of calls in the same hour because a user is hammering the site for some reason.

You can immediately see that the offline process is superior because you have more control over when and how it runs.

Lets go further and say that before you run your report you want to be doubly sure of the numbers. Maybe elon is going to pull out of the takeover deal or something. You can do an unscheduled run of the offline process and sync all 100 customers right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.