39
Introduction to Datomic Siva Jagadeesan

Introduction to datomic

  • Upload
    sivajag

  • View
    158

  • Download
    0

Embed Size (px)

DESCRIPTION

Simple introduction to Datomic

Citation preview

Page 1: Introduction to datomic

Introduction to Datomic

Siva Jagadeesan

Page 2: Introduction to datomic

“there’s an another database!”

• what do you think of first?

Page 3: Introduction to datomic

The job of a database

•Coordination •Consistency •Indexing •Storage •Queries

Page 4: Introduction to datomic

The traditional world

Page 5: Introduction to datomic

• Place-oriented-programming (PLOP)

• designed decades ago

• tiny RAM, tiny disks

• Collocated components

• Difficult to scale

• Necessitates application-level sharding

The dreaded update-in-place

Page 6: Introduction to datomic

sharding

• lose

• consistency

• transactions

• queries

Page 7: Introduction to datomic

key-value stores

• lose

• querying

• really just storage systems

• not “databases”

Page 8: Introduction to datomic

Deconstruction

• relocate subsystems

• separate services each do one thing

• simplification

Page 9: Introduction to datomic

Datomic architecture

• Peers

• Transactors

• Storage services

Page 10: Introduction to datomic

The new world

Page 11: Introduction to datomic

Benefits

• Separating reads and writes

• applications only read from storage

• transactor

• handles transactions

• provides consistency

• reflects changes to peers

Page 12: Introduction to datomic

Benefits

• Integrated data distribution

• built-in in-memory caches

• self-tunes to working set

• automatic

Page 13: Introduction to datomic

Benefits

• Peers each have a query engine

• Datalog

• simple rules and data patterns

• declarative: implicit joins

• declarative: meaning is evident

• locality: datomic db and app data

Page 14: Introduction to datomic

Benefits

• Elasticity

• as elastic as peers

Page 15: Introduction to datomic

Benefits

• Cloud ready

• commodity hardware

• resilient to failures

Page 16: Introduction to datomic

Data model

• Immutable data

• remember everything

• things don’t actually “change”

• audit everything

• automatic

Page 17: Introduction to datomic

Data model

• Facts-oriented (vs. PLOP)

• Atomic Data

• datoms

• entity, attribute, value, transaction

• Not embedded into strucures

Page 18: Introduction to datomic

Data model

• Minimal Schema

• at the datom level

• directly supports cardinality

• avoid rigidity

• even other “schema-free” documents impose their structure into apps

• Hickey: “nothing pivots like a datom”

Page 19: Introduction to datomic

Programming model

• Peer embedded in your application

• Pulls indexes or data segments as needed

• Caches locally, gets updates from transactor

Page 20: Introduction to datomic

Programming model

• No strings-based query language

• Data-structure-driven

• Lists and maps

• Easy to generate and test

Page 21: Introduction to datomic

Programming model

• Transactional

• Totally ordered

• First class: peers get a queue of all transactions

• Can use them in queries

• Facilitates event-driven triggers without polling

• Annotated transactions

Page 22: Introduction to datomic

Programming model

• Datalog

• deductive query system

• facts = datomic db

• can also include other app data

• extensible through custom functions that queries can use

Page 23: Introduction to datomic

Programming model

• Consistent

• without impeding other threads or peers

• reads/queries without transactions

• through immutability

• db as a value

Page 24: Introduction to datomic

Programming model

• Time

• as-of queries

• windowed queries

Page 25: Introduction to datomic

The so-what

• Simplicity

• consistency

• built-in caching

• no manual sharding

• configuration-free

• cloud-scale

Page 26: Introduction to datomic

The so-what

• Evolvability

• datom-level schema

• application free to change “structural” thinking

Page 27: Introduction to datomic

The so-what

• Local query power

• each peer has full query engine

• the db is effectively local

• isolation from others:

• e.g. - analytics usage won’t bog down transaction processing

Page 28: Introduction to datomic

The so-what

• Multiple storage choices

• in-memory for developing, unit-testing

• RDBMS backend possible (behind firewall, etc)

• Distributed storage services for redundancy and unlimited read scaling

• backup/restore tools available

Page 29: Introduction to datomic

The so-what

• Integrated mem-cache support

• local caches can be backed by OTS mem-cache cluster

• datomic is a “good citizen” user

Page 30: Introduction to datomic

The so-what

• Leverage datalog against multiple sources

• datomic db

• application data

Page 31: Introduction to datomic

The so-what

• Travel through time

• audits

• bug-resolution

Page 32: Introduction to datomic

Schema def

{:db/id {:part :db.part/db, :idx -1000001}, :db/ident :user/login, :db/valueType :db.type/string, :db/cardinality :db.cardinality/one, :db/fulltext true, :db/doc "the login handle of a user", :db.install/_attribute :db.part/db}

Page 33: Introduction to datomic

Schema def

{:db/id {:part :db.part/db, :idx -1000003}, :db/ident :user/friends, :db/valueType :db.type/ref, :db/cardinality :db.cardinality/many, :db/fulltext false, :db/doc "the friends of a user", :db.install/_attribute :db.part/db}

Page 34: Introduction to datomic

transactions

[:db/add entity-id attribute value]

[:db/retract entity-id attribute value]

{:db/id entity-id! attribute value! attribute value! ... }

[:db.fn/retractEntity entity-id]

Page 35: Introduction to datomic

identities

{:part :db.part/user, :idx -1000026}

{:db/id 17592186045420}

Page 36: Introduction to datomic

queries

[:find ?e :in $ ?email !:where ![?e :person/email ?email]]

[:find variables :where clauses]

[:find ?e ?x !:where ![?e :age 42] [?e :likes ?x]]

Page 37: Introduction to datomic

queries

• lots more

• pattern matching

• logic programming

• multiple data-sources

Page 38: Introduction to datomic

demonic

• datomic helper

• work at the data-structure level

• supports graphs: nested maps

• only writes dirty data

• “demarcations” as “batched datomic transactions”

• unit-testing support

Page 39: Introduction to datomic

Questions