Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From Relational To Document

Norberto
October 09, 2013

From Relational To Document

#tech4africa presentation

Norberto

October 09, 2013
Tweet

More Decks by Norberto

Other Decks in Technology

Transcript

  1. Key -> Value •  One-dimensional storage •  Single value is

    a blob •  Query on key only •  No schema •  No updates just replaces Key Blob
  2. Relational •  2-dimensional storage (tuples) •  Each field contains one

    value •  Query on any field •  Very structured schema (tables) •  In-place updates •  Normalization requires many tables, joins, indexes •  Poor data locality Primary Key
  3. Document •  N-dimensional storage •  Each field can contain 0,1,

    many or embedded values •  Query on any field & level •  Flexible schema •  Inline updates •  Embedding related data has optimal data locality, requires fewer indexes, has better performance _id
  4. Break Joins Removing Transactions Remove Foreign Keys Multi Field Tables

    BLOBS of XML What the hell is this data doing in RDBMS? Path to DeNormalization (Sanity)
  5. My Database Professor at University “You normalize it till is

    correct, then you denormalize till it works”
  6. { "_id" : 451152, "amenity" : "pub", "name" : "The

    Dignity", "addr:housenumber" : "363", "addr:street" : "Regents Park Road", "addr:city" : "London", "addr:postcode" : "N3 1DH", "toilets" : "yes", "toilets:access" : "customers", "location" : { "type" : "Point", "coordinates" : [-0.1945732, 51.6008172] } } Example of Document
  7. Relational MongoDB { ! first_name: ‘Paul’,! surname: ‘Miller’,! city: ‘London’,!

    location: [45.123,47.232],! cars: [ ! { model: ‘Bentley’,! year: 1973,! value: 100000, … },! { model: ‘Rolls Royce’,! year: 1965,! value: 330000, … }! }! }! Document Data Model
  8. Document Model Benefits •  Agility and Flexibility –  Data models

    can evolve easily –  Projects can adapt to changes quickly •  Intuitive, natural data representation –  Developers are more productive –  Many types of applications are a good fit •  Reduces the need for joins, disks seeks –  Programing is more simple –  Performance can be delivered at scale
  9. class Pearson{ String name; String passport; int age; String []countries_visited;

    Nationality nationality; } class Nationality{ String country; String name; } Seamless Integration
  10. { _id: ObjectId(), name: “Norberto”, passport: “S3CR3T”, age: 30, countries_visited:

    [‘Brasil’, ‘Portugal’, ‘Spain’, ‘Italy’, ‘Israel’ …], nationality: { country: ‘Portugal’, name: ‘Portuguese’ } } To Documents
  11. Most logical comment I’ve ever heard “Requirements are like ice

    skating, only works when they are frozen”
  12. This field should be VARCHAR2 Need FK on this other

    Don’t need this relation after all
  13. Denormalize •  Break Joins •  Remove Transactions •  Merge Tables

    •  Merge Fields •  Temporary Tables •  Transient Data Structures