NoSQL Concepts: Key-value database

NoSQL Concepts: Key-value database

Relational Databases vs NoSQL

Relational DatabasesNoSQL
Use tables/rows/columnsDon't Use tables/rows/columns
Need a predefind schema / complicated to change structureSchema less / easy change structure
Slow queries when joining multiple tablesFast queries
Vertically scalable + More expernsiveHorizontal scalable + Cheaper
Guarantee ACID transactionsMost don't support ACID transactions

Types of NoSQL Databases

  • Key-value database
  • Document database
  • Column family database
  • Graph database

Key-value databases

  • Such as map data structure
  • Is a simplest NoSQL databases
  • Set / Get values with associated key

Key must be unique and not good option to have long keys because they will use more memory.

Advantages of key-value databases

  • Very simple

    • Key-value tuple
    • Not defined schema
    • Basic operations such as Put, Get and Delete
  • Very flexible

    • Allow changes in data type such as User12 = 0111, User12 = "Giza"
    • Add additional attributes such as User12 = {"lang": "en:US"}, User12 = {"lang": "en:US", "Color": "green"}
  • Information stored in memory
    • Fast read & write
  • Scalability
    • Sharding => distributes different parts of the data accross multiple servers

Limitations of key-value databases

  • Just search by key
    • Problem if we don't the key !!!!!!!!
    • Some key-value databases added functionalities to avoid this problem
      • Search by value
      • Add secondary index
      • Search by serveral key simultaneously
    • Not complex query

Suitable cases for value-key databases

  • Shopping carts

    • Key => UserID
    • Value => shopping cart information
  • Real time recommendations

    • Key => UserID
    • Value => items that user like it

The most popular key-value databases is "Redis"