Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

isaackearl's avatar

Hoping for advice! Want to allow users to create there own data storage structure... meta or scaffold?

So...

I essentially am thinking of creating a tool that will allow some users to store data... essentially allow them to store objects. This is mainly an experiment but I want to do it as if it were a really important project.

Use case would essentially be that a user would Name and describe an Object in the browser... and then information into that object via normal crud operations.

The tricky part is figuring out the proper way to store and scale this... Essentially I see two options.

#1 Create an objects table that essentially contains all the meta data for an object and then another table that stores the object information in json format... This would potentially end up being very slow because one table could end up representing many different types of entities etc. If I were in a real world scenario I could end up with millions of rows in a table with semi expensive operations since everything would be stored as json...

#2 Whenever a user creates a new account, run some scaffolding behind the scenes that actually creates a new database for that particular user... then when they create these "objects" I could actually create a table for each object etc. Cons are that this would be hard and I don't know how practical it is for each user to get there own database... But it would be faster to access data etc because it wouldn't be from a shared table with all the other users, and it wouldn't be so abstract... having to query the metadata for what the data should be etc.

#3 3rd option is something similar except maybe just make a new table in the database for each user instead of making a new database...

#4 ? Any other ideas?

This is all purely an exercise for me, and not something very important. Just don't have anybody around to discuss or brainstorm with so I'm wondering if anybody has thoughts.

Thanks!

0 likes
4 replies
insanealec's avatar

Would the user be able to define methods for their objects, or only as data storage. You mention JSON, so what about using some NOSQL database that just stores JSON? Redis could also work for this if they're just defining objects that you're storing.

isaackearl's avatar

@insanealec . The user wouldn't define methods. They would essentially get basic crud operations for the object, and also some options they can turn on and off for the object as a whole, and for each property.. such as making the object read only, or making it cacheable and setting a cache time... Or setting a property so it is not nullable etc.

Thanks for the suggestions... I haven't used a NoSQL database before and this might be a good opportunity for me to give it a shot... I'll go look up some pros and cons of storing the data this way.

insanealec's avatar
Level 4

I've been using probably way too much JSON lately, so hopefully what I'm about to say is actually a good idea, haha.

Creating a table for each object seems like a bit much to me, but that may be the route you want to go if that's what you're familiar with.

You could try storing all of the meta data within the object itself. But sort of hiding that data when it's displayed or used.

"obj1": {
    "key1": {
        "value": "Value for this key.",
        "meta": {
            "readonly": true,
            "cacheable": true,
            "cachetime": 10000,
            "nullable": true
        }
    },
    "key2": {
        ...
    }
}

I don't know if it's clear from above, but you can have a meta object within each property/object of each object which holds the metadata that the user can set. So you allow them to create an object with it's key/value pairs, but allow them to define metadata with different crud operations. Then whatever way you choose to store it you can just store the entire JSON as a stringified version in the database or within some sort of NOSQL storage specifically for JSON.

isaackearl's avatar

@insanealec wow! thanks for the detailed response. I think I'm going to end up doing something exactly like this. Now I need to research my storage options.

Thanks!

1 like

Please or to participate in this conversation.