user5282069
user5282069

Reputation:

Storing user data in JSON files on server

I am building a web application that uses PHP and MySQL on the backend. I want to store some user data -- basically a set of objects in JSON format that detail the user's "favorites" info for the application. I don't want to store this JSON data in a single MySQL field in my user database table because it doesn't seem efficient.

So, I am thinking to just store the JSON data in a flat file on the server with a unique identifier that I can use to know which user the file is associated with. My questions is: would this be a scalable solution for upwards of 10,000 users?

Upvotes: 2

Views: 1971

Answers (1)

elixenide
elixenide

Reputation: 44823

This is likely to cause you lots of headaches, both in terms of technical aspects and in terms of security. And no, it's not very scalable. Think about the problems it will cause: What happens when you need to add a server? How will you sync the files? What if you want to do something involving multiple users, like seeing how many people have XYZ as a favorite?

A much better option is to do one of the following:

  • Normalize your database (do this part regardless) and put the favorites in their own table or
  • Save the favorites in a JSON column (probably the wrong answer, but makes sense in some contexts)

If you're worried about speed, you can implement some caching using Redis, memcached, or some other system. But do not do this yet - that's premature optimization. Do it when you need it.

Upvotes: 2

Related Questions