title: DDD and Node.js: Good practice to have a repository with async callbacks?
body: <p>Here's the thing: </p>
  
  <ul>
  <li>a client shouldn't be aware of the persistence mechanism used by a repository</li>
  <li>When, say, implementing a repository with MongoDB as persistence store, retrieving a value is done through async-callbacks</li>
  <li>a sync call can still be implemented using a callback, a async-call MUST be implemented using a callback. (Or futures, etc. but I don't want to go there) </li>
  </ul>
  
  <p>To me means that repositories (at least for fetches) should have a callback defined in the interface, even though the implementation happens to be synchronous, e.g: </p>
  
  <pre><code>var repo = {
      cache: {},
      getById: function(id,callback){
          callback(null,this.cache[id]); 
      }
  }
  </code></pre>
  
  <p>Since I might (will) change this soon to something like: </p>
  
  <pre><code>var repo = {
      getById: function(id,callback){
          mongoose.findOne({_id:id},callback);
      }
  }
  </code></pre>
  
  <p>IMHO, for C/U/D the same need arises primarily for error reporting from the persistence layer. </p>
  
  <p>in short: Do you consider it best practice to define repositories (in Nodejs, although not really relevant) with async callbacks? </p>