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

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
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
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Recently uploaded (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
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
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
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.
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

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