Chapter 8. Storing application data

 

This chapter covers

  • Relational databases: PostgreSQL
  • NoSQL databases: MongoDB
  • ACID categories
  • Hosted cloud databases and storage services

Node.js serves an incredibly diverse set of developers with equally diverse needs. No single database or storage solution solves the number of use cases tackled by Node. This chapter provides a broad overview of the data storage possibilities, along with some important high-level concepts and terminology.

8.1. Relational databases

For most of the history of the web, relational databases have been the dominant choice for application data storage. This topic has been covered at length in many other texts and university programs, so we don’t spend too much time elaborating on this topic in this chapter.

Relational databases, built upon the mathematical ideas of relational algebra and set theory, have been around since the 1970s. A schema specifies the format of various data types and the relationships that exist among those types. For example, if you’re building a social network, you may have User and Post data types, and define a one-to-many relationship between User and Post. Then using Structured Query Language (SQL), you can issue queries on this data, such as, “Give me all posts belonging to a user with ID 123,” or in SQL: SELECT * FROM post WHERE user_id=123.

8.2. PostgreSQL

8.3. Knex

8.4. MySQL vs. PostgreSQL

8.5. ACID guarantees

8.6. NoSQL

8.7. Distributed databases

8.8. MongoDB

8.9. Key/value stores

8.10. Redis

8.11. Embedded databases

8.12. LevelDB

8.13. Serialization and deserialization are expensive

8.14. In-browser storage

8.15. Hosted storage

8.16. Which database?

8.17. Summary