Tracking page views with MongoDB

by Alex Popescu

After looking at 4 different alternatives — Google Analytics, sharding existing MySQL database, ETL process (nb log processing) and MongoDB, Eventbrite decided to go the MongoDB way dismissing the other approaches:

  • Google Analytics
    • Time-consuming to set up and test
    • Migrating existing page-view data is tricky
    • Not real time
  • Shard the MySQL table
    • Requires downtime to make schema changes
    • Introduces routing at the code level
    • Would still be prone to row locks if we outgrew # of shards
  • ETL process (aka, write to log file and have a process that aggregates and periodically writes to the database)
    • No data integrity
    • Not real time
    • Requires management of log files over multiple web servers

While the post doesn’t really detail the reasons why MongoDB would be able to solve this problem, there are a couple of MongoDB features described in this ☞ post that make it a good fit for this scenario.

Basically, the solution is based on a combination of the following MongoDB features:

  • upsert and $inc operators
  • write operations returning immediately (without waiting the server to effectively confirm a write)
  • $inc operator is a very good replacement for a read-modify-update scenario
As a side note, remember there’s another MongoDB based tool: Hummingbird that provides real time web traffic visualization.

This post is part of the MongoDB case studies series.