dimanche 19 juin 2016

Storing key value pairs in SQL / Stats Aggregator

I'm writing a web application that needs to periodically collect data from an API and perform analysis on these stats to produce a dashboard for unique users. There are 236 unique 'stats' coming in from the API per user which are essentially key value pairs, where the value consists of either a string or number (or time duration or percent).

I'm trying to figure out how best to store this data. One option I thought of which would be the simplest approach was to store the raw JSON response against a userId and perform all analysis from that JSON. The obvious issue with this is that I need to be able to query the data easily and do things like ordering different users by one of the 236 unique stats. The other option would be in a relational database.

If I were to go the relational route, how is it best to store snapshots of data like this? I imagine creating a column for each of the 236 stats would be a bit of a mess, and annoying to add to in the future. I've looked at other relatively similar questions but haven't found anything right for me.

My thoughts so far:

  • Create a StatsType(id, typename) containing 236 rows,
  • and a UserStats(statid, userid, typeid, value, date_added) table, containing 236 rows for each user update from the API.

Would this end up being too huge as the app grows? (Think 200,000+ users) Thoughts would be much appreciated

Aucun commentaire:

Enregistrer un commentaire