Deconstructing the Database Rich Hickey Most programs are outside - - PowerPoint PPT Presentation

deconstructing the database
SMART_READER_LITE
LIVE PREVIEW

Deconstructing the Database Rich Hickey Most programs are outside - - PowerPoint PPT Presentation

Deconstructing the Database Rich Hickey Most programs are outside the bounds of and single process we write in any single FP language What is Datomic? A new database A sound model of information, with time Provides database as a


slide-1
SLIDE 1

Deconstructing the Database

Rich Hickey

Most programs are outside the bounds of and single process we write in any single FP language

slide-2
SLIDE 2

What is Datomic?

  • A new database
  • A sound model of information, with time
  • Provides database as a value to applications
  • Bring declarative programming to applications
  • Focus on reducing complexity

Not going to do a full rationalization or overview Focus on information important for Datomic, not necessarily for all use of dbs/stores

slide-3
SLIDE 3

DB Complexity

  • Stateful
  • Same query, different results
  • no basis
  • Over there
  • ‘Update’ poorly defined
  • Places

Inherent complexity in state

slide-4
SLIDE 4

Update

  • What does update mean?
  • Does the new replace the old?
  • Granularity? new ___ replace the old ___
  • Visibility?

Granularity and replacement the big issues

slide-5
SLIDE 5

Manifestations

  • Wrong programs
  • Scaling problems
  • Round-trip fears
  • Fear of overloading server
  • Coupling, e.g. questions with reporting

read committed vs repeatable, serializable

slide-6
SLIDE 6

Consistency and Scale

  • What’s possible?
  • Distributed redundancy and consistency?
  • Elasticity
  • Inconsistency huge source of complexity

dynamo and bigtable

slide-7
SLIDE 7

Information and Time

  • Old-school memory and records
  • The kind you remember

... and keep

  • Auditing and more
slide-8
SLIDE 8

Perception and Reaction

  • No polling
  • Consistent
slide-9
SLIDE 9

Coming to Terms

Value

  • An immutable

magnitude, quantity, number... or immutable composite thereof

Identity

  • A putative entity we

associate with a series of causally related values (states) over time

State

  • Value of an identity at a

moment in time

Time

  • Relative before/after
  • rdering of causal values
slide-10
SLIDE 10

v1 F v2 F v3 F v4

Process events (pure functions) Observers/perception/memory

States (immutable values)

Identity (succession of states)

Epochal Time Model

slide-11
SLIDE 11

Implementing Values

  • Persistent data structures
  • Trees
  • Structural sharing
slide-12
SLIDE 12

Structural Sharing

Past Next

slide-13
SLIDE 13

Process events (pure functions) Observers/perception/memory Identity (succession of states)

Place Model

DB Connection Transactions Queries

The Database Place

F F F

We should recognize - same problems as OO Conflates identity and value, collapses time

slide-14
SLIDE 14

v1 F v2 F v3 F v4

Process events (pure functions) Observers/perception/memory

States (immutable values)

Identity (succession of states)

Epochal Time Model

DB Connection Transactions DB Values Queries

This is what we want - transactions are functions of db values queries as well

slide-15
SLIDE 15

Traditional Database

cache Server Indexing Trans- actions Query App Process I/O App ORM? Caching policy? Strings DDL + DML Result Sets Serialized ??? Serialized ??? Disk

what’s makes up a database? cache over DB access, disk locality was important

slide-16
SLIDE 16

The Choices

  • Coordination
  • how much, and where?
  • process requires it
  • perception shouldn’t
  • Immutability
  • sine qua non

coordinate up front or later immutability advantages with eventually consistent systems

slide-17
SLIDE 17

Approach

  • Move to information model
  • Split process and perception
  • Immutable basis in storage
  • Novelty in memory
slide-18
SLIDE 18

Information

  • Inform
  • ‘to convey knowledge via facts’
  • ‘give shape to (the mind)’
  • Information
  • the facts
slide-19
SLIDE 19
  • Fact - ‘an event or thing known to have

happened or existed’

  • From: factum - ‘something done’
  • Must include time
  • Remove structure (a la RDF)
  • Atomic Datom
  • Entity/Attribute/Value/Transaction(time)

Facts

don’t get more flexibility by trading tables for documents factum - “something done”

slide-20
SLIDE 20

Database State

  • The database as an expanding value
  • An accretion of facts
  • The past doesn’t change - immutable
  • Process requires new space
  • Fundamental move away from places

What is the state - snapshot of a referential model?

slide-21
SLIDE 21

Accretion

  • Root per transaction doesn’t work
  • Latest values include past as well
  • The past is sub-range
  • Important for information model

can we just do shared structure from before on disk?

slide-22
SLIDE 22

Process

  • Reified
  • Primitive representation of novelty
  • Assertions and retractions of facts
  • Minimal
  • Other transformations expand into those

Important to accretion that novelty representation is minimal

slide-23
SLIDE 23

Deconstruction

  • Process
  • Transactions
  • Indexing
  • O
  • Perception/Reaction
  • Query
  • Indexes
  • I

Server Indexing Trans- actions Query I/O Disk

slide-24
SLIDE 24

State

  • Must be organized to support query
  • Sorted set of facts
  • Maintaining sort live in storage - bad
  • BigTable - mem + storage merge
  • occasional merge into storage
  • persistent trees

Databases are about leverage

slide-25
SLIDE 25

Indexing

  • Maintaining sort live in storage - bad
  • BigTable et al:
  • Accumulate novelty in memory
  • Current view: mem + storage merge
  • Occasional integrate mem into storage

Releases memory

slide-26
SLIDE 26

Transactions and Indexing

Index Merging Trans- actions Log Data Segments Live Index Index Data Segments Storage Novelty

slide-27
SLIDE 27

Perception

Live Index Storage Index Data Segments Novelty

Just a merge join. Any coordination required? Contention? How does live index get updated? Live vs periodic now separate decision

slide-28
SLIDE 28

Components

  • Transactor
  • Peers
  • Your app servers, analytics machines etc
  • Redundant storage service

Physical architecture

slide-29
SLIDE 29

Datomic Architecture

App Server Process Peer Lib Query Cache App Live Index Comm App Server Process Peer Lib Query Cache App Live Index Comm Transactor Indexing Trans- actions App Server Process Peer Lib Query Cache App Live Index Comm Transactor Indexing Trans- actions Data Segments Data Segments Redundant segment storage Storage Service Segment storage memcached cluster (optional) standby

But, storage now remote, slow? No - cache everywhere

slide-30
SLIDE 30

Transactor

  • Accepts transactions
  • Expands, applies, logs, broadcasts
  • Periodic indexing, in background
  • Indexing creates garbage
  • Storage GC
slide-31
SLIDE 31

Peer Servers

  • Peers directly access storage service
  • Have own query engine
  • Have live mem index and merging
  • Two-tier cache
  • Datoms w/object values (on heap)
  • Segments (memcached)
slide-32
SLIDE 32

Consistency and Scale

  • Process/writes go through transactor
  • traditional server scaling/availability
  • Immutability supports consistent reads
  • without transactions
  • Query scales with peers
  • Elastic/dynamic e.g. auto-scaling

consistency as in db satisfies consistency predicate loopholes 7 and 10?

slide-33
SLIDE 33

Memory Index

  • Persistent sorted set
  • Large internal nodes
  • Pluggable comparators
  • 2 sorts always maintained
  • EAVT, AEVT
  • plus AVET,

VAET

slide-34
SLIDE 34

Storage

  • Log of tx asserts/retracts (in tree)
  • Various covering indexes (trees)
  • Storage service/server requirements
  • Data segment values (K->V)
  • atoms (consistent read)
  • pods (conditional put)
slide-35
SLIDE 35

Structural Sharing

Past Next

slide-36
SLIDE 36

What’s in a DB Value?

EAVT t VeAET AEVT db atom nextT asOfT Lucene index history live Lucene sinceT index db value live Storage Hierarchical Cache Roots Memory index (live window) Storage-backed index

Identity Value

Value can be lazily loaded, since source immutable

slide-37
SLIDE 37

Index in Storage

Sorted Datoms Index Root

  • f key->dir

T 42 VeAET AEVT AVET Lucene EAVT dirs segs Index ref

Identity Value

slide-38
SLIDE 38

Datomic on Riak

+ ZooKeeper

  • Riak

redundant, distributed, highly available durable eventually consistent

  • ZooKeeper

redundant, durable, consistent (ordered ops + CAS)

slide-39
SLIDE 39

Datomic on Riak

+ ZooKeeper

Riak ZooKeeper

Index ref Log ref Catalog ref Coord ref

Identities Values

pointer swap mentioned by Eric Brewer this morning

slide-40
SLIDE 40

Riak Usage

  • Everything put into Riak is immutable
  • N=3, W=2, DW=2
  • R=1, not-found-ok = false

‘first found’ semantics

  • There or not

no vector clocks, siblings etc

  • No speculative lookup

What notion of consistency? Application-level predicate

slide-41
SLIDE 41

Transactor Indexing Trans- actions App Process App Process Peer App Server Process Peer Lib Query Cache App Live Index Comm Transactor Indexing Trans- actions Data Segments Redundant segment storage Storage Server/Service Segment storage Peer Service Peer Service Peer REST Server Query Cache REST Server Live Index Comm App Process App Process Client App Process (any language) App REST Client Data Segments memcached cluster (optional) HTTP + Server-Sent Events Standby

Full Datomic Stack

slide-42
SLIDE 42

Stable Bases

  • Same query, same results
  • db permalinks!
  • communicable, recoverable
  • Multiple conversations about same value

//Peer Database db = connection.db().asOf(1000); Peer.q(aQuery, db); //Client GET /data/mem/test/1000/datoms?index=aevt

basis

Value of values

slide-43
SLIDE 43

DB Values

  • Time travel
  • db.asOf - past
  • db.since - windowed
  • db.with(tx) - speculative
  • dbs are arguments to query, not implicit
  • mock with datom-shaped data:

[[:fred :likes "Pizza"] [:sally :likes "Ice cream"]]

slide-44
SLIDE 44

DB Simplicity Benefits

  • Epochal state
  • Coordination only for process
  • Transactions well defined
  • Functional accretion
  • Freedom to relocate/scale storage, query
  • Extensive caching
  • Process events
slide-45
SLIDE 45

The Database as a Value

  • Dramatically less complex
  • More powerful
  • More scalable
  • Better information model
slide-46
SLIDE 46

Thanks for Listening!