Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Immutable data...base?

Immutable data...base?

These are the slides for a talk I gave on the 6th of February at RubyFuza 2014.

Robert Stuttaford

February 06, 2014
Tweet

More Decks by Robert Stuttaford

Other Decks in Programming

Transcript

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

    View Slide

  2. Clojure

    View Slide

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

    View Slide

  4. Lithp ... er, Lisp

    View Slide

  5. 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

    View Slide

  6. Define and call functions

    View Slide

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

    View Slide

  8. This is what
    mutable state
    feels like, now!

    View Slide

  9. Clojure’s collections

    View Slide

  10. 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

    View Slide

  11. Datomic

    View Slide

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

    View Slide

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

    View Slide

  14. Transactor

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

    View Slide

  15. 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

    View Slide

  16. 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

    View Slide

  17. 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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  21. 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!

    View Slide

  22. 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”]

    View Slide

  23. 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!

    View Slide

  24. Let’s see some
    code already!

    View Slide

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

    View Slide

  26. 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

    View Slide