Serving static pages for users can be suitable for landing pages, or for personal blogs. However, if you want to deliver personalized content you have to store the data somewhere, and there are two ways to do that:
Volatile/Temporary Memory (RAM):
- Extremely fast but expensive.
- Memory resets each time you restart your application so data is not retained.
- If you don’t clean up, you can end up with stack overflow.
- Variables are stored in RAM.
Non-volatile/Permanent Memory (hard drive):
- Slow but inexpensive.
- Data has to be serialized, or translated, into a format that can be stored or transmitted and reconstructed later. An example of serialization is JSON.stringify() and JSON.parse().
- Data persistence is achieved by saving a program state in non-volatile memory because data is retained when you restart your application.
- There are two ways to store data in your hard drive:
- A giant excel sheet that you can add, remove, or update data that you want to persist.
- You would not want to store large data such as asset files in the database.
- File System (fs):
- Assets like images and videos are usually stored in your file system (and referenced from your database).
- Your file system is stored in your hard drive along with your database (if you have one).
- use ID index to achieve O(1)
- records are stored in JSON and need to be parsed to find particular field.
- You don’t have to define a schema and you can store any arbitrary JSON.
- Example: PostgresSQL
- use array-like techniques (fixed width data format) to achieve O(1)
- Have to define schemas.
- faster at computing relationships because
- it can skip ID indexing step (ID -> Disk Location).
- records are stored in binary format (not JSON) and fields are always in the same location in every record.
- Example: mongoDB
Schemas: description of the way data is organized in a database.
- PRIMARY KEY: A column with primary key means the value of the column is unique. Primary keys from one tables are often referred to in other tables.
- FOREIGN KEY: When the value of a column is intended to refer to a column in another table, it is called a foreign key.
By referring to data in columns of other tables rather than duplicating the data in two tables, it’s more memory efficient.
SCHEMA & QUERY DESIGN
join table: breaks many-to-many relationship into one-to-many relationships.