You are on page 1of 5

Introduction

Therelationaldatabasehasbeenthefoundationofenterprisedatamanagementforoverthirty
years.Buttheway,webuildandrunapplicationstoday,coupledwithunrelentinggrowthinnew
datasourcesandgrowinguserloadsarepushingrelationaldatabasesbeyondtheirlimits.So,
weareseeingalotofapplicationsbeginningtomigratetoNoSQL,likeMongoDBcompletelyor
movetoahybridmodelutilizingbothRDBMSandMongoDBforpersistingdifferentpartsofthe
samesystem.ThiswhitepaperdiscusseshowMongoDB,theleadingnosqldatabaseoffersa
newandbetterapproachforpersistingdatathanrelationaldatabases.

Table of Contents
MongoDBadvantages
RelationalDatabasechallenges
MongoDBSolution
Agility
Performance
Scalability
HighAvailability
DetailedExplanation
FromrigidtablestoflexibleanddynamicBSONdocuments
Applicationintegration
AtomicityinMongoDB
MigrationtoolsfromrelationaltoMongoDB
MongoDBMMS
Conclusion

MongoDB advantages
DynamicSchemadesignenablesrapiddevelopmentwithoutalonginitialtableandforeignkey
designsencountered,whenusingarelationaldatastore.
Horizontalscalingoncommodityhardware:TheproductionsitecanmanageseveralTBina
singletable(collection),w/obeinglimitedbyaddingnewfieldsorbeinglimitedbygrowth.
Shardingenableslinearandscaleoutgrowthw/orunningoutofbudget.
RapidreplicaSetenablesmeetingregulationwitheasytosetupmultidatacenterDRPandHA
solution.
Highwritethroughput:Withalargenumberinserts,MongoDBarchitectureisgreatfora
systemthatmustsupporthighinsertload.Yetyoucanguaranteetransactionswith
findAndModify(whichisslower)andtwophasecommit(applicationwise).
MongoDBsupportsfulltextsearchindexesandrequiresnoadditionalinfrastructuretobe
deployed.
Developerorientedqueries,enabledeveloperswriteaelegantqueries.
Avarietyofindexesareavailable.Especiallyusefulisbuiltinlocationindex,whichcanbeutilized
tobuildgeospatialapplications.
Map/Reduce:Ifyouhappentoneedthis,thereisbuiltinsupport.
Relational Database challenges
Relationaldatabaseshavethefollowingbroadcategoriesofchallenges:
1. Datatypes:Theyarenotdesignedtosupportunstructured,semistructuredor
polymorphicdata.
2. VolumeofData:Whenitcomestosupportingpetabytesofdata,trillionsofrecords
and/ormillionsofqueriespersecond,RDBMSsstrugglebecauseofinherentdesign
limitation.
3. AgileDevelopment:RDBMSisillsuitedforiterativedevelopment,becauseyouwould
needtofreezedatamodelbeforeanydevelopmentcanstart.Ifitsoundslikewaterfall
model,itsureis.Also,shortdevelopmentcyclesandnewworkloadscanpose
challengesinanyproject/productusingRDBMS.
4. NewArchitecture:AsRDBMSweredesigned30yearsago,theydonthavehorizontal
scalingbuiltintothemyet.Theystruggletoscaleusingcommodityserversandcloud
computing.
MongoDB Solution
Agility
Muchofthedataweusetodayhascomplexstructuresthatcanbemodeledandrepresented
moreefficientlyusingJSON(JavaScriptObjectNotation)documents,ratherthantables.
MongoDBstoresJSONdocumentsinabinaryrepresentationcalledBSON(BinaryJSON).
BSONencodingextendsthepopularJSONrepresentationtoincludeadditionaldatatypessuch
asint,longandfloatingpoint.

Bycontrast,tryingtomaptheobjectrepresentationofthedatatothetabularrepresentationofan
RDBMSslowsdowndevelopment.AddingObjectRelationalMappers(ORMs)cancreate
additionalcomplexitybyreducingtheflexibilitytoevolveschemasandtooptimizequeriesto
meetnewapplicationrequirements.
Performance
MongoDBachievesbetterperformancebyusinginmemorycaching,betterdatalocalityand
inplaceupdates.
Scalability
MongoDBusesshardingtosupportdeploymentswithverylargedatasetsandhighthroughput
operations,whichisamethodforstoringdataacrossmultiplemachines.
High Availability
Replicasetsprovidehighavailabilityusingautomaticfailover.Failoverallowsasecondary
memberstobecomeprimaryifprimaryisunavailable.Failover,inmostsituationsdoesnot
requiremanualintervention.
Detailed Explanation

Wewillexpandsomeofthepointscoveredabovenext.
From rigid tables to flexible and dynamic BSON documents
Muchofthedataweusetodayhascomplexstructuresthatcanbemodeledandrepresented
moreefficientlyusingJSON(JavaScriptObjectNotation)documents,ratherthantables.
MongoDBstoresJSONdocumentsinabinaryrepresentationcalledBSON(BinaryJSON).
BSONencodingextendsthepopularJSONrepresentationtoincludeadditionaldatatypessuch
asint,longandfloatingpoint.
Withsubdocumentsandarrays,JSONdocumentsalsoalignwiththestructureofobjectsatthe
applicationlevel.Thismakesiteasyfordeveloperstomapthedatausedintheapplicationtoits
associateddocumentinthedatabase.
Bycontrast,tryingtomaptheobjectrepresentationofthedatatothetabularrepresentationofan
RDBMSslowsdowndevelopment.AddingObjectRelationalMappers(ORMs)cancreate
additionalcomplexitybyreducingtheflexibilitytoevolveschemasandtooptimizequeriesto
meetnewapplicationrequirements.
Theprojectteamshouldstarttheschemadesignprocessbyconsideringtheapplications
requirements.Itshouldmodelthedatainawaythattakesadvantageofthedocumentmodels
flexibility.Inschemamigrations,itmaybeeasytomirrortherelationaldatabasesflatschemato
thedocumentmodel.However,thisapproachnegatestheadvantagesenabledbythedocument
modelsrich,embeddeddatastructures.Forexample,datathatbelongstoaparentchild
relationshipintwoRDBMStableswouldcommonlybecollapsed(embedded)intoasingle
documentinMongoDB.
Byusinganelegantdocumentdatabaseschemadesignandmakinguseofatomicityat
documentlevel,JOIN'sareredundant.MostofJOINsleadtoalotofperformanceissuesin
relationaldatabases.Somemoreadvantagesofthismodelare:
Anaggregateddocumentcanbeaccessedwithasinglecalltothedatabase,ratherthan
havingtoJOINmultipletablestorespondtoaquery.TheMongoDBdocumentis
physicallystoredasasingleobject,requiringonlyasinglereadfrommemoryordisk.On
theotherhand,RDBMSJOINsrequiremultiplereadsfrommultiplephysicallocations.
Asdocumentsareselfcontained,distributingthedatabaseacrossmultiplenodes(a
processcalledsharding)becomessimplerandmakesitpossibletoachievemassive
horizontalscalabilityoncommodityhardware.TheDBAnolongerneedstoworryabout
theperformancepenaltyofexecutingcrossnodeJOINs(shouldtheyevenbepossiblein
theexistingRDBMS)tocollectdatafromdifferenttables.
Application integration
EaseofuseanddeveloperproductivityaresomeofMongoDBscoredesigngoals.One
fundamentaldifferencebetweenaSQLbasedRDBMSandMongoDBisthattheMongoDB
interfaceisimplementedasmethods(orfunctions)withintheAPIofaspecificprogramming
language,asopposedtoacompletelyseparatelanguagelikeSQL.This,coupledwiththeaffinity
betweenMongoDBsBSONdocumentmodelandthedatastructuresusedinobjectoriented
programming,makesapplicationintegrationsimple.MongoDBhasidiomaticdriversforthemost
popularlanguages,includingoveradozendevelopedandsupportedbyMongoDB(e.g.,Java,
Python,.NET,PERL)andmorethan30communitysupporteddrivers.
Atomicity in MongoDB
Relationaldatabasestypicallyhavewelldevelopedfeaturesfordataintegrity,includingACID
transactionsandconstraintenforcement.Rightly,usersdonotwanttosacrificedataintegrityas
theymovetonewtypesofdatabases.WithMongoDB,userscanmaintainmanycapabilitiesof
relationaldatabases,eventhoughthetechnicalimplementationofthosecapabilitiesmaybe
differentwehavealreadyseenthiswithJOINs.
MongoDBwriteoperationsareatomicatthedocumentlevelincludingtheabilitytoupdate
embeddedarraysandsubdocumentsatomically.Byembeddingrelatedfieldswithinasingle
document,usersgetthesameintegrityguaranteesasatraditionalRDBMS,whichhasto
synchronizecostlyACIDoperationsandmaintainreferentialintegrityacrossseparatetables.
DocumentlevelatomicityinMongoDBensurescompleteisolationasadocumentisupdated
anyerrorscausetheoperationtorollbackandclientsreceiveaconsistentviewofthe
document.
Despitethepowerofsingledocumentatomicoperations,theremaybecasesthatrequire
multidocumenttransactions.Therearemultipleapproachestothisincludingusingthe
findandmodifycommandthatallowsadocumenttobeupdatedatomicallyandreturnedinthe
sameroundtrip.findandmodifyisapowerfulprimitiveontopofwhichuserscanbuildothermore
complextransactionprotocols.Forexample,usersfrequentlybuildatomicsoftstatelocks,job
queues,countersandstatemachinesthatcanhelpcoordinatemorecomplexbehaviors.
Anotheralternativeentailsimplementingatwophasecommittoprovidetransactionlike
semantics.
Migration tools from relational to MongoDB
Manyuserscreatetheirownscripts,whichtransformsourcedataintoahierarchicalJSON
structurethatcanbeimportedintoMongoDBusingthemongoimporttool.
ExtractTransformLoad(ETL)toolsarealsocommonlyusedwhenmigratingdatafrom
relationaldatabasestoMongoDB.AnumberofETLvendorsincludingInformatica,Pentaho
andTalendhavedevelopedMongoDBconnectorsthatenableaworkflowinwhichdatais
extractedfromthesourcedatabase,transformedintothetargetMongoDBschema,stagedthen
loadedintodocumentcollections.
ManymigrationsinvolverunningtheexistingRDBMSinparallelwiththenewMongoDB
database,incrementallytransferringproductiondata:
1. AsrecordsareretrievedfromtheRDBMS,theapplicationwritesthembackoutto
MongoDBintherequireddocumentschema.
2. Consistencycheckers,forexampleusingMD5checksums,canbeusedtovalidatethe
migrateddata.
3. AllnewlycreatedorupdateddataiswrittentoMongoDBonly.
MongoDB MMS
MongoDBManagementandMonitoringservice(MMSinshort)availableoncloudandonpremise
canbeusedtodoperformancemonitoringanddobackupandrestores.
Conclusion
MongoDBistheleadingnosqldatabaseandisbeingincreasinglyusedinhybridapplications
alongwithRDBMSslikeMySQLaswellasinsomecases,asstandalonedatabase.

You might also like