Data Storage & Databases

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:
    • Database:
      • 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

Screen Shot 2017-12-22 at 10.51.08 AM.png

ORM: softwares such as Sequelize that provide Javascript-like syntax for interaction with databases.

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.

Screen Shot 2017-12-22 at 11.14.19 AM

By referring to data in columns of other tables rather than duplicating the data in two tables, it’s more memory efficient.


join table: breaks many-to-many relationship into one-to-many relationships.


Data Storage & Databases

Hackerrank Day 28: Regex Patterns & Databases

RegEx (Regulation Expressions)  

This is a means of describing a set of strings using a subset of common characteristics. For example, the common characteristics of aaa, aba, and aca are that they all start and end with the letter a.

Regular expressions add a level of abstraction to strings that makes it easier to search and manipulate text. While they can seem very confusing at first, the syntax for regular expressions is pretty standard across different programming languages.

This is a good guide for common regex used in Ruby.


Could not solve this problem using RegEx in Ruby and could not find anyone else that did either so I’m frustrated, but I don’t feel too bad.  :/

Solution without RegEx:


Talked to Thomas and he suggested removing the .com and just search of emails that have ‘@gmail’ so we can avoid dealing with the period.  Pretty smart!

Solution with RegEx: 







Hackerrank Day 28: Regex Patterns & Databases