JSON Strings – Storing Large Data for Many Users

jsonMySQLPHP

I have a website that allows users to be "tracked" and track their time/work. This involves the users being able to update their account with my site at most every minute, but typically users do it only a few times per day. However, there is nothing stopping other people from updating your account.

Each update creates a datapoint, a snapshot if you will, of their account status and the amount of work they have done.

Users can view the amount of work they have done in the past day or past week. This is done by changing the range of the datapoints you want to see.

My question now, is: There is the very likely chance of having 300k+ users. There are also some user accounts which people follow more closely than others, say, a ceo or a manager, and so those accounts are going to be updated more often. This leads to there being a possible 100k+ data points for a single user, within the timespan of only a year or so.

Currently I was thinking of just storing these by the following mapping:

unixtime -> account snapshot

This seems like it would be easiest to store as a large json array for a user, for example (with other details I would store):

jsonArray = {
    "alice": {
        "totalHours": 31.6,
        "updates": {
            1515653260 : { work: 95%, hours: 8 },
            1515691399 : { work: 93%, hours: 10 },
            1515695125 : { work: 91%, hours: 7.6 },
            1515698694 : { work: 56%, hours: 6 },
         }
    }
     "bob": {
        "totalHours": 7.32,
        "updates": {
            1515654356 : { work: 95%, hours: 1 },
            1515690342 : { work: 93%, hours: 6.32 },
         }
    }
}

Is this an effective solution? I can't imagine a json string taking up so much space that MySQL wouldn't be able to hold it but I've never dealt with things that are likely to grow this large.

Are there other data structures I could use, or that would be more efficient in grabbing/storing data?

Best Answer

Your scoping requirements (300K+ users, 100K+ bytes per user) suggest the use of a relational database such as MySQL, or a document data store like MongoDB, not a JSON array. JSON is primarily a data transfer mechanism, not a storage mechanism, and it lacks the necessary tools (indexes, querying) that you'll need to effectively work with that much data.

Related Topic