Chapter 5. Storing Node application data


This chapter covers

  • In-memory and filesystem data storage
  • Conventional relational database storage
  • Nonrelational database storage

Almost every application, web-based or otherwise, requires data storage of some kind, and the applications you build with Node are no different. The choice of an appropriate storage mechanism depends on five factors:

  • What data is being stored
  • How quickly data needs to be read and written to maintain adequate performance
  • How much data exists
  • How data needs to be queried
  • How long and reliably the data needs to be stored

Methods of storing data range from keeping data in server memory to interfacing with a full-blown database management system (DBMS), but all methods require trade-offs of one sort or another.

Mechanisms that support long-term persistence of complex structured data, along with powerful search facilities, incur significant performance costs, so using them is not always the best strategy. Similarly, storing data in server memory maximizes performance, but it’s less reliably persistent because data will be lost if the application restarts or the server loses power.

So how will you decide which storage mechanism to use in your applications? In the world of Node application development, it isn’t unusual to use different storage mechanisms for different use cases. In this chapter, we’ll talk about three different options:

5.1. Serverless data storage

5.2. Relational database management systems

5.3. NoSQL databases

5.4. Summary