Couchbase Meetup - "Supportare Milioni di Utenti con NoSQL"

Preview:

DESCRIPTION

Grazie ai social network, le nuove applicazioni web possono diventare virali e arrivare a milioni di utenti in poche settimane. I database relazionali si rivelano inadatti a sostenere questi livelli di traffico. In questa presentazione faremo un confronto tra i database relazionali e quelli NoSQL come Couchbase e illustreremo i vantaggi di quest'ultimi. Porteremo come esempio l'applicazione "Draw Something" di OMGPop

Citation preview

Supportare)Milioni)di)Uten0)con)NoSQL)

Franco)Caporale)

Draw)Something)

Draw)Something)–)OMGPop)

Draw)Something)diventa)virale)in))3)seCmane)

19#17#15#13#11#9#7#5#3#3/1#28#26#24#22#20#18#16#14#12#10#8#2/6#

Daily&Ac)ve&Users&(millions)&

21#

2#

4#

6#

8#

10#

12#

14#

16#

I)da0)crescono)in)modo)non)lineare…)

19#17#15#13#11#9#7#5#3#3/1#28#26#24#22#20#18#16#14#12#10#8#2/6#

Daily&Ac)ve&Users&(millions)&

21#

2#

4#

6#

8#

10#

12#

14#

16#

In)un)mese)30,000,000)di)downloads#della#app,#oltre#5,000)disegni)al#secondo,#

oltre#2,200,000,000)disegni)immagazzina=,#oltre#105,000#operazioni#al#secondo,#e#oltre#3.3)terabytes#di#da=#in#totale.#

#

Invece)con)RDBMS……)

19#17#15#13#11#9#7#5#3#3/1#28#26#24#22#20#18#16#14#12#10#8#2/6#

The)Simpson’s:)Tapped)Out)Daily&Ac)ve&Users&(millions)&

21#

2#

4#

6#

8#

10#

12#

14#

16#

#2)Free#app#on#iPad##3)Free#app#on#iPhone#

MySQL)o)NoSQL?)

La)maggioranza)delle)applicazioni)u0lizzano)gli)RDBMS)

E)a)volte)puo’)diventare))un)po’)grande…..)

hBp://www.seoclerks.com/imagedb/2005/BIGJCATJFOUNDJSpoh#

……o)forse)enorme!)

hBp://www.2pep.com/extremeJfunnyJstuff/#

E)complicato!)

I)principali)mo0vi)per)l’adozione))del)NoSQL)

Schema)rigido)e)non)flessibile)

Difficolta’)a)scalare))

Problemi)di)performance)

Cos0) TuC)I))preceden0)

Altri)

49%)

35%)

29%)

16%) 12%) 11%)

Source:#Couchbase#Survey,#December#2011,#n#=#1351.#

Architettura moderna di un’applicazione web

Application Scales Out Just add more commodity web servers

Database Scales Up Get a bigger, more complex server

Nota#–#I#database#relazionali#sono#una#tecnologia#eccellente#ma#non#per#questo#uso.#

I database NoSQL utilizzano la stessa logica dell’applicazione

Application Scales Out Just add more commodity web servers

Database Scales Out Just add more commodity data servers

Scalando orizzontalmente si riducono I costi e aumentano le performance

NoSQL#Database#Servers#

Una)Stru`ura)dei)Da0)Diversa)

Modello)Relazionale)vs.)A)Documento)

Modello)“Relazionale”) Modello)“A)documento”)Collezione#di#documen=#complessi#con#forma=#arbitrari#e#schema#variabile#

Tabelle#con#schema#rigido#e#struBura#dei#da=#predefinita#

JSON)JSON)

JSON)

C1) C2) C3) C4)

{))))})

Database)a)Documento)

•  Ogni#record#e’#un#documento#a#se’#stante#

•  Ogni#documento#ha#una#struBura#indipendente#

•  I#documen=#possono#essere#complessi#•  Richiedono#una#chiave#unica#•  I#da=#sono#immagazzina=#in#formato#JSON,#XML#o#simili#

•  Il#contenuto#puo’#essere#indicizzato#e#interrogato#

•  Offrono#sharding#automa=co#e#repliche#

{"“UUID”:"“21f7f8de0805105b89086“Time”:" “2011004001T13:01:02.42“Server”:" “A2223E”,“Calling"Server”:" “A2213W”,“Type”:"“E100”,“Initiating" User”:" “dsallings@spy.net”,“Details”:"

{“IP”:"“10.1.1.22”,“API”:" “InsertDVDQueueItem”,“Trace”:" “cleansed”,“Tags”:"

[“SERVER”,"“US0West”,"“API”]

}}

Esempio)Social)Game))Profilo)Giocatore)

{##"jsonType":#"player",##"uuid":#"35767d02Ja958J4b83J8179J616816692de1",##"name":#"Keith4540",##"hitpoints":#75,##"experience":#663,##"level":#4,##"loggedIn":#false#

}##

ID)Utente)

Esempio)Social)Game)Ogge`o)

{##"jsonType":#"item",##"name":#"Katana_e5890c94J11c6J65746ce6c560",##"uuid":#"e5890c94J11c6J4856Ja7a6J65746ce6c560",##"ownerId":#"Dale9887"#

}#

ID)Ogge`o)

ID)Utente)

Esempio)Social)Game)Mostro)

{##"jsonType":#"monster",##"name":#"Bauchan9932",##"uuid":#"d10dfc1bJ0412J4140Jb4ecJaffdbf2aa5ec",##"hitpoints":#370,##"experienceWhenKilled":#52,##"itemProbability":#0.5050581341872865#

}#

ID)Mostro)

Esempio)Blog))Diviso)su)piu’)Documen0)

{"“UUID”:"“21f7f8de0805105b89086“Time”:" “2011004001T13:01:02.42“Server”:" “A2223E”,“Calling"Server”:" “A2213W”,“Type”:"“E100”,“Initiating" User”:" “dsallings@spy.net”,“Details”:"

{“IP”:"“10.1.1.22”,“API”:" “InsertDVDQueueItem”,“Trace”:" “cleansed”,“Tags”:"

[“SERVER”,"“US0West”,"“API”]

}}

{ !“_id”: “Coucbase_Hello_World”,!“author”: “dborkar”, !“type”: “post”!“title”: “Hello World”,!“format”: “markdown”, !“body”: “Hello from [Couchbase](http://couchbase.com).”, !“html”: “<p>Hello from <a href=\“http: …!“comments”:[!

! “comment1_Couchbase_Hello_world”!! ]!

}! {"“UUID”:"“21f7f8de0805105b89086“Time”:" “2011004001T13:01:02.42“Server”:" “A2223E”,“Calling"Server”:" “A2213W”,“Type”:"“E100”,“Initiating" User”:" “dsallings@spy.net”,“Details”:"

{“IP”:"“10.1.1.22”,“API”:" “InsertDVDQueueItem”,“Trace”:" “cleansed”,“Tags”:"

[“SERVER”,"“US0West”,"“API”]

}}

{!“_id”: “comment1_Couchbase_Hello_World”,!“format”: “markdown”, !“body”:”Awesome post!” !})

BLOG)

COMMENTI)

Esempio:)Profilo)Utente)Database'Relazionale'

Indirizzo)Utente)

1) DEN) 30303)CO)

2) MV) 94040)CA)

3) CHI) 60609)IL)

Informazioni)Utente)

KEY) First) ZIP_id)Last)

4) NY) 10010)NY)

1) Dip0) 2)Borkar)

2) Joe)

2)Smith)

3) Ali) 2)Dodson)

4) John) 3)Doe)

ZIP_id) CITY) ZIP)STATE)

1) 2)

2) MV) 94040)CA)

Per)o`enere)informazioni)su)un)utente)specifico,)devi)effe`uare)un)JOIN)tra)due)tabelle)

TuC)I)da0)di)un)utente)in)un)singolo)documento)

){)))))“ID”:)1,)))))“FIRST”:)“Dip0”,)))))“LAST”:)“Borkar”,)))))“ZIP”:)“94040”,)))))“CITY”:)“MV”,)))))“STATE”:)“CA”)))})

JSON)

=) +)

Esempio:)Profilo)Utente)Database'a'Documento'

User)ID) Nome) Cognome) CAP)

1) Dip0) Borkar) 94040)

2) Joe) Smith) 94040)

3) Ali) Dodson) 94040)

4) Sarah) Gorin) NW1)

5) Bob) Young) 30303)

6) Nancy) Baker) 10010)

7) Ray) Jones) 31311)

8) Lee) Chen) V5V3M)

•  ))•  ))•  ))

50000) Doug) Moore) 04252)

50001) Mary) White) SW195)

50002) Lisa) Clark) 12425)

ID)Paese)TEL3)

)001)

ID)Paese) Nome)Paese)

001) USA)

002) UK)

003) Argen0na)

004) Australia)

005) Aruba)

006) Austria)

007) Brazil)

008) Canada)

009) Chile)

•  ))•  ))•  ))

130) Portugal)

131) Romania)

132) Russia)

133) Spain)

134) Sweden)

User)ID) Foto)ID) Commento)

2) d043) NYC)

2) b054) Bday)

5) c036) Miami)

7) d072) Sunset)

5002) e086) Spain)

Tabella)Foto)

))001)

))007)

))001)

))133)

))133)

User)ID) Status)ID) Text)

1) a42) At)conf)

4) b26) excited)

5) c32) hockey)

12) d83) Go)A’s)

5000) e34) sailing)

Tabella)Status)

))134)

007)

))008)

))001)

))005)

Tabella)Paese)

User)ID) Affl)ID) Affl)Name)

2) a42) Cal)

4) b96) USC)

7) c14) UW)

8) e22) Oxford)

Tabella)Affiliazioni)ID)Paese)

))001)

))001)

))001)

))002)

ID)Paese)

ID)Paese)

001)

001)

002)

001)

001)

001)

008)

001)

002)

001)

Tabella)Utente)

.).).)

Effe`uare)una)Modifica)su)RDBMS)

Modifiche)su)un)database))a)documento)

){)))))“ID”:)1,)))))“FIRST”:)“Don”,)))))“LAST”:)“Pinto”,)))))“ZIP”:)“94040”,)))))“CITY”:)“MV”,)))))“STATE”:)“CA”,)))))“STATUS”:)))))))){))“TEXT”:)“At)Conf”))))

) ))

})

})

))))))“GEO_LOC”:)“134”)},)“COUNTRY”:)”USA”)

Basta)aggiungere)le)informazioni)sul)documento)

JSON)

,)})

Il)NoSQL)e)i)Social)Games)

Catalogo)dei)NoSQL)

ChiavewValore)

Memcached# Redis#

Stru`ura)Da0) Documento) Colonna) Grafico)

MongoDB#

Couchbase# Cassandra#

Cache#

(mem

ory#on

ly)#

Database#

(mem

ory/disk)#

Neo4J#

Come)scegliere)il)database)NoSQL))piu’)ada`o?)

Crescita)rapida)

ReaCvita’)del)gioco)

Gioco)globalizzato)e)sempre)aCvo)

Modifiche)frequen0)e)veloci)

Scalabilita’)

Performance)

Sempre)live)

Modello)dei)da0)flessibile)

Couchbase)Open)Source)

•  Il#principale#database#NoSQL#distribuito#

•  Supporta#sia#le#applicazioni#chiaveJvalore#che#a#documento#

•  Tum#I#componen=#sono#disponibili#con#licenza#Apache)2.0)Public)License)

•  Disponibile#come#paccheBo#sonware#sia#nella#versione#Community#che#in#quella#Enterprise#

Couchbase Open Source Project

≠)

Scalabilita’#Semplice#

Performance#Elevate#e#Costan=#

Sempre#Live#24x365#

Ingrandisci#il#tuo#cluster#con#un#click#mentre#l’applicazione#

rimane#live#

Tempi#di#risposta#costan=#soBo#il#millisecondo#per#operazioni#di#

scriBura#e#leBura##

L’applicazione#non#e’#mai#inamva#anche#in#caso#di#

aggiornamen=,#manutenzione#etc.#

Modello#Da=#Flessibile#

Supporto#per#documen=#JSON#senza#uno#schema#rigido#

Principi)Chiave)di)Couchbase)Server)

Differenze)Principali)Rispe`o)ad)Altri)Database)NoSQL)

•  PermeBe#un#al=ssimo#numero#di#connessioni#contemporanee#(fondamentale#per#applicazioni#web#interamve)#

•  Nessun#locks#•  Cache#na=va)•  Hash#par==oning#(non#range)####

!#non#si#formano#“hotspots”#

•  Sharding#automa=co#

Dietro)le)Quinte)di)Couchbase)

3#3# 2#

Server)Singolow)Operazione)Scri`ura)con)Couchbase)

Managed#Cache#

Disk#Que

ue#

Replica=on#Queue#

App#Server#

Doc)1’)

Doc)1)

Doc)1’)Doc)1)

Doc)1’)

Disk#

To#other#node#

Couchbase#Server#Node#

GET)

Doc)1)

3#3# 2#

Server)Singolow)Operazione)Le`ura)con)Couchbase)

Disk#Que

ue#

Replica=on#Queue#

App#Server#

Doc)1)

Doc)1)Doc)1)

Managed#Cache#

Disk#

To#other#node#

Couchbase#Server#Node#

COUCHBASE)SERVER))CLUSTER)

Operazioni)di)Base)sul)Cluster)

• TuC)I)nodi)sono)uguali)e)I)documen0)sono)ugualmente)distribui0)

• Ogni)server)con0ene)sia)I)documen0)aCvi)che)quelli)replica)

• La)mappa)del)cluster)ha)le)coordinate)su)dove)si)trovano)I)documen0)))))))))))))))))))L’applicazione#non#ha#bisogno#di#saperlo#

User#Configured#Replica#Count#=#1#

READ/WRITE/UPDATE)

)) ACTIVE)

Doc)5)

Doc)2)

Doc)

Doc)

Doc)

SERVER)1) )) ACTIVE)

Doc)4)

Doc)7)

Doc)

Doc)

Doc)

SERVER)2)

Doc)8)

)) ACTIVE)

Doc)1)

Doc)3)

Doc)

Doc)

Doc)

REPLICA)

Doc)4)

Doc)1)

Doc)8)

Doc)

Doc)

Doc)

REPLICA)

Doc)6)

Doc)3)

Doc)2)

Doc)

Doc)

Doc)

REPLICA)

Doc)7)

Doc)9)

Doc)5)

Doc)

Doc)

Doc)

SERVER)3)

Doc)6)

APP)SERVER)1)

COUCHBASE)Client)Library))) CLUSTER)MAP)

COUCHBASE)Client)Library))) CLUSTER)MAP)

APP)SERVER)2)

Doc)9)

Aggiungere)Nodi)al)Cluster)

• Due)servers)aggiun0)con)un)solo)click)

•  I)documen0)vengono)automa0camente)ribilancia0)a`raverso)il)cluster)Col#minimo#spostamento#di#documen=#possibile#

•  La)mappa)del)cluster)viene)aggiornata)

•  L’applicazione)ora)e’)supportata)da)un)numero)maggiore)di)servers.)

))

REPLICA)

ACTIVE)

Doc)5)

Doc)2)

Doc)

Doc)

Doc)4)

Doc)1)

Doc)

Doc)

SERVER)1) ))

REPLICA)

ACTIVE)

Doc)4)

Doc)7)

Doc)

Doc)

Doc)6)

Doc)3)

Doc)

Doc)

SERVER)2) ))

REPLICA)

ACTIVE)

Doc)1)

Doc)3)

Doc)

Doc)

Doc)7)

Doc)9)

Doc)

Doc)

SERVER)3) ))

SERVER)4) ))

SERVER)5)

REPLICA)

ACTIVE)

REPLICA)

ACTIVE)

Doc)

Doc)8) Doc)

Doc)9) Doc)

Doc)2) Doc)

Doc)8) Doc)

Doc)5) Doc)

Doc)6)

READ/WRITE/UPDATE) READ/WRITE/UPDATE)

APP)SERVER)1)

COUCHBASE)Client)Library))) CLUSTER)MAP)

COUCHBASE)Client)Library))) CLUSTER)MAP)

APP)SERVER)2)

COUCHBASE)SERVER))CLUSTER)

User#Configured#Replica#Count#=#1#

Caduta)di)un)Nodo)

))

REPLICA)

ACTIVE)

Doc)5)

Doc)2)

Doc)

Doc)

Doc)4)

Doc)1)

Doc)

Doc)

SERVER)1) ))

REPLICA)

ACTIVE)

Doc)4)

Doc)7)

Doc)

Doc)

Doc)6)

Doc)3)

Doc)

Doc)

SERVER)2) ))

REPLICA)

ACTIVE)

Doc)1)

Doc)10)

Doc)

Doc)

Doc)7)

Doc)9)

Doc)

Doc)

SERVER)3) ))

SERVER)4) ))

SERVER)5)

REPLICA)

ACTIVE)

REPLICA)

ACTIVE)

Doc)9)

Doc)8)

Doc) Doc)6) Doc)

Doc)

Doc)5) Doc)10)

Doc)2)

Doc)8) Doc)

Doc)

•  I)server)della)app)accedono)ai)da0)

•  Le)richieste)al)Server)3)falliscono)

•  Il)Cluster)iden0fica)che)un)nodo)e’)offline)Le#repliche#vengono#promosse#ad#amve#e#la#mappa#del#cluster#viene#aggiornata#

•  Le)richieste)della)app)ora)si)dirigono)sul)server)appropriato)

•  Il)tu`o)e’)seguito)dal)ribilanciamento)dei)da0)

Doc)

Doc)1) Doc)3)

APP)SERVER)1)

COUCHBASE)Client)Library))) CLUSTER)MAP)

COUCHBASE)Client)Library))) CLUSTER)MAP)

APP)SERVER)2)

User#Configured#Replica#Count#=#1#

COUCHBASE)SERVER))CLUSTER)

Cross)Data)Center)Replica0on)(XDCR))COUCHBASE)SERVER))CLUSTER)NY)DATA)CENTER)

)) ACTIVE)

Doc))

Doc)2)

SERVER)1)

Doc)9)

))

SERVER)2) ))

SERVER)3)

RAM#

Doc)) Doc)) Doc)

ACTIVE)

Doc)

Doc))

Doc))RAM#

ACTIVE)

Doc))

Doc))

Doc)RAM#

DISK#

Doc)) Doc) Doc))

DISK#

Doc) Doc) Doc)

DISK#

COUCHBASE)SERVER))CLUSTER)SF)DATA)CENTER)

)) ACTIVE)

Doc))

Doc)2)

SERVER)1)

Doc)9)

))

SERVER)2) ))

SERVER)3)

RAM#

Doc)) Doc)) Doc)

ACTIVE)

Doc)

Doc))

Doc))RAM#

ACTIVE)

Doc))

Doc))

Doc)RAM#

DISK#

Doc)) Doc) Doc))

DISK#

Doc) Doc) Doc)

DISK#

Altri)Usi)Comuni)del)NoSQL)

Market)Adop0on)–)Customers)Internet)Companies) Enterprises)

More)than)300)customers)ww)5,000)produc0on)deployments)worldwide)

Cara`eris0che)dei)Da0)

•  Stru`ura)definita)dall’utente)(Twi`er)feeds))•  Serve)supporto)per)crescita)esponenziale)(Apps)virali))•  Stru`ura)dei)da0)non)omogenea)

•  C’e’)necessita’)di)cambiare)stru`ura)frequentemente)

•  Lunghezza)dei)documen0)variabile)

•  Stru`ura)dei)da0)gerarchica)

)

Couchbase)e’)la)scelta)ideale))

Requisi0)di)Performance)

•  Latenze)estremamente)basse)(es.)1millisecondo))

•  Traffici)eleva0)(es.)200000)ops/sec))

•  Numero)di)uten0)elevato)

•  Domanda)non)preven0vabile)con)crescite)improvvise)

•  C’e’)predominanza)di)accesso)dire`o)ai)documen0)

•  Alto)traffico)in)le`ura)e)scri`ura)

)

Couchbase)e’)la)scelta)ideale))

Applicazioni)Comuni)Social)Gaming)

)•  Couchbase#con=ene#I#da=#sugli#uten=#e#I#giochi#

•  Esempi#clien=:#Zynga,#Tapjoy,#Ubison,#Tencent#

)

)Apps)Mobili)

)•  Couchbase#con=ene#da=#su#uten=#e#contenu=#

•  Esempi#clien=:#Kobo,#Play=ka##

)

)

Pubblicita’)Online))

•  Couchbase#con=ene#info#sugli#uten=#per#un#accesso#veloce#

•  Esempi#clien=:#AOL,#Mediamind,#Convertro##

)

Informazioni)di)Sessione))

•  Couchbase#come#database#chiaveJvalore#

•  Esempi#clien=:#Concur,#Sabre#

)

Profili)Uten0))

•  Couchbase#come#database#chiaveJvalore#

•  Esempi#clien=:#Tunewiki#

)Cache)ad)Alta)Disponibilita’)

)•  Couchbase#u=lizzato#come#livello#di#cache#

•  Esempi#clien=:#Orbitz#

)

Metadata)e)Contenu0)•  Couchbase#insieme#ad#Elas=csearch#

•  Esempi#clien=:#McGraw#Hill#)

)Aggregazione)Da0)

)•  Couchbase#aggrega#I#da=#dai#social#media#

•  Esempi#clien=:#Sambacloud#

)

Ques0ons?)

Non)dimen0cate)di………)

Scaricare)e)fare)pra0ca)con)Couchbase)Server)

h`p://www.couchbase.com/download)

Iscrivervi)sul)gruppo)di)Couchbase)Italia)su)LinkedIn)

h`p://www.linkedin.com/groups/CouchbasewItaliaw4932288)

Iscrivervi)sul)nostro)Community)Portal)h`p://www.couchbase.com/communi0es/user/register)

Grazie)a)TuC!)

franco@couchbase.com)

Recommended