Post on 06-Jan-2017
NoSQL vs SQL
Who am I?Beseda DmitriyWeb developer at Binary Studio
email: BesedaDG@gmail.comemail: dmitriy.beseda@binary-studio.comskype: dmitriy.b_binaryfacebook: https://www.facebook.com/profile.php?id=100001784445579
Plan1.Data nowadays
2.SQL advantages / disadvantages
3.NoSQL advantages / disadvantages
4.NoSQL history
5.SQL and NoSQL similarities and differences
6.ORM / ODM
7.Myths
8.Conclusions
Problem
Main “Bottleneck”
Data evolution- Data and web apps are growing rapidly day by day
- Hardware cannot keep pace with data growth
- Apps are moving to Cloud and becoming API driven
Conclusion: It is hard to scale data in a traditional way
Data in businessBusiness is successful if data are used properly
- Statistic, reports
- Real-time
- Recommendations
Conclusion:
- Web apps should be real-time and interactive
- User and services databases grow from tera to peta bytes each day
Pay attention●CRUD (Create Read Update Delete) operations
- Performance
- Reliability
●Data consistency (ACID) & Distributed network- Parallel immediate access
- Updates applying time to all users
●Loading- Data replication
- Sharding
Advantages:
●No duplications
●Data integrity
●Transactions
●Actions sequence
●Security
●Data consistency
SQLDisadvantages:
●Performance
●Work in distributed environment (locks)
●Horizontal scaling complexity
●Additional language to manipulate with data
●Scaling and Sharding
SQL Products and customers
December, 2015
NoSQLAdvantages:
●Performance (aggregation)
●Schemaless (easy to add / remove properties)
●Horizontal scaling (& sharding)
●Way of using memory
●Open source
Disadvantages:
●Absence of transactions
●Embedding limitations
●Lots of manual work (joins are absent)
●Model format is not guaranteed
NoSQL products and customers
NoSQL historyIn 1998 Carlo Strozzi implemented an open source DB, that stored ASCII files and used shell scripts for data manipulations
In June 2009 Eric Evans proposed NoSQL as a Twitter #tag for a conference for existing distributed databases
- Consistency - “Is the data I am looking at now the same if I look at it somewhere else”
- Availability - “What will happen if my database goes down?”
- Partitioning - “What if my data is on a different node?”
SQL - CANoSQL - AP
CAP theorem (Consistency, Availability and Partition-tolerance)
SQL and NoSQL similarities●Primary key or Id is necessary and unique
●Indexes help to increase performance
●Relationships exist
Goals of normalization- Free the database of modification anomalies (references)
- Minimize redesign
- Avoid any bias toward any particular access pattern
SQL schema example
Schema design- Rich documents- Pre join / embed Data- No more joins- No constraints- Atomic operations- No declared schema
NoSQL types●Key Value (Firebase, Dynamo, Redis ...)
●Document (MongoDB, CouchDB)
●Graph (InfoGrid, Neo4J ...)
●Column Family (Cassandra, HyperTable, BigTable)
Data store positioning
SQL Comfort zone
Key Value
Column
Document
GraphRelational
Standardized Model, Tooling, Complexity
Sca
labi
lity
JSON- Array
var array = [ 1, 2, 3, 4, 5]
- Dictionaries
var doc = {
"prop1": "some string","prop2": { a: 2, b: 3},"prop3": array
}
NoSQL document example{
"_id": ObjectId,"description": String,"total": Number,"notes": [{
"_id": ObjectId,"text": String
}],"exclusions": [{
"_id": ObjectId,"text": String
}],"categories": {
"ref1": {"name": String,"status": String,"price": Number
},"ref2": {
"name": String,"status": String,"price": Number
}}
}
ORM and ODMORM:
●Entity Framework (.NET)
●Nhibernate (.NET)
●Hibernate (Java)
●Django (Python)
●Sequelize (JS)
ODM:
●Mongoose (Mongo)
Myths- NoSQL supersedes SQL
- NoSQL is better / worse than SQL
- SQL vs NoSQL is a clear distinction
- The language/framework determines the database
Use SQL if:●Data integrity is essential
●Standards-based proven technologies with good developer experience and support
●Logical related discrete data requirements which can be identified up-front
●Prefer SQL
Use NoSQL if:●Data requirements are unrelated, indeterminate or evolving
●Project objectives are simpler of less specific and allow starting to code immediately
●Speed and scalability is imperative
●Prefer NoSQL
Always remember● Если бы мы действительно ждали завершения каждой транзакции в мировой сети ATM (банкоматов),
транзакции занимали бы столько времени, что клиенты убегали бы прочь в ярости. Что происходит, если ты и твой партнер снимаете деньги одновременно и превышаете лимит? — Вы оба получите деньги, а мы поправим это позже.
● Мы вступаем в эру polyglot persistence — эру, когда для различных потребностей используются разные хранилища данных. Теперь нет монополизма реляционных баз данных, как безальтернативного источника данных. Все чаще архитекторы выбирают хранилище исходя из природы самих данных и того, как мы ими хотим манипулировать, какие объемы информации ожидаются. И поэтому все становится только интереснее.
● A well-designed SQL database will almost certainly perform better than a badly designed NoSQL equivalent and vice versa.
SummarySQL - works great, isn’t scalable for large data 😞NoSQL - works great, isn’t suitable for everyone 😞SQL + NoSQL 😊
References1.SQL vs NoSQL: The Differences
2.MongoDB university
Questions?