agility with data modeling at directv using n1ql in couchbase with node.js: couchbase connect 2015

25
Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js Fidencio Garrido @elfidomx Github: theFido Isidro Salcedo @isidrosalcedo88

Upload: couchbase

Post on 11-Aug-2015

537 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.jsFidencio Garrido

@elfidomxGithub: theFido

Isidro Salcedo@isidrosalcedo88

Page 2: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

About UsDIRECTV is one of the world's leading providers of digital television entertainment services delivering a premium video experience through state-of-the-art technology, superior entertainment experience, and award winning customer service.

Offers over 3,000 SD, HD, 3D and 4K channels in the US alone

Higher customer satisfaction than the leading cable companies for 14 years running

Global presence servicing multiple countries across the entire western hemisphere.

Over 38 million subscribers around the world.

Page 3: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

The Challenge

Developing systems capable of supporting business changes in a fast pace environment.

Supports

• Additional metadata types (different versions of objects)

• Mixed configurations

• Reduction in code changes

Requirements

• Reliable

• Scalable

• High Performance

• Easy Administration (nice to have)

Options

• RDBMS

• Key-Value Stores

• Document DB

Page 4: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Architecture Goals

The overall architecture must perform as if your business depended on it… because it does!

●High Performance

●Reliability

●Scalability

●Easy to Manage

●Never be a constraint

Page 5: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Why Couchbase?

●Performance beast

●Easy setup / administration:●Monitoring tools

●REST Administration API

●All levels of scalability

●Almost flat learning curve (Thanks N1QL!)

●Expressive Language for Query

Page 6: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Couchbase Features

●Document Based

●Persistence + Cache

●Support of Views (map-reduce functions also written in JS)

●Separation of Concerns (index, query, data store)

●Fast Rebalancing

Page 7: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Couchbase N1QL Benefits

●Simplified Code●Reduce Code Complexity: Power of SQL

●Enable Ad-Hoc Queries: interactive queries with low latency with indexes

●Improves granularity of query consistency●Logical-timestamp at run time

●More processing on the server side

Page 8: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Why NodeJS?

●Fast I/O

●Native JSON Speaker

●Soft Typed

●Single threaded but asynchronous

●Light middleware layer provided by express

Page 9: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

API Design

●Stateless

●Fully REST Compliant●Resource Oriented (Avoiding Verbs)

●Using the Right Verbs

●Returning the Right HTTP Code

●Using HTTP Headers to Provide Metadata

Page 10: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Starting Design

API

API

APILB

BL

BL

BL

DAS

DAS

DAS

DB

DB

N1QLLB

API BL DAS N1QL

Page 11: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Clients Growing

API

API

APILB

BL

BL

BL

DAS

DAS

DAS

DB

DB

N1QLLB

API BL DAS N1QL

API BL DAS

Page 12: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

More Read han Write Operations

API

API

API

LBget

BL

BL

BL

DAS

DAS

DAS

DB

DB

N1QLLB

API BL DAS N1QL

N1QLAPI BL DASLBpostput

delete

Page 13: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

More Writes than Read Operations

API

API

API

LBget BL

BL

BL

DAS

DAS

DAS

DB

DB

DBLB

API BL DAS Index

N1QLAPI BL DAS

LBpostput

delete

Page 14: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

More Key Based Operation

API

API

APILB

BL

BL

BL

DAS

DAS

DAS

DB

DB

DBLB

API BL DAS

N1QL

N1QL

Index

Page 15: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Geographic Expansion

Enabling an architecture that scales across multiple data centers to support our global business.

Data Center #1 Data Center #2

XDCR

Data Center #4Data Center #3

Page 16: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Using Documents

●NodeJS is enough for the backend●Couchbase is great to store the information

and retrieve it using the document key but…

What happens when you want to use Couchbase as multipurpose Database System?

Can you really have the same capabilities as any other traditional SQL solution?Short answer…

Page 17: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Meet Couchbase N1QL

●A language that extends SQL capabilities to search into documents

●Supports search through complex structures

●Join operations for documents even if they belong to a different bucket

●Advanced features such as nesting and unnesting

●Index Support

Page 18: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Gentle Learning Curve

●A Language we were already familiar with

●Classic SQL

SELECT first_name, last_name FROM customers WHERE email = "[email protected]";

●N1QL

SELECT first_name, last_nameFROM bucketWHERE email = "[email protected]";

Page 19: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Ad-hoc Querying

{"_metadata": {

"document_type": "program","updated": "2015-06-02","last_user": "admin"

},"data": {

"cast_members" : [{ "person_id" : 14531, "role_id" : 1},{ "person_id " : 5983, "role_id" : 1}

]}

}

SELECT *FROM bucketWHERE _metadata.document_type = "program"AND ANY c_0 IN data.cast_members

SATISFIES c_0.person_id = 15415 END;

Page 20: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Analyze

EXPLAIN SELECT * FROM bucket WHERE _metadata.document_type = "program";

{ "resultset": [ { "input": { "expr": { "left": { "left": { "left": { "path": "dtv-ps-store-dtss", "type": "property" }, "right": { "path": "_metadata", "type": "property" }, "type": "dot_member" },

… }, "input": { "as": "bucket", "bucket": "bucket", "ids": null, "input": { "as": "", "bucket": "bucket", "cover": false, "index": "ix_document_type", "pool": "default",

Page 21: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Challenges

●Thinking in Documents●Think in the structure

●Visualize the queries you want to perform{ “user”: “dtv-user”, “phone”: [“(333) 333-3333”, “(444) 444-4444”] }

{ “user”: “dtv-user”, “platform”: [“iOS 7”, “Android 4”, “Windows 8.1”] }

OR{ “user”: “dtv-user”, “platform”: [123, 232, 342] }

●One Data Space{

“_metadata”: {“documentType”: “user”,“updated”: “2015-06-02”,“lastUser”: “admin”

},“data”: {

“user”: “dtv-002”,“state”: “active”,….

}}

Page 22: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Challenges

●Know your data flow: Use explain●Plan your infrastructure

●N1QL does processing… therefore it requires processors. Trust me, it knows what to do with them.

Page 23: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Roadmap

Support expanding business demands and data growth on common, easy to maintain, platform

Upgrade to Couchbase 4.0 to leverage Multi Dimensional Scale

Leverage the power of Global Secondary Indices for instant lookups and query at scale

Page 24: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

24

Our development toolkit

Page 25: Agility with Data Modeling at DIRECTV Using N1QL in Couchbase with Node.js: Couchbase Connect 2015

Questions