How to store data? It depends.
Juraj Sottnik
CONFIDENTIAL
What is the nature of data?
CONFIDENTIAL
CONFIDENTIAL
How big is your data?
CONFIDENTIAL
CONFIDENTIAL
What kind of data (business problem)?
CONFIDENTIAL
CONFIDENTIAL
When RDBMS
CONFIDENTIAL
CONFIDENTIAL
When NoSQL
CONFIDENTIAL
CONFIDENTIAL
NoSQL - Key value store
CONFIDENTIAL
CONFIDENTIAL
Memcached
Simple key and value. Server does not care what value looks like.
Simple key, numeric value.
set key1 value1
get key1
set key2 0
incr key2 1
CONFIDENTIAL
CONFIDENTIAL
Redis
Simple key, hash value type.
HSET key3 field1 "Hello"
HGET key3 field1
Simple key, list value type.
RPUSH key4 "hello"
RPUSH key4 "world"
LRANGE key4 0 -1
CONFIDENTIAL
CONFIDENTIAL
Redis
Simple key, set value type.
SADD key5 "Hello"
SMEMBERS key5
CONFIDENTIAL
CONFIDENTIAL
NoSQL - Document oriented store
CONFIDENTIAL
CONFIDENTIAL
MongoDB
CONFIDENTIAL
CONFIDENTIAL
MongoDB
Query based on nested properties
{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" }��db.inventory.find(� {� "size.h": {� $lt: 15� },� "size.uom": "in",� status: "D"� }�)
CONFIDENTIAL
CONFIDENTIAL
MongoDB
Aggregation Pipeline
db.transactions.aggregate([
{
$match: {
transactionDate: {
$gte: ISODate("2017-01-01T00:00:00.000Z"),
$lt: ISODate("2017-01-31T23:59:59.000Z")
}
}
}, {
$group: {
_id: null,
total: {
$sum: "$amount"
}
}
}
])
CONFIDENTIAL
CONFIDENTIAL
NoSQL - Column family storage
CONFIDENTIAL
CONFIDENTIAL
Apache Cassandra
CONFIDENTIAL
CONFIDENTIAL
NoSQL - Graph database
CONFIDENTIAL
CONFIDENTIAL
neo4j
MATCH (actor:Person)-[:ACTED_IN]->(movie:Movie)�WHERE movie.title STARTS WITH "T"�RETURN movie.title AS title, collect(actor.name) AS cast�ORDER BY title ASC LIMIT 10;
CONFIDENTIAL
CONFIDENTIAL
Mixed approach
JSON support in Postgres
'[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json->2
{"c":"baz"}
'{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'
3
You can upsert json documents with INSERT ON CONFLICT and jsonb_set.
CONFIDENTIAL
CONFIDENTIAL
Dummy Web Application
Users Sessions - Redis
Product Catalog - MongoDB
User events - MongoDB, Cassandra
Recommendations - neo4j
Analytics - MongoDB, Cassandra
Orders and payments - RDBMS
CONFIDENTIAL
CONFIDENTIAL
Summary
CONFIDENTIAL
CONFIDENTIAL