Regenerate state after a server crash

I'm working on a solution for "state regeneration" of a web app after a crash. For example, my app is able to create invoices, and is using an idCounter for numbering these invoices. If the app crashes, the last invoiceNr need to be fetched from the DB and used to reset the idCounter.

In my route module, I have code that looks like this:

var idCounter = null;

db.invoices.findOne({}, null, {sort: {'invoiceNr': -1}}, function(err, doc) {
    if (err) {
        return next(err);
    }
    idCounter = doc.invoiceNr;
}); 

This works well, but I'm concerned that the icCounter is set trough a callback, which means (in theory) a user can trigger some code that need the idCounter (Like creating a new invoice) BEFORE the callback is triggered, and therefore get the wrong variable...

What kind of pattern do you use for "state regeneration" after a web app crashes?