Slide 1

Slide 1 text

ROBERT STUTTAFORD CTO, COGNICIAN Notes: http://is.gd/imm_db #rubyfuza Immutable data…base?

Slide 2

Slide 2 text

Clojure

Slide 3

Slide 3 text

Lisp Functional Immutable Dynamic Java & JS VMs OSS, 7 years old

Slide 4

Slide 4 text

Lithp ... er, Lisp

Slide 5

Slide 5 text

Functions are the unit of composition Created, stored, passed around for use by higher order functions, e.g. reduce. ! Prefer to use pure functions Those with no side-effects or I/O. Easier to reason about, test, and compose. Functional programming

Slide 6

Slide 6 text

Define and call functions

Slide 7

Slide 7 text

Immutable, persistent data structures Once defined, can’t change ‘under’ you. Changes create copies. Copies share structure internally. Far, FAR easier to reason about!

Slide 8

Slide 8 text

This is what mutable state feels like, now!

Slide 9

Slide 9 text

Clojure’s collections

Slide 10

Slide 10 text

Prefer to pass unadorned data through mostly pure functions, ! rather than creating typed instances and mutating in place via methods. ! Then, both the data and the logic are easier to compose and test! TL;DR

Slide 11

Slide 11 text

Datomic

Slide 12

Slide 12 text

Datomic is a database of  flexible, time-based facts, supporting queries and joins, with elastic scalability, and ACID transactions.

Slide 13

Slide 13 text

JVM, has REST API Closed source :-( Proprietary Paid licenses Free editions :-) Datomic

Slide 14

Slide 14 text

Transactor
 Only 1 process Datomic’s architecture Consistent writes to storage Indexing Reads only while transacting

Slide 15

Slide 15 text

Storage Datomic’s architecture Consistent writes to storage Indexing Reads only while transacting Abstracted, can use any of:
 Internal: In memory, on disk with transactor
 External: SQL, Riak, DynamoDB, and more Transactor
 Only 1 process

Slide 16

Slide 16 text

Storage Peer Up to 30 procs Abstracted, can use any of:
 Internal: In memory, on disk with transactor
 External: SQL, Riak, DynamoDB, and more Reads from storage Inside your JVM app’s process Transparently cache from storage
 in local memory to satisfy reads Datomic’s architecture Consistent writes to storage Indexing Reads only while transacting Transactor
 Only 1 process

Slide 17

Slide 17 text

Storage Query 1-64 peers Datomic’s architecture Memcached 2nd tier cache Peers look here before storage (paid licenses only) Paid licenses support high-availability transactor failover. Transactor
 Only 1 process

Slide 18

Slide 18 text

Datomic’s data model [entity attr value] ! ! Entities have attributes with values. Each EAV combination is a ‘datom’. Entities typically have many datoms.

Slide 19

Slide 19 text

Datomic’s data model [entity attr value] ! [123 :name “Robert”] [123 :likes “coffee”]

Slide 20

Slide 20 text

Datomic’s data model [entity attr value tx] ! ! But what about time?

Slide 21

Slide 21 text

Datomic’s data model [entity attr value tx] ! [123 :name “Robert” 456] [123 :likes “coffee” 456] [456 :tx-timestamp “2014-02-06”] Each datom refers to the transaction that created it. Transactions are also entities!

Slide 22

Slide 22 text

Datomic’s data model [entity attr value tx] ! [123 :likes “coffee” 456] [456 :timestamp “2014-02-06”] [123 :likes “beer” 789] [789 :timestamp “2014-02-07”]

Slide 23

Slide 23 text

Datomic’s data model Schema defines only how attribute’s values behave. ! Required: Name, data type, cardinality (one or many). Optional: indexed, unique, and more. ! Datomic does not proscribe how you combine attributes on entities!

Slide 24

Slide 24 text

Let’s see some  code already!

Slide 25

Slide 25 text

We are hiring! Pure Clojure, ClojureScript & Datomic Experience with other stacks OK! ! [email protected] @RobStuttaford

Slide 26

Slide 26 text

Cape Town Clojure User Group Meet 1 or 2 Thursday evenings a month Next meet: 6-9pm,14 February 2014 Venue: Codebridge in Claremont @clj_ug_ct ! Talk notes: http://is.gd/imm_db