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

Datomic Spotlight

Datomic Spotlight

Amitay Horwitz

August 24, 2017
Tweet

More Decks by Amitay Horwitz

Other Decks in Programming

Transcript

  1. ABOUT DATOMIC • Developed by Cognitect • Initial release 2012

    • Designed by Rich Hickey (author of the Clojure programming language) • Used by Facebook, Netflix, more…
  2. FACTS • “Abraham Lincoln is the president of the United

    States” • “Abraham Lincoln was elected president of the United States on March 4, 1861”
  3. FACTS • Abraham Lincoln • Position • President • March

    4, 1861 Entity Attribute Value Timestamp
  4. FACT = DATOM Entity Attribute Value Tx Operation 1033 :first-name

    "Abraham" 260 add 1033 :last-name "Lincoln" 260 add 1033 :position "Lawyer" 277 add
  5. 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
  6. 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
  7. A DATABASE • A collection of datoms • At a

    specific point in time • An immutable value
  8. 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
  9. 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
  10. DATALOG • Equivalent to relational model + recursion • Declarative,

    expressive and powerful • Pattern matching style • No more string concatenation!
  11. 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]
  12. 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]
  13. Entity Attribute Value 42 :email [email protected] 43 :email [email protected] 42

    :orders 107 42 :orders 141 “What attributes does 42 have?” [42 ?attribute]
  14. 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]
  15. 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”
  16. Peer library Your app cache PEER LIBRARY Transactor Storage •

    Reads data from storage • Caches locally
  17. Peer library Your app cache Peer library Your app cache

    Peer library Your app cache SCALE HORIZONTALLY Transactor Storage
  18. Transactor TRANSACTOR Transactor Storage Peer library Your app • Standalone

    service • Scales vertically • Hot standby for failover
  19. Transactor TRANSACTOR Storage Peer library Your app • Coordinates writes

    • Guarantees ACID transactions (isolation level “serializable”)
  20. Peer library Your app cache Peer library Your app cache

    Peer library Your app cache Storage Transactor TRANSACTOR • Broadcasts live updates
  21. DISTRIBUTED STORAGE ☁ Transactor Storage Peer library Your app •

    DynamoDB • Riak • CouchBase • Cassandra • …
  22. Peer library Your app cache Peer library Your app cache

    Peer library Your app cache SHARED MEMCACHED Transactor Storage Memcached
  23. EVENT SOURCING? • Datomic is lower level - facts vs

    events • Annotate transactions! • Querying already built in • Listen on transaction queue to build reactive systems
  24. Q&A

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