INF397 Full Stack Technologies View Schedule Print

Databases basics

Various Data Models:

  • Relational: MySQL, Postgre, Oracle
  • Key-Value: Raik, Redis
  • Document-based: MongoDb, Couchbase
  • Columnar: Hbase, Cassandra
  • Graph: WhiteDB, Trinity, neo4j

Relational:

  • SQL
  • Normalized data - Related Rows in Tables
  • Row values are stored continuously

Example: Get all Oscar winning movies directed by someone born after 1985


    SELECT movies.*
    FROM oscar_winners
      JOIN movies ON (oscar_winners.movie_id = movies.id)
      JOIN directors ON (movies.director_id = directors.id)
    WHERE directors.year_of_birth > 1985
  

Key-Value

  • Fast and Simple
  • Easy to use, easy to scale
  • Don't support complex queries

Example: Using Redis with Python


    import redis
    pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
    redis = redis.Redis(connection_pool=pool)
    redis.get('title') //some value
    redis.set(user_id, session_string)
  

Document-based

MongoDB: database for JSON documents
  • the basic unit of storage is the JSON object
  • uses javascript as the query language
  • highly cohesive with node.js
  • like every technology it has its limitations
Concepts:
SQL MongoDB
database  =  database
table  =  collection
row  =  binary JSON document
column  =  field
index  =  index
table joins  =  embedded documents and linking

      //inserting a document into the books collection
      //with an embedded author document
      //and an array of related works ids
      db.books.insert({
          "isdn": "2414993-2204",
          "title": "To ask a foolish question",
          "author": {
                  "name":"Robert Sheckley",
                  "occupation": "Sci-fi author"
          },
          "first_published_on": ISODate("1953-03-11"),
          "related_works_ids": [MongoRef("77a2bc3"), MongoRef("32d3298")]
      });
  

    //querying the database
    //for the book with the given isdn
    db.books.find({ isdn: "2414993-2204" });

    //for books with a specified genre
    db.books.find({ genre: { $exists: 1 });

    //for books published after the given date
    db.books.find({
        first_published_on: {$gt: ISODate("1987-03-11")}
    });

    //for books with an author name
    //matching the the regular expression
    db.books.find({ "author.name": /Sheckley/ });

Columnar

  • Hierarchical storage model
  • Rows are constructed from sets of columns
  • Column values are stored continuously

Using Hbase with Java


  public String GetClicks(String action, String date, byte[] column)
    throws IOException {
      try (Connection conn = ConnectionFactory.createConnection(config)) {
        Table table = conn.getTable(TableName.valueOf(TABLE_NAME));

        Get get = new Get(makeKey(date, symbol));
        get.addColumn(COLUMN_FAMILY, column);

        Result r = table.get(get);

        if ( r.isEmpty() ) return null;

        return new String(r.value());
      }
  }
  

Graphs

  • Nodes & Edges
  • Model complex relationships
  • Many data storage options

Graphs

Using Neo4j


    MATCH (p1:Person {id: "me"})-[r:Follows]-(p2:Person {interest: "juggling"})
    RETURN p1.name, r, p2.name; //Misho Follows Wes Peden
  

Many others

  • Full-text: Elastic search
  • Cloud-based storage: S3, DocumentDB, BigTable
  • Redis provides many types of data structure as a service

Course Schedule:

week 1 03.02.2017 History of the web Fullstack Principles Development Processes Agile Processes DevOps Basics Git
week 2 10.02.2017 Frontend Overview Backend Overview Network Overview Testing JavaScript Overview JavaScript Tooling
week 3 17.02.2017 Web Architectures RESTful principles SOLID principles Web Components Continuous Integration
week 4 24.02.2017 Databases basics Using APIs Deployment Automation Monitoring In-class project consultations
week 5 17.03.2017 Project presentations
Final Test
Course Retrospective and Q&A