SlideShare une entreprise Scribd logo
1  sur  70
Télécharger pour lire hors ligne
PATTERNS FOR
KEY-VALUE STORE

   JavaZone 2012




   Ole-Martin Mørk
       13/09/12
OM MEG


Ole-Martin Mørk
Scientist
Bekk Consulting AS




twitter: olemartin
AGENDA

         INTRODUCTION

         DIFFERENT KV STORES

         GENERAL PATTERNS

         RIAK PATTERNS

         REDIS PATTERNS

         RIAK+REDIS PATTERNS

         SUMMARY
MAP



 KEY         VALUE
 session_1   Functional Programming You Already Know
 session_2   Fra enkel J2SE til Grid computing med GigaSpaces XAP
 session_3   Reinventing software quality
 session_4   Taming Java Agents
 session_5   Memory Leaks in Java
 session_6   Linking data without common identifiers
 session_7   Avinstaller Java nå!
PUT
GET
DEL
KEY
VALUE
STORE
select value
from lookup 	
where key=?
HVORFOR BENYTTE KEY-VALUE STORES?   1
                                    0


   Speed
Distribution
HVORFOR BENYTTE KEY-VALUE STORES?                   1
                                                    2




                                    When all you
                                    have is a hammer..
PERSON OG ADRESSER




                     Person
      Epost                      Tlf

                     Adresse

      Twitter                  Facebook
navn: “Ole-Martin Mørk”,	
     	eposter:          epost: ”me@ole - martin.net”   	
     	   	    	     	   type: “jobb”, epost: “ole-martin.mork@bekk.no” 	
     	tlf:        type: “mobil”, tlf: “90252338”   	
     	adresser: 	
     	   	type: “hjem”	
     	   	adresse:       gate: “Lundliveien 30b”, sted: “Oslo” 	
	
     	   	type: “jobb”	
     	   	adresse:      	postboks: “postboks 134, Sentrum”, sted: “Oslo”	
     	   	    	     	   	postnummer: “0150”
{navn: “Ole-Martin Mørk”,	
  	eposter: [ { epost: ”me@ole - martin.net” }, 	
  	   	     	   	{ type: “jobb”, epost: “ole-martin.mork@bekk.no” }],	
  	tlf: [{ type: “mobil”, tlf: “90252338” }],	
  	adresser: [{	
  	   	type: “hjem”, 	
  	   	adresse: { gate: “Lundliveien 30b”, sted: “Oslo” }	
  	   	}, {	
  	   	type: “jobb”,	
  	   	adresse: { 	postboks: “postboks 134, Sentrum”, sted: “Oslo”,	
  	   	     	   	   	postnummer: “0150”	
  	   	}	
  	}]}
HTML5 LOCALSTORAGE




            Demo     Klikk!
CASSANDRA   1
            9
DETTE ER FINE DATABASER   2
                          0




         Why?
PATTERNS
Keys
WELL-FORMED KEYS




    app:space:what:id
LOOKUPS ON OTHER DATA                                       2
                                                            4
   user:id:1234
                         userId       1234
                         username     olemartin
                         email        olemartin@bekk.no
                         twitter      olemartin




                  user:twitter:olemartin     user:id:1234
RELATIONS

   user:id:1234
                  userId     1234
                  username   olemartin
                  email      olemartin@bekk.no
                  twitter    olemartin

   user:id:4321
                  userId     4321
                  username   grolisbeth
                  brother    user:id:1234
Hash
HASHING




 <hash> modulo <antall servere> = serverId
HASHING




          43
           4   3
                   32 2
                      2
                          11   1
KONSISTENT HASHING

                     A




                         B
             C
KONSISTENT HASHING

                     A




                         B
             C
KONSISTENT HASHING

                     A


                 D
            D
                 C       A
                 C           B
             C


                     B
Use cases
EKSEMPLER PÅ APPLIKASJONER SOM KAN KLE K/V




RDBMS + KEY/VALUE
RIAK




                  Key
                   Key
                     Key
                     Key
       Bucket
         Bucket
       Bucket
Consistency
Availability
P artition
N W R
N>W
N>R
PATTERNS
RIAK OG MAP REDUCE
MAP REDUCE




   shopping:13092012:userId
SECONDARY INDEXES               4
                                6


                    Secondary
                     indexes
SECONDARY INDEXES                                         4
                                                          7
   user:id:1234
                         userId     1234
                         username   olemartin
                         email      olemartin@bekk.no
                         twitter    olemartin




   twitter:id_bin   olemartin
   email:id_bin user:twitter:olemartin
                     olemartin@bekk.no     user:id:1234
   user:sex_bin     Male
   user:age_int     35
Pre     Post
Commit   Commit
Hash
               Sorted Sets
       Lists
Sets            Strings
PATTERNS
SELECT * FROM foo
WHERE ...
ORDER BY time DESC LIMIT 10
PATTERNS FOR MILJØER MED RDBMS




   RDBMS                    REDIS
STATISTIKK

Antall sider lest av bruker
<pages:userId, count>
incr pages:userId


Mest leste i dag:
<most_read:300-2012, <url, count>,<url, count>>
zrangebyscore most_read:300-2012 -inf +inf


Unike besøkende:
<page:url:300-2012, <userId>, <userId>, <userId>>
scard page:url:300-2012
SERIALIZATION



         100000 ms
          90000 ms
          80000 ms
          70000 ms
          60000 ms
          50000 ms
          40000 ms
          30000 ms
          20000 ms
          10000 ms
              0 ms
KRYO IN REDIS




<bean id="redisTemplate"	
    class="org.springframework.data.redis.core.RedisTemplate">	
    <property name="connectionFactory" ref="connectionFactory"/>	
    <property name="defaultSerializer" ref="serializer"/>	
</bean>	
	
<bean id="serializer" class="no.bekk.redis.DiggerSerializer"/>
KRYO

public class DiggerSerializer<T> implements RedisSerializer<T> {	

     private Kryo kryo = new Kryo();	

     public DiggerSerializer() {	
           kryo.register(Story.class);	
      }	
     public byte[] serialize(T t) {	
           return new ObjectBuffer(kryo).writeClassAndObject(t);	
      }	
      public T deserialize(byte[] bytes) {	
           return (T) new ObjectBuffer(kryo).readClassAndObject(bytes);	
      }	
}
REDDIT KLONE

1.  story:id – holder styr på id-en til en story
2.  story:id, value – holder selve story-objektet
3.  story:stories_zset – holder styr på antall stemmer
4.  story:tag:storyId – holder styr på tags knyttet til en story
5.  tag:tagId – holder styr på stories knyttet til en tag
REDIS OG RIAK




                +
                =
Product
catalog
     Produktkatalog
RIAK




                    product:2
       Products   product:1
POST COMMIT



                    RSS




         Products         Redis
REDIS




        catalog:product:id    binary data

        catalog:product:today:sold_zset <productId, counter>

        catalog:product:week:sold_zset   <productId, counter>

        catalog:product:year:sold_zset   <productId, counter>
RESULT
Summary
SUMMARY


1.  KV-stores kommer i alle farger og fasonger
2.  Gode nøkkelnavn
3.  Bruk god tid på datamodellering


4.  Konsistent hashing
5.  Bruk KV-store sammen med RDBMS
6.  Bruk KV-store for domener som matcher


7.  Bruk databasen til det den er god til
8.  Kombiner gjerne flere type KV-stores
9.  La kreativiteten blomstre
6
             9




Questions?
TAKK FOR
     MEG!

    Ole-Martin Mørk
ole-martin.mork@bekk.no
      @olemartin

Contenu connexe

Similaire à Patterns for key-value stores

201301 - Panorama NoSQL
201301 - Panorama NoSQL201301 - Panorama NoSQL
201301 - Panorama NoSQLlyonjug
 
Introducing Stitch
Introducing Stitch Introducing Stitch
Introducing Stitch MongoDB
 
RedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory OptimizationRedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory OptimizationRedis Labs
 
Slides: Moving from a Relational Model to NoSQL
Slides: Moving from a Relational Model to NoSQLSlides: Moving from a Relational Model to NoSQL
Slides: Moving from a Relational Model to NoSQLDATAVERSITY
 
Cassandra Intro -- TheEdge2012
Cassandra Intro -- TheEdge2012Cassandra Intro -- TheEdge2012
Cassandra Intro -- TheEdge2012robosonia Mar
 
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...MongoDB
 
HBaseCon 2015: S2Graph - A Large-scale Graph Database with HBase
HBaseCon 2015: S2Graph - A Large-scale Graph Database with HBaseHBaseCon 2015: S2Graph - A Large-scale Graph Database with HBase
HBaseCon 2015: S2Graph - A Large-scale Graph Database with HBaseHBaseCon
 
Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011Jordi Valverde
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revisedMongoDB
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessMongoDB
 
Building a Cross Channel Content Delivery Platform with MongoDB
Building a Cross Channel Content Delivery Platform with MongoDBBuilding a Cross Channel Content Delivery Platform with MongoDB
Building a Cross Channel Content Delivery Platform with MongoDBMongoDB
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
Querying Riak Just Got Easier - Introducing Secondary Indices
Querying Riak Just Got Easier - Introducing Secondary IndicesQuerying Riak Just Got Easier - Introducing Secondary Indices
Querying Riak Just Got Easier - Introducing Secondary IndicesRusty Klophaus
 
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Couchbase Tutorial: Big data Open Source Systems: VLDB2018Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Couchbase Tutorial: Big data Open Source Systems: VLDB2018Keshav Murthy
 
BADCamp 2008 DB Sync
BADCamp 2008 DB SyncBADCamp 2008 DB Sync
BADCamp 2008 DB SyncShaun Haber
 
OC Big Data Monthly Meetup #5 - Session 2 - Sumo Logic
OC Big Data Monthly Meetup #5 - Session 2 - Sumo LogicOC Big Data Monthly Meetup #5 - Session 2 - Sumo Logic
OC Big Data Monthly Meetup #5 - Session 2 - Sumo LogicBig Data Joe™ Rossi
 
Hadoop & no sql new generation database systems
Hadoop & no sql   new generation database systemsHadoop & no sql   new generation database systems
Hadoop & no sql new generation database systemsramazan fırın
 
Couchbase N1QL: Language & Architecture Overview.
Couchbase N1QL: Language & Architecture Overview.Couchbase N1QL: Language & Architecture Overview.
Couchbase N1QL: Language & Architecture Overview.Keshav Murthy
 

Similaire à Patterns for key-value stores (20)

201301 - Panorama NoSQL
201301 - Panorama NoSQL201301 - Panorama NoSQL
201301 - Panorama NoSQL
 
Introducing Stitch
Introducing Stitch Introducing Stitch
Introducing Stitch
 
RedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory OptimizationRedisConf18 - Redis Memory Optimization
RedisConf18 - Redis Memory Optimization
 
Slides: Moving from a Relational Model to NoSQL
Slides: Moving from a Relational Model to NoSQLSlides: Moving from a Relational Model to NoSQL
Slides: Moving from a Relational Model to NoSQL
 
Cassandra Intro -- TheEdge2012
Cassandra Intro -- TheEdge2012Cassandra Intro -- TheEdge2012
Cassandra Intro -- TheEdge2012
 
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
 
HBaseCon 2015: S2Graph - A Large-scale Graph Database with HBase
HBaseCon 2015: S2Graph - A Large-scale Graph Database with HBaseHBaseCon 2015: S2Graph - A Large-scale Graph Database with HBase
HBaseCon 2015: S2Graph - A Large-scale Graph Database with HBase
 
Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011Lighting talk neo4j fosdem 2011
Lighting talk neo4j fosdem 2011
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
 
Building a Cross Channel Content Delivery Platform with MongoDB
Building a Cross Channel Content Delivery Platform with MongoDBBuilding a Cross Channel Content Delivery Platform with MongoDB
Building a Cross Channel Content Delivery Platform with MongoDB
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
Querying Riak Just Got Easier - Introducing Secondary Indices
Querying Riak Just Got Easier - Introducing Secondary IndicesQuerying Riak Just Got Easier - Introducing Secondary Indices
Querying Riak Just Got Easier - Introducing Secondary Indices
 
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Couchbase Tutorial: Big data Open Source Systems: VLDB2018Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
 
MongoDB
MongoDBMongoDB
MongoDB
 
BADCamp 2008 DB Sync
BADCamp 2008 DB SyncBADCamp 2008 DB Sync
BADCamp 2008 DB Sync
 
OC Big Data Monthly Meetup #5 - Session 2 - Sumo Logic
OC Big Data Monthly Meetup #5 - Session 2 - Sumo LogicOC Big Data Monthly Meetup #5 - Session 2 - Sumo Logic
OC Big Data Monthly Meetup #5 - Session 2 - Sumo Logic
 
Hadoop & no sql new generation database systems
Hadoop & no sql   new generation database systemsHadoop & no sql   new generation database systems
Hadoop & no sql new generation database systems
 
Couchbase N1QL: Language & Architecture Overview.
Couchbase N1QL: Language & Architecture Overview.Couchbase N1QL: Language & Architecture Overview.
Couchbase N1QL: Language & Architecture Overview.
 
MongoDB and Schema Design
MongoDB and Schema DesignMongoDB and Schema Design
MongoDB and Schema Design
 

Plus de Ole-Martin Mørk

Plus de Ole-Martin Mørk (9)

Graph search with Neo4j
Graph search with Neo4jGraph search with Neo4j
Graph search with Neo4j
 
Polyglot Persistence
Polyglot PersistencePolyglot Persistence
Polyglot Persistence
 
Presentation of Redis
Presentation of RedisPresentation of Redis
Presentation of Redis
 
Evolusjonen av PaaS
Evolusjonen av PaaSEvolusjonen av PaaS
Evolusjonen av PaaS
 
Polyglot persistence
Polyglot persistencePolyglot persistence
Polyglot persistence
 
Du må vite hva som skjer i produksjon
Du må vite hva som skjer i produksjonDu må vite hva som skjer i produksjon
Du må vite hva som skjer i produksjon
 
Presentasjon om skyen
Presentasjon om skyenPresentasjon om skyen
Presentasjon om skyen
 
Hele butikken i skyen
Hele butikken i skyenHele butikken i skyen
Hele butikken i skyen
 
Collaborative Filtering in Map/Reduce
Collaborative Filtering in Map/ReduceCollaborative Filtering in Map/Reduce
Collaborative Filtering in Map/Reduce
 

Dernier

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Dernier (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Patterns for key-value stores

  • 1. PATTERNS FOR KEY-VALUE STORE JavaZone 2012 Ole-Martin Mørk 13/09/12
  • 2. OM MEG Ole-Martin Mørk Scientist Bekk Consulting AS twitter: olemartin
  • 3. AGENDA INTRODUCTION DIFFERENT KV STORES GENERAL PATTERNS RIAK PATTERNS REDIS PATTERNS RIAK+REDIS PATTERNS SUMMARY
  • 4. MAP KEY VALUE session_1 Functional Programming You Already Know session_2 Fra enkel J2SE til Grid computing med GigaSpaces XAP session_3 Reinventing software quality session_4 Taming Java Agents session_5 Memory Leaks in Java session_6 Linking data without common identifiers session_7 Avinstaller Java nå!
  • 5. PUT
  • 6. GET
  • 7. DEL
  • 10. HVORFOR BENYTTE KEY-VALUE STORES? 1 0 Speed
  • 12. HVORFOR BENYTTE KEY-VALUE STORES? 1 2 When all you have is a hammer..
  • 13. PERSON OG ADRESSER Person Epost Tlf Adresse Twitter Facebook
  • 14. navn: “Ole-Martin Mørk”, eposter: epost: ”me@ole - martin.net” type: “jobb”, epost: “ole-martin.mork@bekk.no” tlf: type: “mobil”, tlf: “90252338” adresser: type: “hjem” adresse: gate: “Lundliveien 30b”, sted: “Oslo” type: “jobb” adresse: postboks: “postboks 134, Sentrum”, sted: “Oslo” postnummer: “0150”
  • 15. {navn: “Ole-Martin Mørk”, eposter: [ { epost: ”me@ole - martin.net” }, { type: “jobb”, epost: “ole-martin.mork@bekk.no” }], tlf: [{ type: “mobil”, tlf: “90252338” }], adresser: [{ type: “hjem”, adresse: { gate: “Lundliveien 30b”, sted: “Oslo” } }, { type: “jobb”, adresse: { postboks: “postboks 134, Sentrum”, sted: “Oslo”, postnummer: “0150” } }]}
  • 16.
  • 17. HTML5 LOCALSTORAGE Demo Klikk!
  • 18.
  • 19. CASSANDRA 1 9
  • 20. DETTE ER FINE DATABASER 2 0 Why?
  • 22. Keys
  • 23. WELL-FORMED KEYS app:space:what:id
  • 24. LOOKUPS ON OTHER DATA 2 4 user:id:1234 userId 1234 username olemartin email olemartin@bekk.no twitter olemartin user:twitter:olemartin user:id:1234
  • 25. RELATIONS user:id:1234 userId 1234 username olemartin email olemartin@bekk.no twitter olemartin user:id:4321 userId 4321 username grolisbeth brother user:id:1234
  • 26. Hash
  • 27. HASHING <hash> modulo <antall servere> = serverId
  • 28. HASHING 43 4 3 32 2 2 11 1
  • 31. KONSISTENT HASHING A D D C A C B C B
  • 33. EKSEMPLER PÅ APPLIKASJONER SOM KAN KLE K/V RDBMS + KEY/VALUE
  • 34.
  • 35.
  • 36.
  • 37. RIAK Key Key Key Key Bucket Bucket Bucket
  • 39. N W R
  • 40. N>W
  • 41. N>R
  • 42.
  • 44. RIAK OG MAP REDUCE
  • 45. MAP REDUCE shopping:13092012:userId
  • 46. SECONDARY INDEXES 4 6 Secondary indexes
  • 47. SECONDARY INDEXES 4 7 user:id:1234 userId 1234 username olemartin email olemartin@bekk.no twitter olemartin twitter:id_bin olemartin email:id_bin user:twitter:olemartin olemartin@bekk.no user:id:1234 user:sex_bin Male user:age_int 35
  • 48. Pre Post Commit Commit
  • 49.
  • 50. Hash Sorted Sets Lists Sets Strings
  • 52. SELECT * FROM foo WHERE ... ORDER BY time DESC LIMIT 10
  • 53. PATTERNS FOR MILJØER MED RDBMS RDBMS REDIS
  • 54.
  • 55. STATISTIKK Antall sider lest av bruker <pages:userId, count> incr pages:userId Mest leste i dag: <most_read:300-2012, <url, count>,<url, count>> zrangebyscore most_read:300-2012 -inf +inf Unike besøkende: <page:url:300-2012, <userId>, <userId>, <userId>> scard page:url:300-2012
  • 56. SERIALIZATION 100000 ms 90000 ms 80000 ms 70000 ms 60000 ms 50000 ms 40000 ms 30000 ms 20000 ms 10000 ms 0 ms
  • 57. KRYO IN REDIS <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="connectionFactory"/> <property name="defaultSerializer" ref="serializer"/> </bean> <bean id="serializer" class="no.bekk.redis.DiggerSerializer"/>
  • 58. KRYO public class DiggerSerializer<T> implements RedisSerializer<T> { private Kryo kryo = new Kryo(); public DiggerSerializer() { kryo.register(Story.class); } public byte[] serialize(T t) { return new ObjectBuffer(kryo).writeClassAndObject(t); } public T deserialize(byte[] bytes) { return (T) new ObjectBuffer(kryo).readClassAndObject(bytes); } }
  • 59. REDDIT KLONE 1.  story:id – holder styr på id-en til en story 2.  story:id, value – holder selve story-objektet 3.  story:stories_zset – holder styr på antall stemmer 4.  story:tag:storyId – holder styr på tags knyttet til en story 5.  tag:tagId – holder styr på stories knyttet til en tag
  • 61.
  • 62. Product catalog Produktkatalog
  • 63. RIAK product:2 Products product:1
  • 64. POST COMMIT RSS Products Redis
  • 65. REDIS catalog:product:id binary data catalog:product:today:sold_zset <productId, counter> catalog:product:week:sold_zset <productId, counter> catalog:product:year:sold_zset <productId, counter>
  • 68. SUMMARY 1.  KV-stores kommer i alle farger og fasonger 2.  Gode nøkkelnavn 3.  Bruk god tid på datamodellering 4.  Konsistent hashing 5.  Bruk KV-store sammen med RDBMS 6.  Bruk KV-store for domener som matcher 7.  Bruk databasen til det den er god til 8.  Kombiner gjerne flere type KV-stores 9.  La kreativiteten blomstre
  • 69. 6 9 Questions?
  • 70. TAKK FOR MEG! Ole-Martin Mørk ole-martin.mork@bekk.no @olemartin