2

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?

elixenide
  • 44,308
  • 16
  • 74
  • 100

1 Answers1

2

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.

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • Great points Ed. Your comment about looking across multiple users is spot on. I was originally thinking to use IndexedDB on the client side, but that makes multiple user analytics a lot harder. I think I will look at a MySQL solution, even if it is not ideal. –  Jun 12 '16 at 14:51
  • Ed I also noted that MySQL 5.7 provides native support for JSON data. I'm on an older MySQL 5.6 version, so I'm going to upgrade and test out JSON retrieval/storage. –  Jun 13 '16 at 14:58
  • @Yves Good luck, and I'm glad I could help! – elixenide Jun 13 '16 at 15:02