title: Incrementing hundreds of counters at once, redis or mongodb?
body: <p><strong>Background/Intent:</strong></p>
  
  <p>So I'm going to create an event tracker from scratch and have a couple of ideas on how to do this but I'm unsure of the best way to proceed with the database side of things. One thing I am interested in doing is allowing these events to be completely dynamic, but at the same time to allow for reporting on relational event counters. </p>
  
  <p>For example, all countries broken down by operating systems. The desired effect would be:</p>
  
  <ol>
  <li>US # of events
  <ul>
  <li>iOS - # of events that occured in US</li>
  <li>Android - # of events that occured in US</li>
  </ul></li>
  <li>CA # of events
  <ul>
  <li>iOS - # of events that occured in CA</li>
  <li>Android - # of events that occured in CA</li>
  </ul></li>
  <li>etc.</li>
  </ol>
  
  <p>My intent is to be able to accept these event names like so:</p>
  
  <pre><code>/?country=US&amp;os=iOS&amp;device=iPhone&amp;color=blue&amp;carrier=Sprint&amp;city=orlando&amp;state=FL&amp;randomParam=123&amp;randomParam2=456&amp;randomParam3=789
  </code></pre>
  
  <p>Which means in order to do the relational counters for something like the above I would potentially be incrementing 100+ counters per request.</p>
  
  <p>Assume there will be 10+ million of the above requests per day.</p>
  
  <p>I want to keep things completely dynamic in terms of the event names being tracked and I also want to do it in such a manner that the lookups on the data remains super quick. As such I have been looking into using redis or mongodb for this.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li><p>Is there a better way to do this then counters while keeping the fields dynamic?</p></li>
  <li><p>Provided this was all in one document (structured like a tree), would using the $inc operator in mongodb to increment 100+ counters at the same time in one operation be viable and not slow? The upside here being I can retrieve all of the statistics for one 'campaign' quickly in a single query.</p></li>
  <li><p>Would this be better suited to redis and to do a zincrby for all of the applicable counters for the event?</p></li>
  </ol>
  
  <p>Thanks</p>