nosql database architectural comparison - griddb · pdf filenosql database architectural...

19
1 NoSQL Database Architectural Comparison June 29, 2017 Revision 1.00

Upload: trandan

Post on 04-Mar-2018

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

1

NoSQLDatabaseArchitecturalComparisonJune29,2017Revision1.00

Page 2: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

2

TableofContentsListofFigures..............................................................................................................................................2ExecutiveSummary..................................................................................................................................3Introduction.................................................................................................................................................3ClusterTopology........................................................................................................................................5ConsistencyModel.....................................................................................................................................8PartitionScheme........................................................................................................................................9ReplicationStrategy...............................................................................................................................10FailoverMethod......................................................................................................................................12StorageEngine.........................................................................................................................................13CachingMechanism...............................................................................................................................16ClientAPIs..................................................................................................................................................17Conclusion..................................................................................................................................................19

ListofFiguresFigure1:Key-DocumentDataType...................................................................................................4Figure2:Key-ContainerDataType....................................................................................................5Figure3:Cassandra'sRingTopology................................................................................................6Figure4:MongoDB'sHierarchalTopology....................................................................................6Figure5:GridDB’sArchitecture..........................................................................................................7Figure6:GridDBandCassandraLongTermPerformance..................................................13Figure7:Cassandra’sStorageEngine............................................................................................14Figure8:GridDB'sStorageEngine..................................................................................................15Figure9:CassandraCaching..............................................................................................................16

Page 3: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

3

ExecutiveSummaryThiswhitepapercomparesandcontrastsToshiba’sGridDBdatabasetoCassandra,MongoDB,Riak,andCouchbase.Topicscoveredincludethelogicalandphysicalclustertopology,howeachdatabasehandlesconsistency,replication,andfailover,aswellastheindividualstorageengineandcachingmechanismsthatareused.Finally,theClientAPIsoftherevieweddatabasesareshowcasedtodemonstratehowdevelopersmaybuildapplications.

IntroductionThetermNoSQL(orNotOnlySQL)becameprominentinthelate2000sbecausetheamountofdatacollectedandusedbypopularwebservicesbegantoincreaseexponentially.ThissuddenchangebroughtaboutnewrequirementsforasolutionthatcouldscalebetterthanSQLdatabaseswiththeirtabularstorageenginesandrelationalqueries.Asawhole,NoSQLdatabasestendtoscaleoutbutthisisnotalwaysthecase.Somedatabases,suchasRocksDB(notevaluatedhere),aremeantforuseinasingleinstance.

CassandraCassandrawasinspiredbyAmazon’sDynamopaperandwasinitiallydevelopedbyFacebook;itsfirstreleasewasin2008.ItiswritteninJavaandmanycompaniescurrentlycontributetoitasatop-levelApacheprojectwiththemostnotablebeingDatastax.

MongoDB10genbegandevelopingMongoDBin2007aspartofanotherprojectbeforeopensourcingitin2009.10genisnowknownasMongoDB,Inc.anditofferscommercialsupportforMongoDB.

RiakRiakisalsobasedontheprincipalsofAmazon’sDynamoandiswritteninErlang;itwasinitiallyreleasedbyBashoTechnologiesin2009.BashoofferssupportedversionsofRiakthathaveadditionalfeatures.

CouchbaseCouchbaseisthemergeroftheMembase(firstreleasedin2010)andCouchDB(firstreleasedin2005)projectsandtheirrespectivecompaniesin2011withthefirstreleaseofthecombinedproductin2012.ItusesC/C++,Erlang,andGofordifferentcomponents.CouchDBhascontinuedasaseparateproject.

GridDBToshibastartedGridDBdevelopmentin2011withitsfirstcommercialreleasecomingin2013--itwasthenopen-sourcedin2016.ItiswritteninC++andhas

Page 4: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

4

languagebindingsforC/C++,Java,andPython.IthasalsobeenintegratedwithotheropensourceprojectssuchasMapReduce,KairosDB,andSpark.DataTypeWithtraditionalRDBMSdatabases,dataisstoredinatablewithapredefinedstructurewhichcanthenbequeriedusinganyofthefields.NoSQLdatabaseshoweverdonotallsharethesamestructure,differentdatadatabaseshavedifferentdatamodels.

CassandraCassandrausesakey-columndataschemathatissimilartoaRDBMSwhereoneormorecolumnsmakeupthekey.TherowsinaCassandratablecanbequeriedbyanyvaluebutthekeysdeterminewhereandhowrowsarereplicated.

MongoDBMongoDBisakey-documentdatabasethatstoresindividualdocumentsinaJSON-likeformatcalledBSON.Individualdocumentscanbequeriedwithakey,fieldvaluesortheycanbegroupedtogetherinacollectionwhichisanalogoustoatableinaRDBMS.Key-documentdatabasesareflexiblebutcanbeslowduetotheircomplexity.

Figure1:Key-DocumentDataType

RiakRiakisakey-valuedatabase.Thevaluecanbeasimpleliteraloritcanbeamorecomplexuser-definedstructure.Riakdoesnotunderstandanypartofthevalueandthusonlythekeymaybeusedtoquerythedatabase.Keyscanbeseparatedacrossdifferentnamespaces:thesevirtualkeyspacesarereferredtoasbuckets.RiaksupportsusingaTimeSerieskeytypebutthisrequiresadifferentinstallationandchangesthedatamodeltobeingtabular,wheredifferenttablescanhavethesametimekeybutdifferentvaluesassigned.

Page 5: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

5

CouchbaseCouchbasesupportsbothkey-valueandkey-documentdatabases.Thedatabase’skeyspacecanbeseparatedbyusingbuckets.Bysettingaflag,thevaluecanbeserializedusingUTFcharacters,rawbytes,Python’snativepickleformat,orwithauser-definedtranscoder.LikeMongoDB,documentsarestoredusingJSON.

GridDBGridDBisakey-containerdatabase.Thekeycanbeeitheranyspecifieduservalueoratimestamp.EachcontainercanbespecifiedviaakeyandthencanbefurtherqueriedlikeatraditionalRDBMS.Thekey-containerdatatypeisidealfordatamodelsusedwithIoTorotherapplicationsthathavedifferentgroupsoflikedata.

Figure2:Key-ContainerDataType

GridDBsupportsbothregularCollectionsandTimeSeriescontainers.CollectionscanuseanyvalueasakeywhileTimeSeriesContainersuseatimevaluethatallowforspecializedhandlingwithintheapplicationamongstotherfeatures.UnlikeRiak,GridDBsupportsbothCollectionsandTimeSeriesContainersinoneinstallation.Thismakesstoringandaccessingmeta-informationaboutaTimeSeriessignificantlylessonerousthanhavingtoswitchandmanagebetweendifferentAPIsandconnections.

ClusterTopologyDistributedserviceshavetwocommonmodels,master/slaveandpeer-to-peer.Themaster/slavetypearchitectureoffersbetterperformanceandhaslittleoverheadbutthemasternodepresentsasinglepointoffailure.Inapeer-to-peercluster,everynodeisidenticalandhasthesameresponsibilitiesallowingfaulttolerancetobeachievedeasilybutoverheadtomaintainconsistencyisquitehigh.

Page 6: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

6

CassandraCassandrahasapeer-to-peerringbasedarchitecturethatcanbedeployedacrossdatacenters.ACassandrainstallationcanbelogicallydividedintoracksandthespecifiedsnitcheswithintheclusterthatdeterminethebestnodeandrackforreplicastobestored.

Figure3:Cassandra'sRingTopology

MongoDBMongoDBhasahierarchalarchitecturebuiltoutofoneormorequeryroutersnamedmongosandthenoneormoreshardsthatrunmongod,whichcanbebuiltusingreplicasets.Eachreplicasethasaprimarynodeandthenmultiplesecondarynodes.

Figure4:MongoDB'sHierarchalTopology

Page 7: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

7

RiakRiakhasapeer-to-peermaster-lessarchitecturewithmultipledatacentersupportavailableinthecommercialversion.Withmultipledatacentersupport,onedatacenterwillactastheprimaryandtheotherswillsynchronizetoit.

CouchbaseCouchbasehasapeer-to-peerarchitecturewhereeachnodecontainsadata,clustermanager,indexandqueryservice.WithCouchbase’smultipledatacentersupport,updatescanflowfromonedatacentertoothersortheycanflowbilaterallywithconflictstypicallybeingresolvedbyeachclusterbeingtheownerforacertainsetofpartitions.

GridDBGridDBhasahybridmaster/slavearchitecture.Allnodesintheclustercontainpartitioningdatarequiredtoorganizetheclusterbutonlyonenodeactsasthemaster.Inthecaseofamasterfailure,abullyelectionisheldandanothernodeisquicklypromotedtobeingthemaster.Thishybridarchitectureprovidesboththehighperformanceofamaster/slavearchitectureandhighreliabilitybutwithoutasinglepointoffailure.Havinganynodebeingabletotakeoverforafailedmasterpreventspotentialproblems,suchasariskysingle-pointoffailure,likeinMongoDBwherethereareonlyasmallnumberofreplicamongosinstances.

Figure5:GridDB’sArchitecture

Page 8: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

8

ConsistencyModelWithdistributeddatabases,individualdesignsmusttradeoffbetweenconsistency,availability,andpartitiontolerance.ThistheoremwasfirstdescribedbyEricBrewerinthelate1990sandisknownastheCAPtheorem.1Consistency(C)isdefinedbythedatabasealwaysreturningthelatestupdateoranerrorifitcan’t.Availability(A)isdefinedasthedatabasealwaysreturningaresult,evenifit’snotthelatest.Partition-tolerance(P)meansthedatabasewillcontinuetooperatedespitepartialnodeornetworkfailuresbetweennodes.Partitiontoleranceisamustwithdistributeddatabases,leavingtheremainingchoicetobebetweenConsistencyandAvailability.Consistencycanbeimplementedintwoways:eventualorimmediate.Eventualconsistencyallowsdifferentnodesthatmayhavecopiesofthesamedataitemtoupdatetheirowncopiesandmakethemavailableforreadingwithoutbeingconcernedthatifthatdataisconsistentwiththecopiesdataitemsofdifferentnodes.Thepremiseisthateventuallyallaccessestothatdataitemwillreturnthesame,mostrecentlyupdatedversionofthatdataitem.Immediateconsistencyinvolvesmultiplenodeshavingtoagreeonadataitemaftertheitemisupdatedbeforeitcanbemadeavailabletoaccess.Thisistoensurethateveryaccessforthatdataitem,forexamplearow,returnsaconsistentandup-to-dateversion.Thispremisecanhavethecostofhavinghigheroverheadandloweravailabilitywheneveranitemisupdated.

CassandraCassandraistypicallyanavailable,partitiontolerant(AP)databasebuthastuneabledataconsistencyparameters.Ausercanchangebothwriteandreadconsistencylevelsrangingfromhavingnoconsistencytorequiringallnodesbeconsistent,withaddedoptionstoenforceconsistencybetweendatacenters(ornot).

MongoDBMongoDBisaconsistent,partitiontolerant(CP)databasebydefault,butitcanbeconfiguredtoreadfromthesecondarynodeswithinareplicasetallowingforthepossibilityofolderdatatobeserved.2Updatestoanindividualdocumentareatomic,meaningaclientwillalwaysreadeithertheoldversionorthenewversion,butneverahalf-updateddocument.Bydefault,whenmultipledocumentsareupdatedinasinglequerytheywillbeupdatedindividually,meaningaclientcanreadsomeupdateddocumentsandsomeolddocuments.

1https://en.wikipedia.org/wiki/CAP_theorem2https://docs.mongodb.com/manual/replication/

Page 9: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

9

RiakLikeCassandra,whichisalsobasedontheideaspresentedinAmazonDynamoWhitePaper,Riakiseventuallyconsistent,meaningthatthedefaultconfigurationisconsideredtobeanAPdatabase.Consistencycanbeenforcedbysettingconfigurationvariablesthatensurethereisaquorumduringaread.

CouchbaseAsingleCouchbaseclusterbydefaultisaconsistent,partitiontolerantclusterbutcantunedtofavoravailabilityoverconsistency.Amulti-datacenterCouchbaseinstallationisalwayseventuallyconsistent.

GridDBGridDBistheonlyfullyACID(atomicity,consistency,isolation,anddurability)compliantdatabase3reviewedinthiswhitepaper.TheACIDcompliancewithinacontainerguaranteesaconsistent,partitiontolerant(CP)database.GridDBallowstheusertoconfigurethedatabasetoallowimmediateconsistencyoreventualconsistency.

PartitionSchemePartitioningdataisacorerequirementforamulti-nodedatabaseandthefivedatabasesinthiswhitepaperusesimilarbutvaryingmethodologiestospreaddataacrosstheirnodes.

CassandraCassandrausesthefirstpartofarow’sprimarykeytobuildthepartitionkey.Fromthepartitionkey,Cassandradistributesrowsamongstnodesinthecluster.Thismeansextracare4mustbetakenwhenchoosingaprimarykeytoensuredataisspreadevenlyacrossthecluster.

MongoDBMongoDBusesaspecifiedsharedkeytopartitionacollectionsdocumentsacrossthenodesinthecluster.Thesharedkeycanbeeitherasinglefieldorcompoundindex(anindexmadeupofmultiplefieldsineachdocument).Thesharedkeysareimmutable,meaningthatyoucanneitherswitchtonewfieldsnorupdatethevaluesoftheshardkeyfield(s).

RiakInRiakKV,partitionsareautomaticallyspreadacrossvirtualnodes(vNodes)bycalculatingahashofthebucketandkey.AvNodeisalogicaldivisionofacluster’sringsizeacrossitsnodes.

3https://griddb.net/en/docs/documents/3-5_transactions-and-acid.php4http://www.datastax.com/dev/blog/basic-rules-of-cassandra-data-modeling

Page 10: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

10

WithRiakTS,rowsarepartitionedbasedonaspecifiedpartitionkeyofoneormorecolumnsinthetable.

CouchbaseCouchbasecallsitsinternalpartitionsvBuckets.DocumentsaremappedtovBucketsbasedonthehashoftheirdocumentID5.DocumentIDscanbeautomaticallygeneratedorspecifiedbytheapplicationbutarealwaysunique.

GridDBAGridDBpartitionisalogicalareathatstoreswholecontainersandisnotdirectlyvisiblebyauser.Ahashalgorithmthatusesthecontainerkeyastheseeddetermineswhichpartitionacontainerisassignedto.Anallocationtableofthenodetoeachpartitioniscalledapartitiontable.Themasternodedistributesthispartitiontabletothefollowernodesorclientlibraries.Byreferringtothispartitiontable,theownernodeandbackupnodebelongingtoacertaincontainercanbemadeknown.AsGridDBstoreswholecontainersinpartitions,accesseswithinacontainerarealwaysfastandscalewellasinternodecommunicationorcoordinationisnotrequired.

ReplicationStrategyDatareplicationishowdistributeddatabasesareabletomaintainavailabilityafteranodefailsbyplacingaconfigurablenumberofcopiesorreplicasofeverypartitionondifferentnodes.

CassandraCassandrahastwodifferentreplicationstrategies6thatcanbesetonapertablebasisalongwiththenumberofreplicas.WithSimpleStrategy,partitionschemesetsthefirstnodethereplicaisstoredonandthenreplicasarestoredonthenextnodeinring.NetworkTopologyStrategytakesintoconsiderationthatnodesinthesamerackoftenfailatthesametime,soreplicasarestoredonthefirstnodeintheringthatisinadifferentrack.

MongoDBMongoDBusesreplicasets7tostoremultiplecopiesofitsdataset.Eachreplicasetconsistsofmultiplemongodprocesses--aprimaryandoneormoresecondaries.Eachreplicasetismanuallydefinedineachnode’smongodconfigurationfileandthemongoshell.Anenduserisabletoincludenodesfromdifferentdatacentersineachreplicaset.Typically,aclientreadsfromtheprimaryreplicaset,butMongoDB

5https://developer.couchbase.com/documentation/server/3.x/admin/Concepts/concept-vBucket.html6http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureDataDistributeReplication_c.html7https://docs.mongodb.com/manual/replication

Page 11: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

11

canbeconfiguredtoreadfromthesecondariesaswell.Aclientwillalwayswritetotheprimarywhichwillthenpropagatetheupdatetothesecondaries.

RiakRiakisbuiltaroundreplication8andthenumberofreplicascanbesetonaperbucketbasis.ReplicasareassignedtothespecifiednumbervNodesthatmaynotactuallybeondifferentphysicalmachines.AquorumofaconfigurablenumberofvNodesresponsestoareadrequestisrequiredforthereadtobesuccessful.

CouchbaseCouchbaseoffersaper-bucketconfigurablelevelofreplicationandeverynodecontainsbothactivedataandreplicadata.Readsandwritesarealwaystothenodewhichhastheactivedata.Thatisuntilafailureoccursinwhichcasethecluster-widemapofwheredatashouldberetrievedfromisupdated,pointingtothereplicadata.

GridDBReplicationlevelscanbesetfortheentireclusterwithGridDB.Eachpartitionhasanodethatistheowner,enoughbackupnodestosatisfytheconfiguredreplicationlevel,andanycatchupnodesthatarerequired.IfGridDBisconfiguredforimmediateconsistency,thepartition’sownerhandlesallclientreadandwriterequestsandpropagatesupdatestothebackupnodes.Ifconfiguredforeventualconsistency,thereplicasmayrespondtoreadrequests.Catchupnodesareusedwhentherearenotenoughbackupnodestosatisfythereplicationlevelorifthereareotherproblemswiththebackupnodes.Themasternodefirsttransmitslargememoryblocksofitspartitiondatatothecatchupnodeandthentransfersupdatelogsuntilthecatchupnodeisin-syncwiththepartitionownerandcanbepromotedtoabackupnode.ThisstrategyissimilartoCouchbaseandMongoDB,readsandwritesaredirecttothepartitionownerratherthanrequiringaquorumofpeer-to-peernodes.

8http://docs.basho.com/riak/kv/2.2.3/learn/concepts/replication/

Page 12: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

12

FailoverMethodWithdistributeddatabases,failureofanodeisagivenoverthelifetimeoftheproduct.Howthedatabasehandlesboththefailureandrecoveryofanodeiscriticaltohowitwillbeadaptedtovariousapplications.

CassandraWithinaCassandradatabase,pre-definedgossipnodestrackthestateofallofthenodes.Gossipnodes9collectthestateofothernodesbothdirectlytoorfromothergossipnodes.Ratherthanuseafixedthresholdtomarknodesasdown,thegossipnodesuseaslidingwindowthatconsiderstheoperatingconditionsoftheclusteraswellastheconfigurablethresholdtoaccountforthedifferencesbetweenoperatinginthepubliccloudorahighperformanceLANorsomewhereinbetween.Afterafailednodecomesbackonline,itwilltrytoreplaythehintsforrowsitownsstoredbyothernodesduringtheoutage.Ifthenodewasdownforlongerthantheconfigurablehintstoragewindow,amanualnoderepairmustberuntore-replicatetherowdatawrittenduringthedowntimetoensureconsistency.

MongoDBMongoDB’sreplicasetsuseasimpleheartbeatbetweenmemberseverytwoseconds.Ifaheartbeathasnoresponsewithin10seconds,thenodeismarkedasbeingdown.Ifthedownnodeistheprimary,anelectionwillbeheldandoneofthesecondarieswillbecometheprimaryandbeginacceptingwrites.Inthecaseofanetworkpartition,theprimarywilldemoteitselfifitcannotreachthemajorityofitsnodeswhiletheunreachablenodeswillcarryoutanelectionandonewillbepromotedtotheprimary.

RiakLikeCassandra,Riakusesgossipprotocol,quorums,andhintedhandoffstodealwithfailureswithinthecluster.

CouchbaseTheCouchbaseClusterManagermonitorsthestatusofallnodesintheclusterandifit’sconfiguredtodosowilltriggerauto-failover10.Auto-failurewillmarkthenodeasofflineandtransferownershipofitsownedvBucketstoothernodes.Ifthenodeisnotre-added,amanualrebalancewillneedtotakeplacethatpermanentlyreassignsvBucketownershipandreplicas.Ifthenodeisaddedbacktothecluster,recoveryisperformedmanuallyeitherusingthedeltaorfullrecoverymethod.Thedeltamethodincrementallycatchesthenodeuptothelateststatewhilefullrecoveryremovesthestaledataandafullrebalanceisthenperformed.

9http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureDataDistributeFailDetect_c.html10https://developer.couchbase.com/documentation/server/current/clustersetup/automatic-failover.html

Page 13: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

13

GridDBTheGridDBmastermonitorsallthenodesinaGridDBcluster.Whenanodedoesnotrespondtothemaster’sheartbeat,themastermarksthatnodeasdownandassignsthepartitionsitownstotheotherreplicas.Ifafterfailure,theconfiguredreplicationlevelisnotmet,anothernodewillbeassignedtheroleofcatch-upandthatpartitionwillbegintransferringlargeblocksofdata.Aftertheinitialhighspeedmemorysynchronizationiscomplete,itwillbetransferred

StorageEngineThedetailsofhoweachofthedifferentNoSQLdatabasesstoretheirdataaredifferent.Therearetwomainthemes:logstructuredmerge(LSM)treefilesthatrequirecompaction(whichinvolvesreducingdiskspacethrougholdandunuseddatefromthedatabaseusedbyCassandra,Riak,andCouchbase)andcheckpointwritesofdatatablesthatareusedbyMongoDBandGridDB.

Figure6:GridDBandCassandraLongTermPerformance

TheLSM-treebaseddatabasespresentexcellentwriteandupdateperformancewhilethecheckpointdatabasescanofferconsistentlybetterreadperformanceasshownbytheabovefigure.CompactionalsocausesthesystemtoseeaspikeinbothdiskusageandI/Oactivity.Thissortofactivitymustbeplannedforasthiscanadverselyaffectspeedandperformance.

Page 14: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

14

CassandraCassandrastoresitsdatainalogmergetreethatavoidsreadsbeforewrites.Updatesareinitiallyappendedtothecommitlogondiskandthein-memorymemtable.Thecommitlogallowsdatapersistenceduringsuddenfailures.WhenthememtableexceedstheconfiguredsizeitgetsflushedtodiskasmultipleLSM-treeSSTables(SortedStringTablesofkeysandvaluessortedbykey)pertable/partition.

Figure7:Cassandra’sStorageEngine

AsCassandradoesnotupdatetheSSTablesinplace,theymustbecompacted.ForCassandratoremoveoldordeleteddata,themostrecentversionoftherecordswillbemovedtoanewSSTableandthenunlinktheoldSSTable.

MongoDBMongoDBsupportsmultiplebackendstorageenginesbutrecommendsusingtheWiredTigerbackendforallnewinstallations.WiredTigercanutilizeeitheraB-treeorLSM-treestructureandusescheckpointcommitstoflushitsstructuredmemoryimagetodisk.Betweencheckpoints,WiredTigerwritesoutawrite-aheadlogorjournalthatensuresdatapersistencebetweencheckpoints.

RiakRiakhasapluggablestorageenginewiththreedefaultoptions:Bitcask,LevelDB,andMemory.Bitcaskisthedefaultstorageengineandisappend-only,requiringcompactionthatkeepstheentirekeyspacemappinginmemory.TheLevelDBbackendutilizesaforkofGoogle’sLevelDBdatabaseusinganLSMstructurethatallowsthekeyspacetobelargerthanthememorysize.TheMemorybackendusesin-memorytablesandhaszeropersistence.

Page 15: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

15

CouchbaseCouchbaseusestwodifferentstorageengines,CouchstorefordataandForrestDBforindices.BothCouchstoreandForrestDBareappend-onlystorageenginesthatrequirecompaction,althoughForrestDBhasacircularre-usemodethatallowsnewwritestotakespaceinthelogthatwasfreedbyoldordeletedrecords.

GridDBGridDBisintendedtokeepmostofthedatabasein-memoryandusesamethodsimilartoMongoDBtopersistdata.Itsinternalmemorystructureisflushedtodiskonacheckpointintervalwhilemaintainingatransactionlogbetweencheckpoints.

Figure8:GridDB'sStorageEngine

Whenthedatabaseoutgrowstheconfiguredmemoryutilization,datanotlikelytobeusedsoonisfreedfrommemory.Thisallowsmoredatabasetransactionstooccurin-memory,meaningGridDBdoesnotaccessthediskasfrequentlythusofferinghigherperformance.Evenwhenthedatabasedoesnotfitinmemory,GridDB’sperformanceremainsremarkablystablewithouttheuserhavingtoperformanyregularmaintenance.Fixstarsshowcasedthisinbenchmarksperformedin201611.

11https://griddb.net/en/blog/griddb-and-cassandra-ycsb-benchmarks/

Page 16: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

16

CachingMechanismCachingmechanismsarecloselyrelatedtothedatabases’storageenginesandvaryconsiderablybetweenthediscusseddatabasesinthiswhitepaperwithCassandra,MongoDB,andRiaknotusingaspecifiedcachesystematallbydefault.GridDBattemptstokeeptheentiredatabaseinmemoryifcapacityallows.

CassandraCassandrahastwocaches,arowcacheandakeycachethatarebothdisabledbydefault.Therowcacheismeanttobeusedbyveryhotrecordsthatareusedoften.Bothcachescanbeconfiguredformaximumsizeandrecordage.Thekeycacheisrecommendedtobe10%oftheheapsizeor100MB.

Figure9:CassandraCaching

Toenablebettercaching12,manyCassandrausersaddanadditionallayerandaddatoollikememcachedtotheirstacktoincreaseperformance.

MongoDBMongoDBwillkeepworkingdatauptotheconfiguredsizeinmemorybutdoesnotstoretheresultsofqueriesinmemory.Bydefault,WiredTigeruseshalfofthesystemmemoryminus1GBforitscacheallowingthefilesystemcacheforitselfandotherapplicationstofilltheremainder.

RiakThecachingmechanismusedbyRiakdependsonitsbackendstorageoption.WithBitcask,Riakreliesexclusivelyonthefilesystemcacheprovidedbytheoperatingsystem.TheLevelDBbackend,ontheotherhand,hasaconfigurablecachesize.As12https://www.datastax.com/dev/blog/maximizing-cache-benefit-with-cassandra

Page 17: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

17

previousLevelsarestoredinthecache,onlyonediskreadshouldberequiredforaquery.Ofcourse,thememorybackendkeepstheentiredatabaseinmemory,makingfurthercachingredundant.WithRiakEnterprise,BashoalsooffersaCacheProxyservicethatenablesuserstointegrateRedisintotheirstack.

CouchbaseCouchbaseisbuiltbyengineersofmemcachedsoftware13andtoutsamemory-firstarchitecture.ActualrowdataiskeptinamemcachedsystemsimilartocachewhiletheIndexandSearchservicesstorethemostpopularindicesinmemory.TheQueryservicedoesn’tstoretheactualqueryresultsbutdoescachetheprocessingstreamsrequiredtocalculatethequeryresponse.

GridDBGridDBisanin-memorydatabasewithpersistencethatwillstoreuptotheconfiguredamountofdatainmemoryandrecommendsthatmostofthesystemmemoryisassignedtoit.GridDBusesLeastRecentlyUsed(LRU)andDataaffinityalgorithmstodeterminewhichrecordsstayinmemoryandwhichrecordsremainonlyindisk.Thesealgorithmshelpensureonlythemostrelevantandquerieddatainthedatabasestayinthecache,whichcanaidintheoverallefficiencyoftheapplication.ThelargeamountofmemorygiventothecachealongwiththeoptimizedcachemanagementfunctionsallowGridDBtooffersignificantlyhighercachehitratesallowinghighperformancewithouthavingtoincorporateasecondcachingsystemlikememcachedorRedis.

ClientAPIsHowthedevelopersareablecreateapplicationsthatreadandwritetothedatabasesareequallycriticaltotheotherdatabasecharactersforaprojecttobesuccessful.ThescopeoftheNoSQLdatabaseclientAPI’svariessignificantlywithGridDBandCassandrahavingfeaturefulquerylanguageswhileRiakrequiresthirdpartytoolstoofferfeatureslikesearch.

CassandraApplicationsuseCassandraQueryLanguage(CQL)tointeractwithaCassandradatabase.AsCassandra’sdatatypeismostsimilartoSQL,itmakessensethatCQListhemostsimilartoSQL,sharingcommandssuchasCREATE,SELECT,INSERT,UPDATE,ALTER,DROPaswellasaggregationfunctions.ThebiggestdifferencebetweenSQLandCQListhatCQLdoesnotdirectlysupportjoinsbutjoinscanbecompletedusingSpark14.13https://developer.couchbase.com/documentation/server/current/architecture/managed-caching-layer-architecture.html14https://www.datastax.com/2015/03/how-to-do-joins-in-apache-cassandra-and-datastax-enterprise

Page 18: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

18

INSERTINTOitems(id,number)VALUES(“foo”,25);INSERTINTOitems(id,number)VALUES(“bar”,42);

SELECT*FROMitemsWHEREnumber<30;

MongoDBMongoDB’sAPIdiffersdependingontheprogramminglanguage15usedfortheapplication.InmostcaseseithernativetypedictionariesorparsableJSONstringsareprovidedtoinsertrecords.FetchqueriescaneitherbebuiltusingaJSONstructureorusingsimpleoperatorssuchaseq().PythonInsert:db.items.insert_many( [

{"id": "foo", "number": 25 }, {“id”: “bar”, “number”: 52 }

]) JavaQuery: collection.find(lt("number", 30))); collection.find(eq("name", "456 Cookies Shop"))

RiakRiakcanusebothanHTTPoraprotocolbufferAPI.BothofferGETandPUTtopushorfetchkey-valuepairs.Searchqueriesofuser-definedindicescanbedoneusingRiak’sSolrintegration.16myBucket.store("foo",25).execute();myBucket.store("bar",52).execute();Integerfoo=myBucket.fetch(“foo”,Integer);Integerbar=myBucket.fetch(“bar”,Integer);

CouchbaseCouchbasehasabothasynchronousandsynchronousAPIswithsimpleget/putsemanticsavailabletoapplications.17JsonObjectfoo=JsonObject.empty().put("number",25)JsonObjectbar=JsonObject.empty().put("number",52)JsonDocumentfooResp=bucket.upsert(JsonDocument.create("foo",foo););JsonDocumentbarResp=bucket.upsert(JsonDocument.create("bar",bar));

15https://docs.mongodb.com/manual/tutorial/query-documents/16http://docs.basho.com/riak/kv/2.2.3/developing/usage/search/17https://developer.couchbase.com/documentation/server/3.x/developer/java-2.1/java-intro.html

Page 19: NoSQL Database Architectural Comparison - GridDB · PDF fileNoSQL Database Architectural Comparison June 29, 2017 Revision 1.00 2 Table of Contents ... CouchDB has continued as a separate

19

JsonDocumentfoo=bucket.get(“foo”);JsonDocumentbar=bucket.get(“foo”);

GridDBGridDBcanbequeriedeitherthroughitsAPIorviaTQL.TQLisasmallsubsetofSQLthatallowsdevelopertoperformbasicoperationsincludingsearchandaggregation.Itemfoo=newItem(“foo”,25);Itembar=newItem(“bar”,52);collection.put(foo);collection.put(foo);Query<Item>=collection.query(“SELECT*WHEREnumber<30”,Item.class);

LikeCassandra,GridDBsupportsthestandardaggregationfunctionslikeMIN,MAX,AVERAGEandalsoincludesspecializedTimeSeriesfunctionssuchasTIME_AVG,whichprovidesthetime-weightedaverageofafield.TIME_NEXTprovidesaresultthatisidenticalwithorjustafterthespecifiedtimestamporTIME_SAMPLINGthatreturnsrowsthatmatchthespecifiedintervalinthegiventimeframe.

ConclusionTosummarize,GridDBisverymuchahybriddatabase.Ithasbothahybridmaster/slavearchitecturewherethedatabaseisanefficientmaster/slavearchitecturebutanyofthenodesmaybepromotedtomasterincaseoffailure,andahybridin-memorypersistentstorageenginewhererequestsmaybequicklyservedfrommemorybutthedatabasecanalsogrowpasttheboundsofasystem’savailablememory.GridDBhasamulti-facetedapproachtoscalabilityaswell;withitskey-containerdatatype,efficientpartitioningofdata,andanstorageenginethatdoesnotrequiremaintenance.ItcanscalenotonlyinIOPSordatabasesize,butalsointheeaseofdevelopingapplicationswithalargenumberofdatasources.Aswe’veshown,GridDBhasauniquecombinationoffeaturesthatwillallowittoexcelinmanyapplicationfields,includingstoringthemachinegenerateddatalikethatofIoTdevices.Asnodatabaseisperfect,itishopedthattheprecedingwhitepaperwasausefulreviewofthefiveNoSQLdatabases.Notalldatabasesarecreatedequal–theyallhavecommonanddifferingfeaturesandcarefulconsiderationisrequiredbeforeselectingadatabaseforaparticularapplicationtoensurethatthegoalsoftheprojectcanbemet.