DAL for mongoDB

Up until now our node.js project used a class we built (cache.js) that holds various collections in-memory. A Data Access Layer is used to abstract the data from the logic, and to allow us to easily add a persistency later on. This dal.js makes synchronous call to cache.js for all CRUD operations.

Now time has come, and I want to hook MongoDB to the DAL instead of this cache.js. Problem is that mongoDB + node.js philosophy is to call the DB asynchronously with a callback.

Should we redesign all of our app (including the classes that use the DAL)? Isn't too complicated and wrong to enforce the business logic to use callbacks on every CRUD they need? What are the best practices to maintain KISS (I know mongoose can help as well, but not directly)?

Depending on your scalability model, you could consider synchronizing the in-memory model periodically. Something like that:

var model = {
  x: 5
};

setInterval(function() {
  if (is_model_changed(model)) write_to_db(model); // <-- this can conflict with other changes
  model = read_from_db();
}, 5000);

You should probably have some form of server affinity (per shard/user) in this case so to try to avoid conflicts when writing to the database as much as possible.