SlideShare a Scribd company logo
Redis: The Universal NoSQL-
            Tool
            Eberhard Wolff
Architecture and Technology Manager
              adesso AG
NoSQL is all
about Big Data
NoSQL is all
about Big Data
Redis
•  Remote Dictionary Server
•  Advanced Key Value Store
•  Actually also a cache and a messaging
   server
•  Open Source – free to change the code
•  Sponsored by VMware
•  No commercial agenda
•  Implemented in C (actually pretty small)
•  In memory (fast)
Redis
•  Data should fit in memory
•  Data written asynchronously to disk or in
   an append only file
  –  Won't slow down operations
  –  Configurable delay
•  Bindings for many languages
•  Very easy replication
•  i.e. like an in-memory cache with
   persistence option
•  http://redis.io/
Redis - The Universal NoSQL Tool
How to Use Redis
•  Very simple protocol
•  Can telnet to it

•  Libraries for lots of languages

•  Java:
    –  Jedis
    –  JRedis
    –  RJC
•  Spring Data Redis as abstraction
    –  Uniform concepts (e.g. templates) across all NoSQL and SQL
       stores
    –  Even JPA
    –  Exception translation
    –  Still exposes unique features
Use Case: High Scores for
            Players
•  Online game
•  Store high scores

•  High data volume
•  Frequently changing data
Use Case: High Scores for
            Players
•  Note: Other data (name, email, etc) can
   still be stored somewhere else

•  Key: Name of player
•  Value: Score
•  Encoded as bytes

•  Operations: GET, SET, DEL
Demo: RedisWriter /
RedisMultiWriter / RedisClean /
   redis-cli / telnet / redis-
         benchmark
Points to Note
•  Extremely fast
•  See http://redis.io/topics/benchmarks
•  Multi Set: Can issue multiple set operations in
   one round trip for very high performance
•  Data in database does not impact performance
•  Data written asynchronously
•  Not shown:
   –  APPEND : append data to a key
   –  KEYS : find all keys for a pattern
   –  RENAME : Change key
Redis as a Cache
•  Data kept in memory
•  …and on disk
•  Data survives restarts
•  No need for the cache to warm up
•  But: What about evicting data from the cache?
•  Solution: Data can have time-to-live
•  Can set global memory policy to avoid
   excessive memory consumption
•  Let assume certain texts (e.g. HTML) should be
   cached for our application…
Demo: RedisCache
Create Unique Player ID
•  Each player should have a unique ID
•  Needs to be unique, even in a cluster
•  Solution: atomic incr operation
•  i.e. works correctly even if multiple
   threads access the counter at the same
   time
•  Quick – in memory
Demo: RedisCreateID
Similar operations
•  GETSET : Atomically get old value and
   set to new value
•  Global locks using SETNX / DEL
•  SETNX returns true only if the client
   successfully set the value
•  i.e. lock was successfully acquired
Replication
•  Redis uses master / slave replication
•  Slaves can replicate to other slaves
•  Replication does not block the master
•  Useable for scalability of reads or data
   redundancy
•  Write would go to the master and be
   propagated
•  Make backups quite easy
•  Just add
   slaveof <ip> <port>
   to redis.conf
Scaling
•  Slaves can be used for (eventually
   consistent) reads
•  Storage to disk can be offloaded to
   slaves
•  No more breaks during disk writes
•  But: Only one master can write
•  Still: All data should fit in RAM
Scaling
•  Can use Virtual Memory
•  Redis has its own Virtual Memory
   implementation (to be deprecated)
•  Partially implemented: Redis Cluster with
   Master / Slave replication
•  Sharding i.e. data distributed across many
   nodes
•  Could implement your own sharding on the
   client
Redis Data Types
•  So far: Simple types: byte[]
   –  String and numbers encoded as byte[]
   –  Can cluster multiple get/set into one atomic action
•  Atomic increment / decrement for integers
•  Lists
   –  Can add / remove atomically
•  Sets
   –  Like lists but no order
•  Sorted sets
   –  Each element has a score to sort by
Highscores
•  Range the high scores
•  Solutions: Use a sorted set

•  Result: scores automatically sorted

•  Trivial to get the top high scores
Demo: RedisHighScore
Sending EMails
•  EMails should be sent by a server

•  Need to queue emails

•  Solution: Use a list + push / pop
Demo: RedisEMailReaderList /
   RedisEMailWriterList
Next step: Messaging
•  Lists are not really designed for communication
•  Message driven middleware is an established
   concept
•  Redis has some parts
•  Topics
   –  Have a name
   –  Multiple receivers can listen to it
•  Subscribe to
   –  A Topic
   –  Or a patterns of topic names
Demo:
RedisEMailReaderMessaging /
 RedisEMailWriterMessaging
Transactions
•    Multiple actions can be put into a transaction
•    Command MULTI to start transaction
•    EXEC to execute
•    DISCARD to discard

•  Guarantees:
     –  Executed in the defined order
     –  Atomic (all or nothing)
     –  No isolation
     –  Can use optimistic locking
Key-Value Stores: Store Complex Data
•  Storing data as serialized blobs / JSON / XML
     –  ”player:wolff" è ”all the data"
•  Storing data as multiple keys
     –  "player:wolff:score" è 42
     –  "player:wolff:email" è ”eberhard.wolff@adesso.de"
•    Requires multi get/set to be efficient
•    Can find all keys using patterns
•    Can create your custom Serializer in Spring Data
•    Key / values stores are no really useful for
     complex data
Conclusion – Redis is a Swiss Knife
•    Very fast - In Memory
•    Cache + persistence
•    Messaging
•    Centralized locking and counting
•    Much more than just persistence
•    Not shown: Lua scripting
•    Not useful for
     –  Big Data
     –  Seamless scaling
     –  Ad hoc queries
•  Will not be the only data store you use
Links
•  http://redis.io/
•  Try it yourself: http://try.redis-db.com/
•  Spring Data Redis
   http://www.springsource.org/spring-data/redis
•  Demos: https://github.com/ewolff/spring-redis-demo
•  Who is using it?
   http://redis.io/topics/whos-using-redis
•  Books
  –  Tiago Macedo, Fred Oliveira: Redis Cookbook
  –  Pollack, Gierke, Risberg, Brisbin, Hunger: Spring Data
Ad

More Related Content

What's hot (19)

Using Redis at Facebook
Using Redis at FacebookUsing Redis at Facebook
Using Redis at Facebook
Redis Labs
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
PostgreSQL-Consulting
 
Ansible for large scale deployment
Ansible for large scale deploymentAnsible for large scale deployment
Ansible for large scale deployment
Karthik .P.R
 
From 100s to 100s of Millions
From 100s to 100s of MillionsFrom 100s to 100s of Millions
From 100s to 100s of Millions
Erik Onnen
 
DrupalCampLA 2014 - Drupal backend performance and scalability
DrupalCampLA 2014 - Drupal backend performance and scalabilityDrupalCampLA 2014 - Drupal backend performance and scalability
DrupalCampLA 2014 - Drupal backend performance and scalability
cherryhillco
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
Ricard Clau
 
CI_CONF 2012: Scaling
CI_CONF 2012: ScalingCI_CONF 2012: Scaling
CI_CONF 2012: Scaling
Chris Miller
 
Apache Con 2021 Structured Data Streaming
Apache Con 2021 Structured Data StreamingApache Con 2021 Structured Data Streaming
Apache Con 2021 Structured Data Streaming
Shivji Kumar Jha
 
Managing 50K+ Redis Databases Over 4 Public Clouds ... with a Tiny Devops Team
Managing 50K+ Redis Databases Over 4 Public Clouds ... with a Tiny Devops TeamManaging 50K+ Redis Databases Over 4 Public Clouds ... with a Tiny Devops Team
Managing 50K+ Redis Databases Over 4 Public Clouds ... with a Tiny Devops Team
Redis Labs
 
Migrate Oracle database to Amazon RDS
Migrate Oracle database to Amazon RDSMigrate Oracle database to Amazon RDS
Migrate Oracle database to Amazon RDS
Jesus Guzman
 
Performance out
Performance outPerformance out
Performance out
Andrea Martinez
 
Roshan Bhattarai: Scaling WordPress for high traffic sites
Roshan Bhattarai: Scaling WordPress for high traffic sitesRoshan Bhattarai: Scaling WordPress for high traffic sites
Roshan Bhattarai: Scaling WordPress for high traffic sites
wpnepal
 
Scaling wordpress for high traffic
Scaling wordpress for high trafficScaling wordpress for high traffic
Scaling wordpress for high traffic
Roshan Bhattarai
 
Scaling MySQL using Fabric
Scaling MySQL using FabricScaling MySQL using Fabric
Scaling MySQL using Fabric
Karthik .P.R
 
Hadoop in a Windows Shop - CHUG - 20120416
Hadoop in a Windows Shop - CHUG - 20120416Hadoop in a Windows Shop - CHUG - 20120416
Hadoop in a Windows Shop - CHUG - 20120416
Chicago Hadoop Users Group
 
Drupal performance
Drupal performanceDrupal performance
Drupal performance
Piyuesh Kumar
 
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
Nexcess.net LLC
 
lessons from managing a pulsar cluster
 lessons from managing a pulsar cluster lessons from managing a pulsar cluster
lessons from managing a pulsar cluster
Shivji Kumar Jha
 
REDIS (Remote Dictionary Server)
REDIS (Remote Dictionary Server)REDIS (Remote Dictionary Server)
REDIS (Remote Dictionary Server)
Ameya Vijay Gokhale
 
Using Redis at Facebook
Using Redis at FacebookUsing Redis at Facebook
Using Redis at Facebook
Redis Labs
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
PostgreSQL-Consulting
 
Ansible for large scale deployment
Ansible for large scale deploymentAnsible for large scale deployment
Ansible for large scale deployment
Karthik .P.R
 
From 100s to 100s of Millions
From 100s to 100s of MillionsFrom 100s to 100s of Millions
From 100s to 100s of Millions
Erik Onnen
 
DrupalCampLA 2014 - Drupal backend performance and scalability
DrupalCampLA 2014 - Drupal backend performance and scalabilityDrupalCampLA 2014 - Drupal backend performance and scalability
DrupalCampLA 2014 - Drupal backend performance and scalability
cherryhillco
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
Ricard Clau
 
CI_CONF 2012: Scaling
CI_CONF 2012: ScalingCI_CONF 2012: Scaling
CI_CONF 2012: Scaling
Chris Miller
 
Apache Con 2021 Structured Data Streaming
Apache Con 2021 Structured Data StreamingApache Con 2021 Structured Data Streaming
Apache Con 2021 Structured Data Streaming
Shivji Kumar Jha
 
Managing 50K+ Redis Databases Over 4 Public Clouds ... with a Tiny Devops Team
Managing 50K+ Redis Databases Over 4 Public Clouds ... with a Tiny Devops TeamManaging 50K+ Redis Databases Over 4 Public Clouds ... with a Tiny Devops Team
Managing 50K+ Redis Databases Over 4 Public Clouds ... with a Tiny Devops Team
Redis Labs
 
Migrate Oracle database to Amazon RDS
Migrate Oracle database to Amazon RDSMigrate Oracle database to Amazon RDS
Migrate Oracle database to Amazon RDS
Jesus Guzman
 
Roshan Bhattarai: Scaling WordPress for high traffic sites
Roshan Bhattarai: Scaling WordPress for high traffic sitesRoshan Bhattarai: Scaling WordPress for high traffic sites
Roshan Bhattarai: Scaling WordPress for high traffic sites
wpnepal
 
Scaling wordpress for high traffic
Scaling wordpress for high trafficScaling wordpress for high traffic
Scaling wordpress for high traffic
Roshan Bhattarai
 
Scaling MySQL using Fabric
Scaling MySQL using FabricScaling MySQL using Fabric
Scaling MySQL using Fabric
Karthik .P.R
 
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
Nexcess.net LLC
 
lessons from managing a pulsar cluster
 lessons from managing a pulsar cluster lessons from managing a pulsar cluster
lessons from managing a pulsar cluster
Shivji Kumar Jha
 
REDIS (Remote Dictionary Server)
REDIS (Remote Dictionary Server)REDIS (Remote Dictionary Server)
REDIS (Remote Dictionary Server)
Ameya Vijay Gokhale
 

Viewers also liked (6)

Operations and Monitoring with Spring
Operations and Monitoring with SpringOperations and Monitoring with Spring
Operations and Monitoring with Spring
Eberhard Wolff
 
Legacy Sins
Legacy SinsLegacy Sins
Legacy Sins
Eberhard Wolff
 
JAXonf 2012 New Challenges and Approaches for Enterprise Java
JAXonf 2012 New Challenges and Approaches for Enterprise JavaJAXonf 2012 New Challenges and Approaches for Enterprise Java
JAXonf 2012 New Challenges and Approaches for Enterprise Java
Eberhard Wolff
 
More Productivitiy with Spring Roo
More Productivitiy with Spring RooMore Productivitiy with Spring Roo
More Productivitiy with Spring Roo
Eberhard Wolff
 
Architectures For The Cloud
Architectures For The CloudArchitectures For The Cloud
Architectures For The Cloud
Eberhard Wolff
 
Continuous Delivery and DevOps in the Enterprise
Continuous Delivery and DevOps in the EnterpriseContinuous Delivery and DevOps in the Enterprise
Continuous Delivery and DevOps in the Enterprise
Eberhard Wolff
 
Operations and Monitoring with Spring
Operations and Monitoring with SpringOperations and Monitoring with Spring
Operations and Monitoring with Spring
Eberhard Wolff
 
JAXonf 2012 New Challenges and Approaches for Enterprise Java
JAXonf 2012 New Challenges and Approaches for Enterprise JavaJAXonf 2012 New Challenges and Approaches for Enterprise Java
JAXonf 2012 New Challenges and Approaches for Enterprise Java
Eberhard Wolff
 
More Productivitiy with Spring Roo
More Productivitiy with Spring RooMore Productivitiy with Spring Roo
More Productivitiy with Spring Roo
Eberhard Wolff
 
Architectures For The Cloud
Architectures For The CloudArchitectures For The Cloud
Architectures For The Cloud
Eberhard Wolff
 
Continuous Delivery and DevOps in the Enterprise
Continuous Delivery and DevOps in the EnterpriseContinuous Delivery and DevOps in the Enterprise
Continuous Delivery and DevOps in the Enterprise
Eberhard Wolff
 
Ad

Similar to Redis - The Universal NoSQL Tool (20)

Redis meetup
Redis meetupRedis meetup
Redis meetup
Nikhil Dole
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
Ricard Clau
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Ofer Zelig
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
Richard Schneeman
 
Redis in 20 minutes
Redis in 20 minutesRedis in 20 minutes
Redis in 20 minutes
András Fehér
 
Redis acc 2015_eng
Redis acc 2015_engRedis acc 2015_eng
Redis acc 2015_eng
DaeMyung Kang
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in Java
Ruben Badaró
 
NoSql
NoSqlNoSql
NoSql
Girish Khanzode
 
REDIS327
REDIS327REDIS327
REDIS327
Rajan Bhatt
 
Big Data Developers Moscow Meetup 1 - sql on hadoop
Big Data Developers Moscow Meetup 1  - sql on hadoopBig Data Developers Moscow Meetup 1  - sql on hadoop
Big Data Developers Moscow Meetup 1 - sql on hadoop
bddmoscow
 
KeyValue Stores
KeyValue StoresKeyValue Stores
KeyValue Stores
Mauro Pompilio
 
Introduction to Data Science NoSQL.pptx
Introduction to Data Science  NoSQL.pptxIntroduction to Data Science  NoSQL.pptx
Introduction to Data Science NoSQL.pptx
tarakesh7199
 
Redis
RedisRedis
Redis
Hung-yu Lin
 
Top 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloudTop 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloud
Rogue Wave Software
 
Cloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation inCloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation in
RahulBhole12
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
LinkedIn
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
Jurriaan Persyn
 
Real-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and HadoopReal-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and Hadoop
Rogue Wave Software
 
Redis Labcamp
Redis LabcampRedis Labcamp
Redis Labcamp
Angelo Simone Scotto
 
Infrastructure Around Hadoop
Infrastructure Around HadoopInfrastructure Around Hadoop
Infrastructure Around Hadoop
DataWorks Summit
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
Ricard Clau
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Ofer Zelig
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
Richard Schneeman
 
Writing Scalable Software in Java
Writing Scalable Software in JavaWriting Scalable Software in Java
Writing Scalable Software in Java
Ruben Badaró
 
Big Data Developers Moscow Meetup 1 - sql on hadoop
Big Data Developers Moscow Meetup 1  - sql on hadoopBig Data Developers Moscow Meetup 1  - sql on hadoop
Big Data Developers Moscow Meetup 1 - sql on hadoop
bddmoscow
 
Introduction to Data Science NoSQL.pptx
Introduction to Data Science  NoSQL.pptxIntroduction to Data Science  NoSQL.pptx
Introduction to Data Science NoSQL.pptx
tarakesh7199
 
Top 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloudTop 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloud
Rogue Wave Software
 
Cloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation inCloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation in
RahulBhole12
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
LinkedIn
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
Jurriaan Persyn
 
Real-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and HadoopReal-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and Hadoop
Rogue Wave Software
 
Infrastructure Around Hadoop
Infrastructure Around HadoopInfrastructure Around Hadoop
Infrastructure Around Hadoop
DataWorks Summit
 
Ad

More from Eberhard Wolff (20)

Architectures and Alternatives
Architectures and AlternativesArchitectures and Alternatives
Architectures and Alternatives
Eberhard Wolff
 
Beyond Microservices
Beyond MicroservicesBeyond Microservices
Beyond Microservices
Eberhard Wolff
 
The Frontiers of Continuous Delivery
The Frontiers of Continuous DeliveryThe Frontiers of Continuous Delivery
The Frontiers of Continuous Delivery
Eberhard Wolff
 
Four Times Microservices - REST, Kubernetes, UI Integration, Async
Four Times Microservices - REST, Kubernetes, UI Integration, AsyncFour Times Microservices - REST, Kubernetes, UI Integration, Async
Four Times Microservices - REST, Kubernetes, UI Integration, Async
Eberhard Wolff
 
Microservices - not just with Java
Microservices - not just with JavaMicroservices - not just with Java
Microservices - not just with Java
Eberhard Wolff
 
Deployment - Done Right!
Deployment - Done Right!Deployment - Done Right!
Deployment - Done Right!
Eberhard Wolff
 
Data Architecture not Just for Microservices
Data Architecture not Just for MicroservicesData Architecture not Just for Microservices
Data Architecture not Just for Microservices
Eberhard Wolff
 
How to Split Your System into Microservices
How to Split Your System into MicroservicesHow to Split Your System into Microservices
How to Split Your System into Microservices
Eberhard Wolff
 
Microservices and Self-contained System to Scale Agile
Microservices and Self-contained System to Scale AgileMicroservices and Self-contained System to Scale Agile
Microservices and Self-contained System to Scale Agile
Eberhard Wolff
 
How Small Can Java Microservices Be?
How Small Can Java Microservices Be?How Small Can Java Microservices Be?
How Small Can Java Microservices Be?
Eberhard Wolff
 
Data Architecturen Not Just for Microservices
Data Architecturen Not Just for MicroservicesData Architecturen Not Just for Microservices
Data Architecturen Not Just for Microservices
Eberhard Wolff
 
Microservices: Redundancy=Maintainability
Microservices: Redundancy=MaintainabilityMicroservices: Redundancy=Maintainability
Microservices: Redundancy=Maintainability
Eberhard Wolff
 
Self-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to MicroservicesSelf-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to Microservices
Eberhard Wolff
 
Microservices Technology Stack
Microservices Technology StackMicroservices Technology Stack
Microservices Technology Stack
Eberhard Wolff
 
Software Architecture for Innovation
Software Architecture for InnovationSoftware Architecture for Innovation
Software Architecture for Innovation
Eberhard Wolff
 
Five (easy?) Steps Towards Continuous Delivery
Five (easy?) Steps Towards Continuous DeliveryFive (easy?) Steps Towards Continuous Delivery
Five (easy?) Steps Towards Continuous Delivery
Eberhard Wolff
 
Nanoservices and Microservices with Java
Nanoservices and Microservices with JavaNanoservices and Microservices with Java
Nanoservices and Microservices with Java
Eberhard Wolff
 
Microservices: Architecture to Support Agile
Microservices: Architecture to Support AgileMicroservices: Architecture to Support Agile
Microservices: Architecture to Support Agile
Eberhard Wolff
 
Microservices: Architecture to scale Agile
Microservices: Architecture to scale AgileMicroservices: Architecture to scale Agile
Microservices: Architecture to scale Agile
Eberhard Wolff
 
Microservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Microservices, DevOps, Continuous Delivery – More Than Three BuzzwordsMicroservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Microservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Eberhard Wolff
 
Architectures and Alternatives
Architectures and AlternativesArchitectures and Alternatives
Architectures and Alternatives
Eberhard Wolff
 
The Frontiers of Continuous Delivery
The Frontiers of Continuous DeliveryThe Frontiers of Continuous Delivery
The Frontiers of Continuous Delivery
Eberhard Wolff
 
Four Times Microservices - REST, Kubernetes, UI Integration, Async
Four Times Microservices - REST, Kubernetes, UI Integration, AsyncFour Times Microservices - REST, Kubernetes, UI Integration, Async
Four Times Microservices - REST, Kubernetes, UI Integration, Async
Eberhard Wolff
 
Microservices - not just with Java
Microservices - not just with JavaMicroservices - not just with Java
Microservices - not just with Java
Eberhard Wolff
 
Deployment - Done Right!
Deployment - Done Right!Deployment - Done Right!
Deployment - Done Right!
Eberhard Wolff
 
Data Architecture not Just for Microservices
Data Architecture not Just for MicroservicesData Architecture not Just for Microservices
Data Architecture not Just for Microservices
Eberhard Wolff
 
How to Split Your System into Microservices
How to Split Your System into MicroservicesHow to Split Your System into Microservices
How to Split Your System into Microservices
Eberhard Wolff
 
Microservices and Self-contained System to Scale Agile
Microservices and Self-contained System to Scale AgileMicroservices and Self-contained System to Scale Agile
Microservices and Self-contained System to Scale Agile
Eberhard Wolff
 
How Small Can Java Microservices Be?
How Small Can Java Microservices Be?How Small Can Java Microservices Be?
How Small Can Java Microservices Be?
Eberhard Wolff
 
Data Architecturen Not Just for Microservices
Data Architecturen Not Just for MicroservicesData Architecturen Not Just for Microservices
Data Architecturen Not Just for Microservices
Eberhard Wolff
 
Microservices: Redundancy=Maintainability
Microservices: Redundancy=MaintainabilityMicroservices: Redundancy=Maintainability
Microservices: Redundancy=Maintainability
Eberhard Wolff
 
Self-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to MicroservicesSelf-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to Microservices
Eberhard Wolff
 
Microservices Technology Stack
Microservices Technology StackMicroservices Technology Stack
Microservices Technology Stack
Eberhard Wolff
 
Software Architecture for Innovation
Software Architecture for InnovationSoftware Architecture for Innovation
Software Architecture for Innovation
Eberhard Wolff
 
Five (easy?) Steps Towards Continuous Delivery
Five (easy?) Steps Towards Continuous DeliveryFive (easy?) Steps Towards Continuous Delivery
Five (easy?) Steps Towards Continuous Delivery
Eberhard Wolff
 
Nanoservices and Microservices with Java
Nanoservices and Microservices with JavaNanoservices and Microservices with Java
Nanoservices and Microservices with Java
Eberhard Wolff
 
Microservices: Architecture to Support Agile
Microservices: Architecture to Support AgileMicroservices: Architecture to Support Agile
Microservices: Architecture to Support Agile
Eberhard Wolff
 
Microservices: Architecture to scale Agile
Microservices: Architecture to scale AgileMicroservices: Architecture to scale Agile
Microservices: Architecture to scale Agile
Eberhard Wolff
 
Microservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Microservices, DevOps, Continuous Delivery – More Than Three BuzzwordsMicroservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Microservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Eberhard Wolff
 

Redis - The Universal NoSQL Tool

  • 1. Redis: The Universal NoSQL- Tool Eberhard Wolff Architecture and Technology Manager adesso AG
  • 4. Redis •  Remote Dictionary Server •  Advanced Key Value Store •  Actually also a cache and a messaging server •  Open Source – free to change the code •  Sponsored by VMware •  No commercial agenda •  Implemented in C (actually pretty small) •  In memory (fast)
  • 5. Redis •  Data should fit in memory •  Data written asynchronously to disk or in an append only file –  Won't slow down operations –  Configurable delay •  Bindings for many languages •  Very easy replication •  i.e. like an in-memory cache with persistence option •  http://redis.io/
  • 7. How to Use Redis •  Very simple protocol •  Can telnet to it •  Libraries for lots of languages •  Java: –  Jedis –  JRedis –  RJC •  Spring Data Redis as abstraction –  Uniform concepts (e.g. templates) across all NoSQL and SQL stores –  Even JPA –  Exception translation –  Still exposes unique features
  • 8. Use Case: High Scores for Players •  Online game •  Store high scores •  High data volume •  Frequently changing data
  • 9. Use Case: High Scores for Players •  Note: Other data (name, email, etc) can still be stored somewhere else •  Key: Name of player •  Value: Score •  Encoded as bytes •  Operations: GET, SET, DEL
  • 10. Demo: RedisWriter / RedisMultiWriter / RedisClean / redis-cli / telnet / redis- benchmark
  • 11. Points to Note •  Extremely fast •  See http://redis.io/topics/benchmarks •  Multi Set: Can issue multiple set operations in one round trip for very high performance •  Data in database does not impact performance •  Data written asynchronously •  Not shown: –  APPEND : append data to a key –  KEYS : find all keys for a pattern –  RENAME : Change key
  • 12. Redis as a Cache •  Data kept in memory •  …and on disk •  Data survives restarts •  No need for the cache to warm up •  But: What about evicting data from the cache? •  Solution: Data can have time-to-live •  Can set global memory policy to avoid excessive memory consumption •  Let assume certain texts (e.g. HTML) should be cached for our application…
  • 14. Create Unique Player ID •  Each player should have a unique ID •  Needs to be unique, even in a cluster •  Solution: atomic incr operation •  i.e. works correctly even if multiple threads access the counter at the same time •  Quick – in memory
  • 16. Similar operations •  GETSET : Atomically get old value and set to new value •  Global locks using SETNX / DEL •  SETNX returns true only if the client successfully set the value •  i.e. lock was successfully acquired
  • 17. Replication •  Redis uses master / slave replication •  Slaves can replicate to other slaves •  Replication does not block the master •  Useable for scalability of reads or data redundancy •  Write would go to the master and be propagated •  Make backups quite easy •  Just add slaveof <ip> <port> to redis.conf
  • 18. Scaling •  Slaves can be used for (eventually consistent) reads •  Storage to disk can be offloaded to slaves •  No more breaks during disk writes •  But: Only one master can write •  Still: All data should fit in RAM
  • 19. Scaling •  Can use Virtual Memory •  Redis has its own Virtual Memory implementation (to be deprecated) •  Partially implemented: Redis Cluster with Master / Slave replication •  Sharding i.e. data distributed across many nodes •  Could implement your own sharding on the client
  • 20. Redis Data Types •  So far: Simple types: byte[] –  String and numbers encoded as byte[] –  Can cluster multiple get/set into one atomic action •  Atomic increment / decrement for integers •  Lists –  Can add / remove atomically •  Sets –  Like lists but no order •  Sorted sets –  Each element has a score to sort by
  • 21. Highscores •  Range the high scores •  Solutions: Use a sorted set •  Result: scores automatically sorted •  Trivial to get the top high scores
  • 23. Sending EMails •  EMails should be sent by a server •  Need to queue emails •  Solution: Use a list + push / pop
  • 24. Demo: RedisEMailReaderList / RedisEMailWriterList
  • 25. Next step: Messaging •  Lists are not really designed for communication •  Message driven middleware is an established concept •  Redis has some parts •  Topics –  Have a name –  Multiple receivers can listen to it •  Subscribe to –  A Topic –  Or a patterns of topic names
  • 27. Transactions •  Multiple actions can be put into a transaction •  Command MULTI to start transaction •  EXEC to execute •  DISCARD to discard •  Guarantees: –  Executed in the defined order –  Atomic (all or nothing) –  No isolation –  Can use optimistic locking
  • 28. Key-Value Stores: Store Complex Data •  Storing data as serialized blobs / JSON / XML –  ”player:wolff" è ”all the data" •  Storing data as multiple keys –  "player:wolff:score" è 42 –  "player:wolff:email" è ”[email protected]" •  Requires multi get/set to be efficient •  Can find all keys using patterns •  Can create your custom Serializer in Spring Data •  Key / values stores are no really useful for complex data
  • 29. Conclusion – Redis is a Swiss Knife •  Very fast - In Memory •  Cache + persistence •  Messaging •  Centralized locking and counting •  Much more than just persistence •  Not shown: Lua scripting •  Not useful for –  Big Data –  Seamless scaling –  Ad hoc queries •  Will not be the only data store you use
  • 30. Links •  http://redis.io/ •  Try it yourself: http://try.redis-db.com/ •  Spring Data Redis http://www.springsource.org/spring-data/redis •  Demos: https://github.com/ewolff/spring-redis-demo •  Who is using it? http://redis.io/topics/whos-using-redis •  Books –  Tiago Macedo, Fred Oliveira: Redis Cookbook –  Pollack, Gierke, Risberg, Brisbin, Hunger: Spring Data