SlideShare a Scribd company logo
1 of 70
Download to read offline
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

More Related Content

Similar to 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
 

Similar to 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
 

More from Ole-Martin Mørk

More from 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
 

Recently uploaded

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
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
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
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
 
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
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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 Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
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
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
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
 
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
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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 Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

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