1

I've built a website using node js and it has two parts. one for users and one for website administrators for editing content on website that is locked by a login page. The user side, loads data from local json file and administrators side, loads data from mysql database. I want to know is it better to use mysql on both sides for increased performance? I am new in programming and I'm a bit confused between mysql Connections and Pools. Which one is better for performance if I have a lot of users receiving data?

this is the function for receiving data:

function getAllProductsLocal() {
    try {

        const products_json = JSON.parse(fsExtra.readFileSync("./public/assets/JSON/products.json"));
        return products_json;
    
    }catch(e) {
        throw e;
    }    
}

and this is an example of the data I'm storing in JSON file:

{
    "ID": 19,
    "Cost": 212,
    "Sizes": "[4,7]",
    "Category": "man",
    "Color": "blue"
}

there will be a hundred of them

4
  • I doubt that the user will be glad if you force him to install MySQL. So for client side use either plain text file (JSON) or some embedded DBMS (SQLite, for example). Which one is better for performance On the client - depends on data amount. On the server - DBMS, of course. – Akina Feb 11 at 11:40
  • @Akina I don't understand, wouldn't the User be connecting to a remote database (via the app) if OP switched to MySQL?...it's a website. I wouldn't think they'd need to install anything? – J.D. Feb 11 at 12:20
  • excuse me. I think I didn't explain it clearly. I mean the node js app sends data to user viewing website from a local JSON file saved on the server in a directory. every time user sends a request to "/products" node app reads data from JSON file using fsExtra. I think this will not work well with a lot of requests. I just want your experience about it. will JSON file affect performance with a bunch of users? – Parham Moieni Feb 11 at 12:35
  • I mean the node js app sends data to user viewing website from a local JSON file saved on the server in a directory. On what side the file mentioned in the phrase "The user side, loads data from local json file" is local??? Does this file is posessed on the server or on the client? – Akina Feb 11 at 12:48
0

The question really depends on what kind of querying of the JSON data you're doing, but I suspect if your data grows large enough (or when your use cases become complex enough) you'll find the file processing operations you're doing with fs-extra will be outperformed by the equivalent operations in a database, such as MySQL, especially because you mentioned the JSON file is accessed remotely since it's stored on the server, rather than the client's end.

I think local JSON files are good on the client's end for simple things like user app settings and user preferences, and fine to store on the server for basic things like the navigation menu's structure of the website, for example. But I wouldn't plan to store the main data of the application in a file, rather you'll likely be better off storing it in a database.

7
  • 1
    thank you for your answer. I edited my question and added function and a data sample. – Parham Moieni Feb 11 at 13:32
  • @ParhamMoieni If there's ever a case where you don't want all the products, any kind of filtering, etc, then the fact you need to read and parse the whole file with the JSON solution is always going to be slower than a database driven solution. – J.D. Feb 11 at 15:18
  • thanks. I have to use MySQL pools instead of connection. right? – Parham Moieni Feb 11 at 19:40
  • @ParhamMoieni I'm not an expert on MySQL implementation, but I assume you mean connection pooling vs persistent connection. You can use either but I couldn't advise when to use one over the other, but maybe this StackOverflow answer could help you out. – J.D. Feb 11 at 20:12
  • 1
    thank you for your help. It really helped me. – Parham Moieni Feb 11 at 21:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.