Why You May Need a NoSQL Database Even if You Aren't Google or Facebook
1. Perchè potresti avere bisogno di un database NoSQL anche se non sei Google o Facebook Luca Garulli
2. The graph db for the Enterprise & Web www.orientechnologies.com
3. Why do I could need something different than a Relational DBMS ? www.orientechnologies.com
4. (1) RDBMSs have more than 30 years Information Technology is not properly the same of '70 ... www.orientechnologies.com
5. (2) In the Web age applications could have Thousands or Millions of users Are you ready for this? www.orientechnologies.com
6. (3) Time-to-Market measured not anymore in years/man but days/weeks for a demo and months for the final www.orientechnologies.com
7. (4) Applications are more “ social” with much more relationships - tabular data and + interconnected Graphs www.orientechnologies.com
8. (5) Who believe yet to the bullshit that performance problems can be resolved just by scaling with the hardware? www.orientechnologies.com
9. (6) We use new stuff everyday HTTP , REST , Javascript & JSON How can I use them in better way without conversions & mapping? www.orientechnologies.com
10. (7) Modern applications are mostly I/O Bound not CPU bound. Often the DB Is the bottleneck of all www.orientechnologies.com
14. www.orientechnologies.com Non exhaustive list of NoSQL products: AllegroGraph, Amazon SimpleDB, Amazon Dynamo, Dynomite, BerkleyDB, Google BigTable, Cassandra, CouchDB, DB4O, Hbase, Hipertable, Hive, Jackrabbit, InfiniteGraph, InfoGrid, Memcached, MemcacheDB, Mnesia, M/DB/DT.M, MongoDB, Neo4J, OrientDB , Pig, Project Voldemort, RavenDB, Redis, Riak, Scalaris, Sesame, Sones, Terrastore, Tokyo Cabinet/Tyrant, Yahoo! Pnuts/Sherpa
15. www.orientechnologies.com The “NoSQL container” groups so very-very-very different products, no standard, difficult to choice, difficult to learn them
16. www.orientechnologies.com Can I have a Fast, scalable, flexible storage with transactions , SQL and security easy to use and maintain?
25. Schema- less schema is not mandatory, relaxed model , collect heterogeneous documents all together www.orientechnologies.com
26. Schema- full schema with constraints on fields and validation rules Customer.age > 17 Customer.address not null Customer.surname is mandatory Customer.email matches '[A-Z0-9._%+-]+@[A-Z0-9.-]+[A-Z]{2,4}' www.orientechnologies.com
27. Schema- mixed schema with mandatory and optional fields + constraints the best of schema-less and schema-full modes www.orientechnologies.com
28. ACID Transactions db.begin(); try{ // your code ... db.commit(); } catch( Exception e ) { db.rollback(); } www.orientechnologies.com
29. Complex types native support for collections : ['cool','fast'] maps (key/value): { 'age', 33 } and embedded documents no more additional tables to handle them www.orientechnologies.com
30. Relationships are direct links no Relational JOINS to connect multiple tables Load trees and graphs in few ms ! www.orientechnologies.com
34. www.orientechnologies.com For the most of the queries everyday a programmer needs SQL is simpler, more readable and compact then Scripting (Map/Reduce)
35. www.orientechnologies.com SELECT SUM(price) as prices, SUM(cost) as costs, prices-costs, margin/price FROM Balance VS function (key, values) { var price = 0.0, cost = 0.0, margin = 0.0, marginPercent = 0.0; for (var i = 0; i < values.length; i++) { price += values[i].price; cost += values[i].cost; } margin = price - cost; marginPercent = margin / price; return { price: price, cost: cost, margin: margin, marginPercent: marginPercent }; }
36. For Relational skilled Developers (everyone of us?) using OrientDB is easy www.orientechnologies.com
37. Asynchronous Query invoke callback when a record matches the condition doesn't collect the result set perfect for immediate results useful to compute aggregates www.orientechnologies.com
38. Language bindings Java as native JRuby , Scala and Javascript ready C , C++ , Ruby , Node.js in progress www.orientechnologies.com
39. Your language is not supported (yet)? Write an adapter using the C, Java or HTTP binding www.orientechnologies.com
40. HTTP RESTful firewall friendly use it from the web browser use it from the ESB (SOA) www.orientechnologies.com
42. Import/Export uses JSON format online operations (don't stop the database) www.orientechnologies.com
43. MVRB+Tr e e index the best of B+Tree and RB-Tree fast on browsing, low insertion cost It's a new algorithm (soon public) www.orientechnologies.com
44. www.orientechnologies.com OO Inheritance Definition of Classes of documents Classes can extend others classes Queries are polymorphics Contact name : string surname : string Customer orders : List<Order> Provider products : List<Product>
45. Hooks similar to triggers catch events against records , database and transactions implement custom cascade deletion algorithm enforce constraints www.orientechnologies.com
46. Fetch plans Choose what to fetch on query and document loading Documents not fetched will be lazy-loaded on request Invoice 3:100 | | customer +---------> Customer | 5:233 | city country +---------> City ---------> Country | 11:2 12:3 | orders +--------->* [ OrderItem OrderItem OrderItem ] [ 8:12 8:19 8:23 ] www.orientechnologies.com
47. Security users and roles , encrypted passwords fine grain privileges www.orientechnologies.com
54. Document Database the base of all DB implementations documents have dynamic structure something like a smart Map<String,Object> or a record with dynamic fields www.orientechnologies.com
61. Use hooks (triggers) public class HookTest extends ORecordHookAbstract { public saveProfile(){ ODatabaseObjectTx database = new ODatabaseObjectTx("remote:localhost/demo"); database.open("writer", "writer"); database.registerHook(this); ... } @Override public void onRecordAfterCreate(ORecord<?> iRecord){ System.out.println("Record created successfully"); } } www.orientechnologies.com
62. Object Database wrapper on top of Document Database binds POJO from/to the database no OR-Mapping complexity no enhancement, no Java Proxies www.orientechnologies.com
63. POJO mapping Uses the reflection to bind POJO fields at start-up caches reflection meta-data 1-to-1 binding configurable options by @annotations www.orientechnologies.com
65. Polymorphics SQL Query List<Person> result = database.query( new OSQLSynchQuery("select from person where city.name = 'Rome'")); for( Person p : result ) { if( p instanceof Customer ) System.out.println("Customer: " + p.getName() + “ “ + p.getSurname() ); } www.orientechnologies.com Queries are polymorphics and subclasses of Person can be part of result set
66. Graph Database wrapper on top of Document Database Few simple concepts: Vertex , Edge , Property and Index www.orientechnologies.com
67. TinkerPop Blueprints http://tinkerpop.com Standard de-facto to interact with GraphDBs implements transactional and indexable property graph model with bidirectional edges www.orientechnologies.com
68. TinkerPop Blueprints Available implementations: OrientDB Neo4J, Sail (RDF storage) Under development: InfiniteGraph, DEX, Redis www.orientechnologies.com
69. GraphDB & Blueprints API OrientGraph graph = new OrientGraph("local:/tmp/db/graph”); Vertex actor = graph.addVertex(null); actor.setProperty("name", "Leonardo"); actor.setProperty("surname", "Di Caprio"); Vertex movie = graph.addVertex(null); movie.setProperty("name", "Inception"); Edge edge = graph.addEdge(null, actor, movie, "StarredIn"); graph.shutdown(); www.orientechnologies.com
70. TinkerPop scripting language easy to learn and understand Used for operations against graphs www.orientechnologies.com
72. Load graph Run the console, open the database and load a graph in xml format marko:~/software/gremlin$ ./gremlin.sh ,,/ (o o) -----oOOo-(_)-oOOo----- gremlin> $_g := orientdb:open('/tmp/graph/test') ==>orientgraph[/tmp/graph/test] gremlin> g:load('data/graph-example-1.xml') ==>true gremlin> $_g ==>orientgraph[/tmp/graph/test] www.orientechnologies.com
73. Search Displays outgoing edges of vertices with name equals to 'marko', then the name of inbound vertices gremlin> g:key-v('name','marko')/outE ==>e[6:0][5:2-knows->5:1] ==>e[6:1][5:2-knows->5:4] ==>e[6:4][5:2-created->5:0] gremlin> g:key-v('name','marko')/outE/inV/@name ==>vadas ==>josh ==>lop gremlin> g:close() ==>true www.orientechnologies.com
74. API resume object, key/value and graph elements all work on top of Document you can always access to the underlying document changes to the document are reflected to the object, key/value and graph elements and viceversa www.orientechnologies.com
75. Enhanced SQL SQL is not enough for collections, maps, trees and graphs need to enhance SQL syntax Easy syntax derived from JDO/JPA standards www.orientechnologies.com
76. SQL & relationships select from Account where address .city.country.name = 'Italy' select from Account where addresses contains ( city.country.name = 'Italy') www.orientechnologies.com
77. SQL & trees/graphs select from Profile where friends traverse(0,7) ( sex = 'female' ) (Soon new specific operators for trees and graphs) www.orientechnologies.com
78. SQL & strings select from Profile where name .toUpperCase() = 'LUCA' select from City where country.name .substring(1,3).toUpperCase() = 'TAL' select from Agenda where phones contains ( number .indexOf( '+39' ) > -1 ) select from Agenda where email matches 'A-Z0-9._%+-?+@A-Z0-9.-?+A-Z?{2,4}' www.orientechnologies.com
79. SQL & conversions select from Shapes where area .toFloat() > 3.14 select from Agenda where birthDate .toDateTime() > '1976-10-26 07:00:00' select from Workflow where completed .toBoolean() = true www.orientechnologies.com
80. SQL & schema-less select from Profile where any() like '%Jay%' select from Stock where all() is not null www.orientechnologies.com
81. SQL & collections select from Tree where children contains ( married = true ) select from Tree where children containsAll ( married = true ) select from User where roles containsKey 'shutdown' select from Profile where tags in 'cool' select from Graph where edges .size() > 0 www.orientechnologies.com
82. SQL & documents select from Vehicle where @class = 'Car' select from Friend where @version > 100 select from File where @size > 1000000 www.orientechnologies.com
83. High-Availability Cluster of distributed server nodes Synchronous, Asynchronous and Read-Only Replication Load-balancing between client ↔ servers and Servers ↔ Servers www.orientechnologies.com
85. Always Free Open Source Apache 2 license free for any purposes, even commercials www.orientechnologies.com
86. Prof €$$ ional $ € rvic €$ by a network of companies through Orient Technologies support, training, consulting, mentoring www.orientechnologies.com
87. www.orientechnologies.com OrientDB for Java developers 8 hours OrientDB Master Development 14 hours OrientDB for SOA 6 hours OrientDB and the power of graphs 6 hours OrientDB for DBA 6 hours OrientPlanet for Web Developers 6 hours
88. Certification Program to be part of the network do courses share revenues for support work as consultant www.orientechnologies.com Contact commercial @orientechnologies.com
92. Luca Garulli Author of OrientDB and Roma <Meta> Framework Open Source projects, Member of JSR#12 (jdo 1.0) and JSR#243 (jdo 2.0) CTO at Asset Data and Orient Technologies Technical Manager at Romulus consortium www.orientechnologies.com www.twitter.com/ lgarulli @Rome, Italy