SlideShare a Scribd company logo
1 of 25
Download to read offline
SQL or NoSQL?
Lars Thorup, Zealake
September, 2016
Lars Thorup
● Software developer/architect
● JavaScript, C#
● Test Driven Development
● Coach
● Agile engineering practices
● Founder
● BestBrains
● Zealake
● Triggerz
● @larsthorup
Agenda
● My history with databases
● Databases - what are they good for?
● SQL and noSQL - what is the difference?
● Redis - a noSQL database
● Matching use cases to database systems
● Redis - datastructures and algorithms
My history with databases
● Databases
● Pre 1980 - many competing database models
● 1980-2010 - SQL dominates
● 2010-now - many competing noSQL database
models
● Myself
● 1990-2016 - SQL for administrative systems,
documents, e-commerce, music, collaboration
tools, data analytics
● 2015 - Redis and Neo4J for social media
Databases - what are they good for?
● Make data available
● Across the globe
● From multiple computers
● Across long time spans
● Prevent data loss
● Quickly search for, fetch data and update data
● Ensure consistency in data
Example database systems
● SQL
● Relational: SQL Server, PostgreSQL, Oracle
● NoSQL
● Key-value: DynamoDB, Berkeley DB, S3
● Document: MongoDB, RethinkDB
● Data structure: Redis
● Graph: Neo4J
● Columns: Cassandra, HBase
Example database use cases
● Banks: accounts, owners, transactions
● Social media: posts, comments, ratings
● Caching: user sessions, generated pages
● Sales analytics: counts, sums, locations, averages,
hierarchies
SQL and noSQL - what is the difference?
● What kind of data do we store?
● How many machines do we use?
● Will there be type checking?
● Will we have to code the lookup algorithms?
● How do we prevent incosistent data?
Typical SQL database
● Many small tables with lots of columns
● Single instance on a large server
● Explicit column types, referential constraints
● Advanced and efficient standard query language
● Transactions over complex updates
Typical NoSQL database
● Collections of JSON documents
● Cluster of servers with shards and replicas
● Application may handle evolving document structures
● Specific low-level query language
● Single-update transactions
Categorizing a database system
SQL NoSQL
Impedance mismatch
Distribution
Schema
Query engine
tables and columns
server
explicit
optimizing manual
implicit
cluster
documents
Redis - one NoSQL database
SQL NoSQL
Impedance mismatch
Distribution
Schema
Query engine
tables and columns
server
explicit
optimizing manual
implicit
cluster
documents
Redis
Redis
● REmote DIctionary Server, started in 2009
● Popular, fast, robust
● In-memory
● Single-threaded
● Many data types
● dictionaries, lists, sets, sorted sets
● Other features
● key expiry
● publish - subscribe
Redis demo
● string values (session count)
● dictionary values (session)
● list values (lucene index queue)
● sorted list values (front page posts)
● expiry (session)
● http://redis.io/topics/data-types-intro
Demo: string values
● Example: Global objects
incr 'session:id'
set 'session:42' '{"name":"lars", "level": 5}'
get 'session:42'
Demo: dictionary values
● Example: Session object
hset 'session:42' info '{"name":"lars"}'
hset 'session:42' level "5"
hgetall 'session:42'
hincrby 'session:42' level 1
hget 'session:42' level
Demo: list values
● Example: lucene indexing queue
rpush 'index:lucene' "42"
rpush 'index:lucene' "105"
rpush 'index:lucene' "7"
lrange 'index:lucene' 0 -1
lpop 'index:lucene'
Demo: sorted list values
● Example: front page posts
zadd 'post:score' 17 "42"
zadd 'post:score' 39 "43"
zadd 'post:score' 22 "44"
zincrby 'post:score' 1 "42"
zrevrange 'post:score' 0 -1
zrevrank 'post:score' "42"
Demo: expiry
● Example: session
set 'session:42' '{"name":"lars", "level": 5}'
expire 'session:42' 20
ttl 'session:42'
get 'session:42'
Demo: simple transactions
● Example: maintaining indexes
multi
set 'session:42' '{"name":"lars", "level": 5}'
hset 'session:by:name' "lars" "42"
expire 'session:42' 20
exec
Demo: not so simple transactions
● Example: doing updates
watch 'session:42'
get 'session:42'
multi
set 'session:42' '{"name":"lars", "level": 7}'
exec
Redis demo questions
Redis - one NoSQL database
SQL NoSQL
Impedance mismatch
Distribution
Schema
Query engine
tables and columns
server
explicit
optimizing manual
implicit
cluster
documents
Redis
Trade-off: coding effort
● SQL
● Distribution: sharding and
clustering
● Impedance mismatch: Object-
relational mapping
● Explicit schema: fixed, declared
up-front, requires migrations
● NoSQL
● Manual query optimization
● Difficult transactional safety
● Implicit and dynamic schema
migrations
Questions!

More Related Content

What's hot

Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project Experiences
Henrik Olsson
 
Building Quality with Foundations of Mud
Building Quality with Foundations of MudBuilding Quality with Foundations of Mud
Building Quality with Foundations of Mud
seleniumconf
 

What's hot (20)

Сергей Больщиков "Angular Components: все уже за, а вы еще нет?"
Сергей Больщиков "Angular Components: все уже за, а вы еще нет?"Сергей Больщиков "Angular Components: все уже за, а вы еще нет?"
Сергей Больщиков "Angular Components: все уже за, а вы еще нет?"
 
"Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
 "Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii... "Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
"Real-time Collaborative Text Editing on Grammarly’s Front-End Team" Oleksii...
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
 
Javascript
JavascriptJavascript
Javascript
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
Type script
Type scriptType script
Type script
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
 
Arquillian & Citrus
Arquillian & CitrusArquillian & Citrus
Arquillian & Citrus
 
Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project Experiences
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Parallel run selenium tests in a good way
Parallel run selenium tests in a good  wayParallel run selenium tests in a good  way
Parallel run selenium tests in a good way
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Building Quality with Foundations of Mud
Building Quality with Foundations of MudBuilding Quality with Foundations of Mud
Building Quality with Foundations of Mud
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 

Similar to SQL or NoSQL - how to choose

Overview of no sql
Overview of no sqlOverview of no sql
Overview of no sql
Sean Murphy
 

Similar to SQL or NoSQL - how to choose (20)

No sql bigdata and postgresql
No sql bigdata and postgresqlNo sql bigdata and postgresql
No sql bigdata and postgresql
 
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
 
Sql vs NO-SQL database differences explained
Sql vs NO-SQL database differences explainedSql vs NO-SQL database differences explained
Sql vs NO-SQL database differences explained
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
 
the rising no sql technology
the rising no sql technologythe rising no sql technology
the rising no sql technology
 
Datastore PPT.pptx
Datastore PPT.pptxDatastore PPT.pptx
Datastore PPT.pptx
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
 
2018 05 08_biological_databases_no_sql
2018 05 08_biological_databases_no_sql2018 05 08_biological_databases_no_sql
2018 05 08_biological_databases_no_sql
 
NoSQL
NoSQLNoSQL
NoSQL
 
First steps to Azure Cosmos DB: Getting Started with MongoDB and NoSQL
First steps to Azure Cosmos DB: Getting Started with MongoDB and NoSQLFirst steps to Azure Cosmos DB: Getting Started with MongoDB and NoSQL
First steps to Azure Cosmos DB: Getting Started with MongoDB and NoSQL
 
Say Yes To No SQL
Say Yes To No SQLSay Yes To No SQL
Say Yes To No SQL
 
PostgreSQL and MySQL
PostgreSQL and MySQLPostgreSQL and MySQL
PostgreSQL and MySQL
 
Javascript on Server-Side
Javascript on Server-SideJavascript on Server-Side
Javascript on Server-Side
 
Overview of no sql
Overview of no sqlOverview of no sql
Overview of no sql
 
What’s new in SQL Server 2017
What’s new in SQL Server 2017What’s new in SQL Server 2017
What’s new in SQL Server 2017
 
Nashville analytics summit aug9 no sql mike king dell v1.5
Nashville analytics summit aug9 no sql mike king dell v1.5Nashville analytics summit aug9 no sql mike king dell v1.5
Nashville analytics summit aug9 no sql mike king dell v1.5
 
NoSQL
NoSQLNoSQL
NoSQL
 
UNIT-2.pptx
UNIT-2.pptxUNIT-2.pptx
UNIT-2.pptx
 
Resident good: NoSQL
Resident good: NoSQLResident good: NoSQL
Resident good: NoSQL
 
NoSQL
NoSQLNoSQL
NoSQL
 

More from Lars Thorup

Javascript unit testing with QUnit and Sinon
Javascript unit testing with QUnit and SinonJavascript unit testing with QUnit and Sinon
Javascript unit testing with QUnit and Sinon
Lars Thorup
 

More from Lars Thorup (19)

100 tests per second - 40 releases per week
100 tests per second - 40 releases per week100 tests per second - 40 releases per week
100 tests per second - 40 releases per week
 
Super fast end-to-end-tests
Super fast end-to-end-testsSuper fast end-to-end-tests
Super fast end-to-end-tests
 
Extreme Programming - to the next-level
Extreme Programming - to the next-levelExtreme Programming - to the next-level
Extreme Programming - to the next-level
 
Advanced Javascript Unit Testing
Advanced Javascript Unit TestingAdvanced Javascript Unit Testing
Advanced Javascript Unit Testing
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy code
 
Advanced QUnit - Front-End JavaScript Unit Testing
Advanced QUnit - Front-End JavaScript Unit TestingAdvanced QUnit - Front-End JavaScript Unit Testing
Advanced QUnit - Front-End JavaScript Unit Testing
 
Put "fast" back in "fast feedback"
Put "fast" back in "fast feedback"Put "fast" back in "fast feedback"
Put "fast" back in "fast feedback"
 
Database Schema Evolution
Database Schema EvolutionDatabase Schema Evolution
Database Schema Evolution
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
 
Javascript unit testing with QUnit and Sinon
Javascript unit testing with QUnit and SinonJavascript unit testing with QUnit and Sinon
Javascript unit testing with QUnit and Sinon
 
Continuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScriptContinuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScript
 
Automated Performance Testing
Automated Performance TestingAutomated Performance Testing
Automated Performance Testing
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Agile Contracts
Agile ContractsAgile Contracts
Agile Contracts
 
High Performance Software Engineering Teams
High Performance Software Engineering TeamsHigh Performance Software Engineering Teams
High Performance Software Engineering Teams
 
Elephant Carpaccio
Elephant CarpaccioElephant Carpaccio
Elephant Carpaccio
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++
 
Unit Testing in JavaScript with MVC and QUnit
Unit Testing in JavaScript with MVC and QUnitUnit Testing in JavaScript with MVC and QUnit
Unit Testing in JavaScript with MVC and QUnit
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Recently uploaded (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

SQL or NoSQL - how to choose

  • 1. SQL or NoSQL? Lars Thorup, Zealake September, 2016
  • 2. Lars Thorup ● Software developer/architect ● JavaScript, C# ● Test Driven Development ● Coach ● Agile engineering practices ● Founder ● BestBrains ● Zealake ● Triggerz ● @larsthorup
  • 3. Agenda ● My history with databases ● Databases - what are they good for? ● SQL and noSQL - what is the difference? ● Redis - a noSQL database ● Matching use cases to database systems ● Redis - datastructures and algorithms
  • 4. My history with databases ● Databases ● Pre 1980 - many competing database models ● 1980-2010 - SQL dominates ● 2010-now - many competing noSQL database models ● Myself ● 1990-2016 - SQL for administrative systems, documents, e-commerce, music, collaboration tools, data analytics ● 2015 - Redis and Neo4J for social media
  • 5. Databases - what are they good for? ● Make data available ● Across the globe ● From multiple computers ● Across long time spans ● Prevent data loss ● Quickly search for, fetch data and update data ● Ensure consistency in data
  • 6. Example database systems ● SQL ● Relational: SQL Server, PostgreSQL, Oracle ● NoSQL ● Key-value: DynamoDB, Berkeley DB, S3 ● Document: MongoDB, RethinkDB ● Data structure: Redis ● Graph: Neo4J ● Columns: Cassandra, HBase
  • 7. Example database use cases ● Banks: accounts, owners, transactions ● Social media: posts, comments, ratings ● Caching: user sessions, generated pages ● Sales analytics: counts, sums, locations, averages, hierarchies
  • 8. SQL and noSQL - what is the difference? ● What kind of data do we store? ● How many machines do we use? ● Will there be type checking? ● Will we have to code the lookup algorithms? ● How do we prevent incosistent data?
  • 9. Typical SQL database ● Many small tables with lots of columns ● Single instance on a large server ● Explicit column types, referential constraints ● Advanced and efficient standard query language ● Transactions over complex updates
  • 10. Typical NoSQL database ● Collections of JSON documents ● Cluster of servers with shards and replicas ● Application may handle evolving document structures ● Specific low-level query language ● Single-update transactions
  • 11. Categorizing a database system SQL NoSQL Impedance mismatch Distribution Schema Query engine tables and columns server explicit optimizing manual implicit cluster documents
  • 12. Redis - one NoSQL database SQL NoSQL Impedance mismatch Distribution Schema Query engine tables and columns server explicit optimizing manual implicit cluster documents Redis
  • 13. Redis ● REmote DIctionary Server, started in 2009 ● Popular, fast, robust ● In-memory ● Single-threaded ● Many data types ● dictionaries, lists, sets, sorted sets ● Other features ● key expiry ● publish - subscribe
  • 14. Redis demo ● string values (session count) ● dictionary values (session) ● list values (lucene index queue) ● sorted list values (front page posts) ● expiry (session) ● http://redis.io/topics/data-types-intro
  • 15. Demo: string values ● Example: Global objects incr 'session:id' set 'session:42' '{"name":"lars", "level": 5}' get 'session:42'
  • 16. Demo: dictionary values ● Example: Session object hset 'session:42' info '{"name":"lars"}' hset 'session:42' level "5" hgetall 'session:42' hincrby 'session:42' level 1 hget 'session:42' level
  • 17. Demo: list values ● Example: lucene indexing queue rpush 'index:lucene' "42" rpush 'index:lucene' "105" rpush 'index:lucene' "7" lrange 'index:lucene' 0 -1 lpop 'index:lucene'
  • 18. Demo: sorted list values ● Example: front page posts zadd 'post:score' 17 "42" zadd 'post:score' 39 "43" zadd 'post:score' 22 "44" zincrby 'post:score' 1 "42" zrevrange 'post:score' 0 -1 zrevrank 'post:score' "42"
  • 19. Demo: expiry ● Example: session set 'session:42' '{"name":"lars", "level": 5}' expire 'session:42' 20 ttl 'session:42' get 'session:42'
  • 20. Demo: simple transactions ● Example: maintaining indexes multi set 'session:42' '{"name":"lars", "level": 5}' hset 'session:by:name' "lars" "42" expire 'session:42' 20 exec
  • 21. Demo: not so simple transactions ● Example: doing updates watch 'session:42' get 'session:42' multi set 'session:42' '{"name":"lars", "level": 7}' exec
  • 23. Redis - one NoSQL database SQL NoSQL Impedance mismatch Distribution Schema Query engine tables and columns server explicit optimizing manual implicit cluster documents Redis
  • 24. Trade-off: coding effort ● SQL ● Distribution: sharding and clustering ● Impedance mismatch: Object- relational mapping ● Explicit schema: fixed, declared up-front, requires migrations ● NoSQL ● Manual query optimization ● Difficult transactional safety ● Implicit and dynamic schema migrations