conceptos básicos. seminario web 1: introducción a nosql

42

Upload: mongodb

Post on 21-Apr-2017

7.642 views

Category:

Data & Analytics


2 download

TRANSCRIPT

Page 1: Conceptos básicos. Seminario web 1: Introducción a NoSQL
Page 2: Conceptos básicos. Seminario web 1: Introducción a NoSQL
Page 3: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Back to Basics 2016: Webinar 1Introducción a NoSQL

Rubén TerceñoSenior Solutions Architect, [email protected]@rubenTerceno

Page 4: Conceptos básicos. Seminario web 1: Introducción a NoSQL

¡Bienvenidos!

Page 5: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Agenda del CursoDate Time Webinar25-Mayo-2016 16:00 CEST Introducción a NoSQL 7-Junio-2016 16:00 CEST Su primera aplicación MongoDB 21-Junio-2016 16:00 CEST Diseño de esquema orientado a documentos 07-Julio-2016 16:00 CEST Indexación avanzada, índices de texto y geoespaciales 19-Julio-2016 16:00 CEST Introducción al Aggregation Framework 28-Julio-2016 16:00 CEST Despliegue en producción

Page 6: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Agenda de hoy• ¿Porqué existe NoSQL?

• Tipos de bases de datos NoSQL

• Características clave de MongoDB

• Tolerancia a fallos y persistencia de datos en MongoDB

• Escalabilidad en MongoDB

• Preguntas

Page 7: Conceptos básicos. Seminario web 1: Introducción a NoSQL

The origin of SQL (1979)

250 Mb$ 81.000/year

Dennis RitchieBrian Kernighan$ 8.000/year … (both)

Page 8: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Relational

Expressive Query Language& Secondary Indexes

Strong Consistency

Enterprise Management& Integrations

Page 9: Conceptos básicos. Seminario web 1: Introducción a NoSQL

The World Has ChangedData Risk Time Cost

Page 10: Conceptos básicos. Seminario web 1: Introducción a NoSQL

The origin of NoSQL

•Google y Amazon• Sistemas distribuídos• Open source• No relacionales

•2009 twitter hashtag #nosql

Page 11: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Scalability& Performance

Always On,Global Deployments

FlexibilityExpressive Query Language& Secondary Indexes

Strong Consistency

Enterprise Management& Integrations

NoSQL

Page 12: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Types of NoSQL Database

•Key/Value Stores

•Column Stores

•Graph Stores

•Multi-model Databases

•Document Stores

Page 13: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Consistency vs Availability

Reservas

NY…

Reservas

NY…

1 1

Page 14: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Key Value Stores• An associative array

• Single key lookup

• Very fast single key lookup

• Not so hot for “reverse lookups”Key Value12345 4567.345678712346 { addr1 : “The Grange”, addr2: “Dublin” }12347 “top secret password”12358 “Shopping basket value : 24560”12787 12345

Page 15: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Revision : Row Stores (RDBMS)• Store data aligned by rows (traditional RDBMS, e.g MySQL)• Reads retrieve a complete row every time• Reads requiring only one or two columns are wasteful

ID Name Salary Start Date

1 Ruben T $24000 1/Jun/1970

2 Peter J $28000 1/Feb/1972

3 Phil G $23000 1/Jan/1973

1 Ruben T $24000 1/Jun/1970

2 Peter J $28000 1/Feb/1972 3 Phil G $23000 1/Jan/1973

Page 16: Conceptos básicos. Seminario web 1: Introducción a NoSQL

How a Column Store Does it

1 2 3

ID Name Salary Start Date

1 Ruben T $24000 1/Jun/1970

2 Peter J $28000 1/Feb/1972

3 Phil G $23000 1/Jan/1973

Ruben T Peter J Phil G $24000 $28000 $23000 1/Jun/1970 1/Feb/1972 1/Jan/1973

Page 17: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Why is this Attractive?• A series of consecutive seeks can retrieve a column efficiently

• Compressing similar data is super efficient

• So reads can grab more data off disk in a single seek

• How do I align my rows? By order or by inserting a row ID

• IF you just need a small number of columns you don’t need to read all the rows

• But Updating and deleting by row is expensive

• Append only is preferred

• Better for OLAP than OLTP

Page 18: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Graph Stores• Store graphs (edges and vertexes)

• E.g. social networks

• Designed to allow efficient traversal

• Optimised for representing connections

• Can be implemented as a key value stored with the ability to store links

• If your use case is not a graph you don’t need a graph database

Page 19: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Multi-Model Databases• Combine multiple storage/access models

• Often Graph plus “something else”

• Fixes the “polyglot persistence” issue of keeping multiple independent databases consistent

• The “new new thing” in NoSQL Land

• Expect to hear more noise about these kinds of databases

Page 20: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Document Store• Not PDFs, Microsoft Word or HTML• Documents are nested structures created using Javascript Object Notation (JSON)

{ name : “Rubén Terceño”,title : “Senior Solutions Architect”,employee_number : 653,location : { type : “Point”,coordinates : [ 43.34, -3.26 ]},expertise: [ “MongoDB”, “Java”, “Geospatial” ],address : {address1 : “Rutilo 11”,address2 : “Piso 1, Oficina 2”,zipcode : “28041”,}}

Page 21: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Documents are Rich Structures{

name : “Rubén Terceño”,

title : “Senior Solutions Architect”,

employee_number : 653,

location : {

type : “Point”,

coordinates : [ 43.34, -3.26 ]},

expertise: [ “MongoDB”, “Java”, “Geospatial” ],

address : {

address1 : “Rutilo 11”,

address2 : “Piso 1, Oficina 2”,

zipcode : “28041”,

}

}

Fields can contain sub-documents

Typed field values

Fields can contain arrays

String

Number

Geo-Location

Fields

Page 22: Conceptos básicos. Seminario web 1: Introducción a NoSQL

• From the very first version it was a native JSON database

• Understands and can index the sub-structures

• Stores JSON as an serialized binary format called BSON

• Efficient for encoding and decoding for network transmission

• MongoDB can create indexes on any document field

• (We will cover these areas in detail later on in the course)

MongoDB really speaks JSON

Page 23: Conceptos básicos. Seminario web 1: Introducción a NoSQL

MongoDB is Full-Featured

Rich Queries Find all Solution Architects

Find all employees knowing Java in Support or Consulting

Geospatial Find all the employees currently in France

Text Search Find all employees describing themselves as “self-driven”

Aggregation Calculate the average distance to the Office for all employees

Map Reduce What are the most common skills by region over time (is node.js trending in Brasil?)

Page 24: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Nexus Architecture

Scalability& Performance

Always On,Global Deployments

FlexibilityExpressive Query Language& Secondary Indexes

Strong Consistency

Enterprise Management& Integrations

Page 25: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Development – The Past

{ CODE } DB SCHEMAXML CONFIG

APPLICATION RELATIONAL DATABASEOBJECT RELATIONAL MAPPING

Page 26: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Development – With MongoDB

{ CODE } DB SCHEMAXML CONFIG

APPLICATION RELATIONAL DATABASEOBJECT RELATIONAL MAPPING

Page 27: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Replica Sets

• Replica set – 2 to 50 copies• Replica sets make up a self-healing ‘shard’• Data center awareness• Replica sets address:

• High availability• Data durability, consistency• Maintenance (e.g., HW swaps)• Disaster Recovery

Application

Driver

Primary

Secondary

Secondary

Replication

Page 28: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Replica Sets – Workload Isolation

• Replica sets enable workload isolation• Example: Operational workloads on the

primary node, analytical workloads on the secondary nodes

eCommerce Application

MongoDB PrimaryIn-memory Storage Engine

MongoDB SecondaryWiredTiger Storage Engine

User DataSessions, Cart,Recommendations

MongoDB SecondaryWiredTiger Storage Engine

PersistedUser Data

Page 29: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Node 1

Node 2 Node 3

Replica Set Creation

Page 30: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Node 1(Primary)

Node 2(Secondary)

Node 3(Secondary)

Replication Replication

Heartbeat

Replica Set - Initialize

Page 31: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Node 2(Secondary)

Node 3(Secondary)

Heartbeat

Primary Election

Node 1(Primary)

Replica Set - Failure

Page 32: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Node 1(Primary)

Node 2(Primary)

Node 3(Secondary)

Heartbeat

Replication

Replica Set - Failover

Page 33: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Node 2(Primary)

Node 3(Secondary)

Heartbeat

Replication

Node 1(Recovery)

Replication

Replica Set - Recovery

Page 34: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Node 2(Primary)

Node 3(Secondary)

Heartbeat

Replication

Node 1(Secondary)

Replication

Replica Set - Recovered

Page 35: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Elastic Scalability: Automatic Sharding

• Increase or decrease capacity as you go

• Automatic load balancing

• Three types of sharding

• Hash-based

• Range-based

• Tag-aware

Shard 1 Shard 2 Shard 3 Shard N

Horizontally Scalable

Page 36: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Scalability with Sharding• Shard key partitions the content

• MongoDB automatically balances the cluster

• Shards can be added dynamically to a live system

• Rebalancing happens in the background

• Shard key is immutable

• Shard key can route queries to a specific shard

• Queries without a shard key are sent to all members• Each member process its part in parallel.

Page 37: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Query Routing

• Multiple query optimization models

• Each of the sharding options are

appropriate for different apps / use

cases

Page 38: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Query Routing• With a sharded cluster we use a routing layer to guide queries

• We use a daemon called MongoS (Mongo Shard Router)

• Daemon is stateless

• Can run as many as required

• Typically one per app server

Page 39: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Resumen• ¿Porqué existe NoSQL?• Tipos de bases de datos NoSQL• Características clave de MongoDB• Tolerancia a fallos y persistencia de datos en MongoDB• Escalabilidad en MongoDB

Page 40: Conceptos básicos. Seminario web 1: Introducción a NoSQL

Próximo WebinarSu primera aplicación MongoDB

• 7 de Junio 2016 – 16:00 GMT, 11:00, 9:00• ¡Regístrese si aún no lo ha hecho!• Aprenda cómo construir tu primera aplicación con MongoDB

• Cree bases de datos y colecciones• Cree queries• Construya Índices• Entienda cómo analizar el rendimiento

• Regístrese en : https://www.mongodb.com/webinars• Denos su opinión, por favor: [email protected]

Page 41: Conceptos básicos. Seminario web 1: Introducción a NoSQL

¿Preguntas?

Page 42: Conceptos básicos. Seminario web 1: Introducción a NoSQL