Polyglot Persistence
Otávio Santana
@otaviojava
otaviojava@apache.org
NoSQL
● Database
● Doesn't use structure
● Not Transaction
● BASE
● Five different types
Key Value
● AmazonDynamo
● AmazonS3
● Redis
● Hazelcast
SunApollo
WarAres
LoveAphrodite Beaty
Column Family
● Hbase
● Cassandra
● Scylla
● Clouddata
● SimpleDb
● DynamoDB
Row-key Columns...
Apollo
Aphrodite
Ares
Sun
Duty
{Love, happy}
Duty
War
Duty
Sword
weapon
Color
Kratos
Dead Gods
13
Document
● ApacheCouchDB
● MongoDB
● Riak
● Couchbase
{
"name":"Diana",
"duty":[
"Hunt",
"Moon",
"Nature"
],
"siblings":{
"Apollo":"brother"
}
}
Graph
● Neo4j
● InfoGrid
● Sones
● HyperGraphDB
Apollo Ares
Kratoswas killed by was killed by
Is brother
killed killed
Multi-Model
● OrientDB (graph, document)
● Couchbase (key value,
document)
● Elasticsearch (document, graph)
● ArangoDB (column family,
graph, key-value)
SQL Key-value Column Document Graph
Table Bucket Column
Family
Collection
Row Key/value
pair
Column Document Vertex
Column Key/value
pair
Key/value pair Vertex and Edge
property
Relationship Link Edge
SQL vs NoSQL
BASE vs ACID
● Basically Available
● Soft state
● Eventual consistency
● Atomicity
● Consistency
● Isolation
● Durability
CAP
Scalability vs Complexity
S
c
a
l
a
b
i
l
i
t
y Complexity
key-value
Column
Document
Graph
KISS
● Avoid complexity
● Product First
● MVP
● Baby Step
Our database
is too slow and
not big enough!
We need
NoSql!
SQL
● know-who
● know-why
● General
SQL
● Explain
● Compose
● Index
● Model
Emulate
● ACID
● Replica
● Duplicate
Model
Validation
● Test
● Migration
● TTL
Diversity
● Types
● Unique
● Configuration
Slow
● Index
● Wildcard
Search Engine
● Analyzers
● Character filter
● Tokenizer
● Token filter
Search Engine
Character
filter
Tokenizer
Token
filter
Commandm
ents
1. Keep it simple
2. Don't follow the Hype
3. SQL still in shape
4. Understand NoSQL
5. Don't trust in Benchmarks
6. Never emulate
7. Models are differents
8. Improving tests
9. Diversity
10. Search Engine
JNoSQL
● Mapping API
● Communication API
● No lock-in
● Divide and conquer
DAO
Mapping
Communication
Document
Key
Column
Graph
DIANA
ARTEMIS
JNoSQL
Data Tier
Communication Issue
ODocument document = new
ODocument(“collection”);
document.field(name, value);
JsonObject jsonObject = JsonObject.create();
jsonObject.put(name, value);
BaseDocument baseDocument = new
BaseDocument();
baseDocument.addAttribute(name, value);
Document document = new Document();
document.append(name, value);
Communication Issue
ODocument document = new
ODocument(“collection”);
document.field(name, value);
JsonObject jsonObject = JsonObject.create();
jsonObject.put(name, value);
BaseDocument baseDocument = new
BaseDocument();
baseDocument.addAttribute(name, value);
Document document = new Document();
document.append(name, value);
Communication Issue
DocumentEntity entity =
DocumentEntity.of("documentCollection");
Document document = Document.of(name, value);
entity.add(document);
Diversity
ColumnEntity entity = ColumnEntity.of(COLUMN_FAMILY);
Column id = Column.of("id", 10L);
entity.add(id);
entity.add(Column.of("version", 0.001));
entity.add(Column.of("name", "Diana"));
entity.add(Column.of("options", Arrays.asList(1, 2, 3)));
//mutiple implementation
columnEntityManager.save(entity);
ColumnQuery query =
select().from(COLUMN_FAMILY).where("id").eq(10L).build();
Optional<ColumnEntity> result = columnEntityManager.singleResult(query);
//cassandra only
List<ColumnEntity> entities = columnEntityManagerCassandra
.cql("select * from newKeySpace.newColumnFamily where id=10;");
columnEntityManagerCassandra.insert(entity, ConsistencyLevel.ALL);
Thank you
Otávio Santana
@otaviojava
osantana@tomitribe.com
otaviojava@apache.org

Polyglot persistence