Migrating from RDBMS to MongoDB

46
RDBMS to MongoDB Migration Best Practices Mrinal Sarkar Solutions Architect m [email protected]

Transcript of Migrating from RDBMS to MongoDB

Page 1: Migrating from RDBMS to MongoDB

RDBMS to MongoDBMigration Best Practices

Mrinal SarkarSolutions Architect

[email protected]

Page 2: Migrating from RDBMS to MongoDB

2

• Relational Challenges• Migration Roadmap• Schema Design• Application Integration• Data Migration• Operational Considerations• Resources to Get Started

What We’ll Cover

Page 3: Migrating from RDBMS to MongoDB

Relational Challenges

Page 4: Migrating from RDBMS to MongoDB

4

Relational

Expressive Query Language& Secondary Indexes

Strong Consistency

Enterprise Management& Integrations

Page 5: Migrating from RDBMS to MongoDB

5

Relational Database ChallengesData TypesUnstructured dataSemi-structured dataPolymorphic data

Agile DevelopmentIterativeShort development cyclesNew workloads

Volume of DataTera-Peta Bytes of dataBillions of records‘000s of queries/sec

New ArchitecturesHorizontal scaling Commodity serversCloud computing

Page 6: Migrating from RDBMS to MongoDB

6

The World Has ChangedData Risk

Time Cost

Page 7: Migrating from RDBMS to MongoDB

7

NoSQL

Scalability& Performance

Always On,Global Deployments

FlexibilityExpressive Query Language& Secondary Indexes

Strong Consistency

Enterprise Management& Integrations

Page 8: Migrating from RDBMS to MongoDB

8

Nexus Architecture

Scalability& Performance

Always On,Global Deployments

FlexibilityExpressive Query Language& Secondary Indexes

Strong Consistency

Enterprise Management& Integrations

Page 9: Migrating from RDBMS to MongoDB

Migration Steps

Page 10: Migrating from RDBMS to MongoDB

Migration Roadmap

• Backed by Free, Online MongoDB Training• Paid Consulting, Services and Support available

Page 11: Migrating from RDBMS to MongoDB

Schema Design

Page 12: Migrating from RDBMS to MongoDB

DefinitionsRDBMS MongoDBDatabase Database

Table Collection

Row Document

Index Index

JOIN Embedded document, document references or $lookup to combine data from different Collections

Page 13: Migrating from RDBMS to MongoDB

SQL to Aggregation Mapping

Mapping Chart:http://docs.mongodb.org/manual/reference/sql-aggregation-comparison/

Page 14: Migrating from RDBMS to MongoDB

Mapping MongoDB Query Language to SQL

Mapping Chart:http://docs.mongodb.org/manual/reference/sql-comparison/

Page 15: Migrating from RDBMS to MongoDB

15

• Embedding– For 1:1 or 1:Many (where “many” viewed with the parent)– Ownership and containment– Document limit of 16MB, consider document growth– Atomicity of updates

• Referencing– _id field is referenced in the related document– Application runs 2nd query to retrieve the data– Data duplication vs performance gain– Object referenced by many different sources– Models complex Many : Many & hierarchical structures

Modeling Relationships:Embedding and Referencing

Page 16: Migrating from RDBMS to 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, … } ]}

Data Models: Relational to DocumentRelational MongoDB

Page 17: Migrating from RDBMS to MongoDB

Referencing Documents

Page 18: Migrating from RDBMS to MongoDB

18

RDBMS

Document Model BenefitsMongoDB

{ _id : ObjectId("4c4ba5e5e8aabf3"), employee_name: "Dunham, Justin", department : "Marketing", title : "Product Manager, Web", report_up: "Neray, Graham", pay_band: “C", benefits : [ { type :  "Health", plan : "PPO Plus" }, { type :   "Dental", plan : "Standard" }

] }

Page 19: Migrating from RDBMS to MongoDB

19

Anatomy of a BSON Document{ first_name: ‘Paul’, surname: ‘Miller’, cell: ‘+447557505611’ city: ‘London’, location: [45.123,47.232], Profession: [banking, finance, trader], cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } ]}

Fields can contain an array of sub-documents

Fields

Typed field values

Fields can contain arrays

String

Number

Geo-

Coordinates

Page 20: Migrating from RDBMS to MongoDB

Document Model BenefitsAgility and flexibility• Data model supports business

change• Rapidly iterate to meet new

requirements

Intuitive, natural data representation• Eliminates ORM layer• Developers are more productive

Reduces the need for joins, disk seeks• Programming is more simple• Performance delivered at scale

{

_id :

ObjectId("4c4ba5e5e8aabf3"),

employee_name: "Dunham,

Justin",

department : "Marketing",

title : "Product Manager,

Web",

report_up: "Neray, Graham",

pay_band: “C",

benefits : [

{ type :  "Health",

plan : "PPO

Plus" },

{ type :   "Dental",

plan :

"Standard" }

]

}

Page 21: Migrating from RDBMS to MongoDB

MongoDB is Fully Featured

Page 22: Migrating from RDBMS to MongoDB

22

• MongoDB indexing will be familiar to DBAs– B-Tree Indexes, Secondary Indexes

• Single biggest tunable performance factor– Define indexes by identifying common queries– Use MongoDB explain to ensure index coverage– MongoDB profiler logs all slow queries

Indexing in MongoDB

• Compound• Unique • Array • TTL

• Geospatial • Hash • Sparse• Partial (new in version

3.2)

• Text Search

Page 23: Migrating from RDBMS to MongoDB

Further Reading

http://docs.mongodb.org/manual/data-modeling/

Page 24: Migrating from RDBMS to MongoDB

Application Integration

Page 25: Migrating from RDBMS to MongoDB

Drivers & Ecosystem

Morphia

MEAN Stack

Python PerlRuby

Support for the most popular languages and frameworks

Page 26: Migrating from RDBMS to MongoDB

27

• Ad-hoc reporting, grouping and aggregations, without the complexity of MapReduce

– Max, Min, Averages, Sum, Union, Redact, GeoNear

• Similar functionality to SQL GROUP_BY• Processes a stream of documents• Series of operators

– Filter or transform data– Input/output chain

• Supports single servers & shards

Application IntegrationMongoDB Aggregation Framework

Page 27: Migrating from RDBMS to MongoDB

High Availability: Replica SetsReplica Set – 2 to 50 copies

Addresses availability considerations:

High Availability

Disaster Recovery

Maintenance

Workload Isolation: operational & analytics

Page 28: Migrating from RDBMS to MongoDB

29

Scalability via Sharding

Multiple query optimization models

Each sharding option appropriate for different apps

Elastic and self-balancing

Shard Key Selection:http://docs.mongodb.org/manual/tutorial/choose-a-shard-key/

Page 29: Migrating from RDBMS to MongoDB

30

BI Integration

https://docs.mongodb.org/ecosystem/tools/hadoop/

Page 30: Migrating from RDBMS to MongoDB

31

MongoDB Connector for BIVisualize and explore multi-dimensional

documents using SQL-based BI tools. The

connector does the following:

• Provides the BI tool with the schema of the MongoDB

collection to be visualized

• Translates SQL statements issued by the BI tool into

equivalent MongoDB queries that are sent to MongoDB

for processing

• Converts the results into the tabular format expected by

the BI tool, which can then visualize the data based on

user requirements

Page 31: Migrating from RDBMS to MongoDB

Data Integrity

Page 32: Migrating from RDBMS to MongoDB

33

Data Governance with Document Validation

Implement data governance without sacrificing agility that comes from dynamic schema

• Enforce data quality across multiple teams and applications

• Use familiar MongoDB expressions to control document structure

• Validation is optional and can be as simple as a single field, all the way to every field, including existence, data types, and regular expressions

Page 33: Migrating from RDBMS to MongoDB

34

Document Validation Example

The example on the left adds a rule to the contacts collection that validates:

• The year of birth is no later than 1994

• The document contains a phone number and / or an email address

• When present, the phone number and email addresses are strings

Page 34: Migrating from RDBMS to MongoDB

Data Durability: Write Concern & Journal

• Configurable per operation• Combination of Write Concern

Levels & Journaling allow multiple levels of Guarantees

Write Concern describes the level of acknowledgement requested from MongoDB for write operations

Page 35: Migrating from RDBMS to MongoDB

Migration and Operations

Page 36: Migrating from RDBMS to MongoDB

39

Traditional ETL

Source Database ETL

Page 37: Migrating from RDBMS to MongoDB

Incremental Migration, Live

Legacy Database

MongoDB Database

Page 38: Migrating from RDBMS to MongoDB

41

• Configuration, Provisioning, Monitoring and Backup• High Availability & Disaster Recovery• Scalability• Hardware selection

– Commodity Servers: Prioritize RAM, Fast CPUs & SSD• Security

– Access Control, Authentication, Encryption

Operations

Download the WhitepaperMongoDB Operations Best Practices

Page 39: Migrating from RDBMS to MongoDB

42

Ops Manager & Cloud Manager

Single-click provisioning, scaling & upgrades, admin tasks

Monitoring, with charts, dashboards and alerts on 100+ metrics

Backup and restore, with point-in-time recovery, support for sharded clusters

The Best Way to Manage MongoDB Up to 95% Reduction in Operational Overhead

Page 40: Migrating from RDBMS to MongoDB

43

MongoDB CompassFor fast schema discovery and visual construction of ad-hoc queries

• Visualize schema– Frequency of fields– Frequency of types– Determine validator rules

• View Documents• Graphically build queries• Authenticated access

Page 41: Migrating from RDBMS to MongoDB

Migration Roadmap

• Backed by Free, Online MongoDB Training• Paid Consulting, Services and Support available

Page 42: Migrating from RDBMS to MongoDB

Getting Started

Page 43: Migrating from RDBMS to MongoDB

MongoDB EnablementConsulting, training, and professional services throughout your project lifecycle

For Operations

For Developers

Design & Development

Pre-Production(Test, QA, Deployment) Production Expansion

Dedicated Consulting Engineer | Custom Projects

OperationsRapid Start Production Readiness

MongoDBPrivate CloudAccelerator

Health Check

DevelopmentRapid Start Performance Evaluation and Tuning

For Both

T

DeveloperTraining

T

Essentials Training

T

Administrator Training

T

Advanced DeveloperTraining

T

Advanced AdministratorTraining

Page 44: Migrating from RDBMS to MongoDB

Migration in Action

eCommerce Application• Migration from MS-SQL• Project completed in 8

months vs original 18 month planned.

• High Availability, Performance and reliability at a fraction of the cost.

• Lower latency• Faster dev cycles

Content Management• Migration from Oracle• 80% cost reduction with

commodity hardware• 900% performance

improvement• Development cycles in

weeks vs. tens of months

Customer Data Mgmt & Analytics• Multi RDBMS Migration• 95% faster in identifying

matches• 50% increase in paying

subscribers • 60% increase in unique web

site visits.

Page 45: Migrating from RDBMS to MongoDB

48

• MongoDB Brings the best of Both Relational & NoSQL Data Models• MongoDB is a full featured Database Platform• MongoDB Helps you reduce your Project Time, Cost and Risks• Migrating to MongoDB is easier than before with Enterprise level

Consulting, Training and Support.

Summary

Download the Guidehttps://www.mongodb.com/collateral/rdbms-mongodb-migration-guide

Page 46: Migrating from RDBMS to MongoDB