title: API - Should aggregation be done in the front-end or back-end app?
body: <p>I have written an API which retrieves data from a MongoDB database.
  I also have a front-end application which uses the data from the API (both applications are written in Node JS using the Koa framework if it's relevant)</p>
  
  <p>I need to do an aggregation of a large set of numerical data, over a given period that would need calculating (averaging, quintiles etc), and this could be all data grouped by month, grouped by year or by personID.</p>
  
  <p>I've read some examples where people say that the API should be used as a wrapper for the database layer, presenting access only to the raw data - but it makes sense to me that the logic would live on the database (rather than asking the front-end application to churn over the data).</p>
  
  <p>Is this a common problem, and from your own experience - is it be better to get the API to do the aggregation, or the front-end application?</p>
  
  <p><strong>Example documents</strong></p>
  
  <pre><code>{
      "date": ISODate("2016-07-31T07:34:05+01:00Z"),
      "value": 5,
      "personID": 123
  },
  {
      "date": ISODate("2016-08-01T12:53:05+01:00Z"),
      "value": 3,
      "personID": 789
  }
  </code></pre>