Slide 1

Slide 1 text

DGRAPH-ORM Not everything can fit in rows and columns By Ashok Vishwakarma

Slide 2

Slide 2 text

WHO AM I? Naukri.com AVP - Engineering Google Developer Expert (GDE) Web Technologies & Angular Ashok Vishwakarma @avishwakarma @_avishwakarma

Slide 3

Slide 3 text

THE RDBMS PROBLEM What RDBMS forces you to do? ● Maintain a strict schema ○ If you modify a column from string to float you have to do manual table migration. ● Data duplication to avoid slow joins ○ The same information is kept in multiple tables, to avoid joins. ● Pre-compute counts for foreign tables ○ To allow efficient sorting of data.

Slide 4

Slide 4 text

NOSQL IS NOT A SOLUTION It’s a way out not a way in ● It kills the valuable relationship between data ○ Storing everything into a single document is not possible all the time. ● Data duplication is still there ○ We are force to put the same data in multiple documents ● ACID, Security and etc.

Slide 5

Slide 5 text

THE SOLUTION A Graph Database. How it helps? ● Flexible sparse schema with real-time modifiable data types ○ Change predicate type from string to float without migration. ● No data duplication ○ Any join is single lookup. ● Counts are cheap in real time ○ Any sort can be perform on these counts efficiently.

Slide 6

Slide 6 text

WHO USES GRAPH DATABASES? ● Google - NoEdgeGraph ● Facebook - FacebookTau ● Twitter - FlockDB ● Dropbox, Pinterest, Linkedin and etc have their own versions of graph layers Any company doing anything smart is using Graph Databases

Slide 7

Slide 7 text

SO LET’S MOVE TO GRAPH DATABASE ● Single server or on top of other databases ○ Existing graphs either single server like Neo4j or they are hastily put together on other databases like Cayley, titanDB or DSCGraph. ● No standard ○ Companies have to built their graph systems. FcabeookTau, NoEdgeGraph FlockDB and etc. Wait! There are some problems with existing Graph Database solutions

Slide 8

Slide 8 text

INTRODUCING DGRAPH An Open Source Graph Database written in Go ● Fast - Built like a search engine ● Sharded and Distributed with distributed joins, filters and sort ● Horizontally Scalable with consistent replication using Raft ● Highly available by design ● Fault-tolerant ● GraphQL+- Dgraph Query Language

Slide 9

Slide 9 text

DGRAPH VS NEO4J & CAYLEY - BENCHMARK Neo4j ● 100x faster data loading ● 3x to 6x faster in querying data Cayley ● 9.7x faster data loading ● 5x to 36x faster in querying data

Slide 10

Slide 10 text

MYTHS Should we really using Graph Database? ● Are they an overkill? ○ I might have to run some traversals should I use graphs or its an overkill. ● Are they robust? ○ Do I need to run a primary datastore so this graph database does not lose my data. ● Are they scalable? ○ I have to run lot of queries, can graph database achieve the performance and scale.

Slide 11

Slide 11 text

MYTHS Should we really using Graph Database? ● Are they an overkill? ○ No! You should use a graph database they are not an overkill. ● Are they robust? ○ Yes! They can act like a primary datastore. ● Are they scalable? ○ Yes! They will scale, in fact Dgraph with sharded and distributed architecture scale better than mysql database stuck on a single server.

Slide 12

Slide 12 text

DGRAPH-ORM dgraph-orm - Why we need an ORM? ● Dgraph uses GraphQL+- for it’s query language. ○ GraphQL is fine but that +- is tricky and require learning. ● We love Mongoose and Sequelize ○ Using similar ORM is easy to get started. ● Object based schema ○ Dgraph’s schema is string based

Slide 13

Slide 13 text

user.name: string @index(term) . ... user.friend uid @count @reverse . // User.js import {Schema, model, Types} from 'dgraph-orm'; const UserSchema = new Schema('user', { name: { type: Types.STRING, index: true, token: { term: true } }, ... friends: { type: Types.UID, model: 'user', count: true, reverse: true } }); const User = model('user', UserSchema);

Slide 14

Slide 14 text

import User from './user'; // Creating user const users = await User.create({ email: '[email protected]', password: '$ecureP@ssw0rd' }); // Querying users const users = await User.has('email', { filter: { email: '[email protected]' } }); # creating user { set { _:u1 '[email protected]' . _:u1 '$ecureP@ssw0rd' . } } # querying users { users(func: has(user.email)) @filter(eq(user.email, '[email protected]')) { uid email: user.email } } More Examples https://github.com/ashokvishwakarma/dgraph-orm

Slide 15

Slide 15 text

Live Demo

Slide 16

Slide 16 text

DGRAPH-ORM NPM https://www.npmjs.com/package/dgraph-orm GITHUB https://github.com/ashokvishwakarma/dgraph-orm Where can you find it?

Slide 17

Slide 17 text

QUESTIONS? { ? }