Slide 1

Slide 1 text

DATOMIC @amitayh THE FUNCTIONAL DATABASE

Slide 2

Slide 2 text

FULL DISCLOSURE ⚠

Slide 3

Slide 3 text

ABOUT DATOMIC • Developed by Cognitect • Initial release 2012 • Designed by Rich Hickey (author of the Clojure programming language) • Used by Facebook, Netflix, more…

Slide 4

Slide 4 text

FACTS ✅

Slide 5

Slide 5 text

FACTS • “Abraham Lincoln is the president of the United States”

Slide 6

Slide 6 text

FACTS • “Abraham Lincoln is the president of the United States” • “Abraham Lincoln was elected president of the United States on March 4, 1861”

Slide 7

Slide 7 text

FACTS • Abraham Lincoln • Position • President • March 4, 1861 Entity Attribute Value Timestamp

Slide 8

Slide 8 text

FACT = DATOM Entity Attribute Value Tx Operation

Slide 9

Slide 9 text

FACT = DATOM Entity Attribute Value Tx Operation 1033 :first-name "Abraham" 260 add 1033 :last-name "Lincoln" 260 add 1033 :position "Lawyer" 277 add

Slide 10

Slide 10 text

FACT = DATOM Entity Attribute Value Tx Operation 1033 :first-name "Abraham" 260 add 1033 :last-name "Lincoln" 260 add 1033 :position "Lawyer" 277 add 1033 :position "President" 522 add

Slide 11

Slide 11 text

FACT = DATOM Entity Attribute Value Tx Operation 1033 :first-name "Abraham" 260 add 1033 :last-name "Lincoln" 260 add 1033 :position "Lawyer" 277 add 1033 :position "President" 522 add 1033 :position "President" 881 retract

Slide 12

Slide 12 text

FACT BASED MODEL Facts Facts Facts Facts Facts Facts Facts Facts Time Facts Facts Time

Slide 13

Slide 13 text

GIT Facts Facts Facts Facts Objects Facts Facts Objects Time Facts Objects Time

Slide 14

Slide 14 text

A DATABASE • A collection of datoms • At a specific point in time • An immutable value

Slide 15

Slide 15 text

DATABASE AS A VALUE • Same as 42 is a value • Safe to share, easy to reason about • Functions that take a database as an argument, or return a database

Slide 16

Slide 16 text

TIME BUILT IN • Get the database value as of, or since, a point in time • See how the database would have looked like as if certain transactions took place • Reactive transaction reports

Slide 17

Slide 17 text

QUERIES

Slide 18

Slide 18 text

DATALOG • Equivalent to relational model + recursion • Declarative, expressive and powerful • Pattern matching style • No more string concatenation!

Slide 19

Slide 19 text

EXAMPLE DATABASE Entity Attribute Value 42 :email [email protected] 43 :email [email protected] 42 :orders 107 42 :orders 141

Slide 20

Slide 20 text

DATA PATTERN Constrains the results returned, binds variables: [?customer :email ?email] Attribute Value Entity

Slide 21

Slide 21 text

DATA PATTERN Constrains the results returned, binds variables: [?customer :email ?email] Constant Variable Variable

Slide 22

Slide 22 text

Entity Attribute Value 42 :email [email protected] 43 :email [email protected] 42 :orders 107 42 :orders 141 “Find all customers with emails” [?customer :email ?email]

Slide 23

Slide 23 text

Entity Attribute Value 42 :email [email protected] 43 :email [email protected] 42 :orders 107 42 :orders 141 “Find a particular customer’s email” [42 :email ?email]

Slide 24

Slide 24 text

Entity Attribute Value 42 :email [email protected] 43 :email [email protected] 42 :orders 107 42 :orders 141 “What attributes does 42 have?” [42 ?attribute]

Slide 25

Slide 25 text

Entity Attribute Value 42 :email [email protected] 43 :email [email protected] 42 :orders 107 42 :orders 141 “What attributes and values does 42 have?” [42 ?attribute ?value]

Slide 26

Slide 26 text

WHERE CLAUSE [:find ?customer
 :where [?customer :email]] Data pattern

Slide 27

Slide 27 text

FIND CLAUSE [:find ?customer
 :where [?customer :email]]

Slide 28

Slide 28 text

IMPLICIT JOIN [:find ?customer
 :where [?customer :email] [?customer :orders]] “Find all the customers who have placed orders”

Slide 29

Slide 29 text

PREDICATES [:find ?item
 :where [?item :item/price ?price] [(< 50 ?price)]] “Find the expensive items”

Slide 30

Slide 30 text

CALLING FUNCTIONS [:find ?customer ?product
 :where [?customer :ship-address ?addr] [?adde :zip ?zip] [?product :product/weight ?weight] [?product :product/price ?price] [(Shipping/estimate ?zip ?weight) ?ship-cost] [(<= ?price ?ship-cost)]] “Find me the customer/product combinations where the shipping cost dominates the product cost”

Slide 31

Slide 31 text

ARCHITECTURE

Slide 32

Slide 32 text

DATABASE ROLES • Queries • Transactions • Consistency • Storage

Slide 33

Slide 33 text

BREAK DOWN

Slide 34

Slide 34 text

DATOMIC COMPONENTS Peer library Transactor Storage

Slide 35

Slide 35 text

PEER LIBRARY Transactor Storage Peer library Your app • Embedded in your app • Executed queries locally

Slide 36

Slide 36 text

Peer library Your app cache PEER LIBRARY Transactor Storage • Reads data from storage • Caches locally

Slide 37

Slide 37 text

Peer library Your app cache Peer library Your app cache Peer library Your app cache SCALE HORIZONTALLY Transactor Storage

Slide 38

Slide 38 text

TRANSACTOR Transactor Storage Peer library Your app • Standalone service • Scales vertically

Slide 39

Slide 39 text

Transactor TRANSACTOR Transactor Storage Peer library Your app • Standalone service • Scales vertically • Hot standby for failover

Slide 40

Slide 40 text

Transactor TRANSACTOR Storage Peer library Your app • Coordinates writes • Guarantees ACID transactions (isolation level “serializable”)

Slide 41

Slide 41 text

Storage Transactor TRANSACTOR Peer library Your app • Writes transaction log to storage • Generates indices

Slide 42

Slide 42 text

Peer library Your app cache Peer library Your app cache Peer library Your app cache Storage Transactor TRANSACTOR • Broadcasts live updates

Slide 43

Slide 43 text

STORAGE Transactor Storage Peer library Your app • Provided as a service • Many different backends

Slide 44

Slide 44 text

LOCAL STORAGE Transactor Storage Peer library Your app • Memory • Filesystem • Great for testing!

Slide 45

Slide 45 text

NEARBY STORAGE Transactor Storage Peer library Your app • SQL database (any JDBC)

Slide 46

Slide 46 text

DISTRIBUTED STORAGE ☁ Transactor Storage Peer library Your app • DynamoDB • Riak • CouchBase • Cassandra • …

Slide 47

Slide 47 text

Peer library Your app cache Peer library Your app cache Peer library Your app cache SHARED MEMCACHED Transactor Storage Memcached

Slide 48

Slide 48 text

EVENT SOURCING? • Datomic is lower level - facts vs events • Annotate transactions! • Querying already built in • Listen on transaction queue to build reactive systems

Slide 49

Slide 49 text

Q&A

Slide 50

Slide 50 text

RESOURCES • http://www.datomic.com/ • Intro to Datomic by Rich Hickey -
 http://wix.to/b8CQABU • The Value of Values by Rich Hickey -
 http://wix.to/D8CRABU • Datomic Datalog - http://wix.to/cMCQABU