I'm new to server-side programming and I'm building a small "test" web application in NodeJS. Each time the clients need to view data from the PostgreSQL database, NodeJS will execute a "SELECT" query and will give me the result in JSON (which I then add to a webpage and serve it to them). Instead of executing a "SELECT" query every time I wanted to get data, the server could keep a JSON version of the tables and update them each time data is added, edited or removed

Does this have any drawbacks?

  • 3
    Are you trying to cache the data? en.wikipedia.org/wiki/Cache_(computing) Commented May 30, 2018 at 1:54
  • Sure the server can hold some data duplicated in two very different forms. But why? And what is the point of storing some data of a table in a JSON file when each SELECT query produces just specific rows and columns from one table, or maybe some cross join? Sounds more like some vague, half-baked solution looking for a problem.
    – Doc Brown
    Commented May 30, 2018 at 3:39

1 Answer 1


Basic Drawbacks

Excess complexity, redundancy. More potential for bugs (more paths through more code), more time to develop, test, and more cost to maintain, forever.

Stale Data

The moment the data in the database changes from some other source than this service, the server starts returning incorrect (or at least stale) data. You get to experience cache that is inconsistent with persistent data. That's quite educational.

Scale Out and Cache Consistency

As soon as the test app scales to thousands of users (most test apps do that, right?) and you add more servers, you will have a cache consistency problem, where each of those servers has its own copy of that JSON cache, and the copies may give different results to requests.

Concurrent Modification

What happens when many concurrent requests come in from multiple users? How do you insure that each user sees up to date information and that no user's changes are lost? It's quite solvable. The database can provide this service. How will you provide it for JSON? It's a great learning opportunity, but is this your priority now?

But Caching Is Sometimes A Good Idea

There is a place for caching. Sometimes it's needed for performance. If the time to retrieve data from the database is "fast enough" then there's no need for cache.

Maybe Learning Is Your First Priority

You are building a test application. It's your sandbox. If you feel like having an intermediate JSON cache, there is no need to justify it.

Just do it, and learn from the experience.

  • Thank you for the long answer and explanation! I will try to query to the database directly on each request and will learn about caching when necessary :) I really needed the perspective of someone with more experience. Commented May 30, 2018 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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