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

Lessons from 4 Years with Datomic

Lessons from 4 Years with Datomic

We’ll starting with a crash course on the Datomic data model, and then switch gears to talking about all sorts of data-modeling problems and their solutions.

Presented at ClojureRemote 2017, February 2017.
Recording: https://youtu.be/4BhZshZyf9E

Robert Stuttaford

December 29, 2017
Tweet

More Decks by Robert Stuttaford

Other Decks in Technology

Transcript

  1. Digital self-coaching, in the workplace Robert Stuttaford, CTO at Cognician

    Twitter: RobStuttaford Github: robert-stuttaford
  2. Clojure & ClojureScript since April 2012. Datomic since September 2012.

    In production since Jan 2013! Digital self-coaching, in the workplace
  3. Digital self-coaching, in the workplace 50,265,275 lovingly crafted, by-a-real-person transactions!

    Clojure & ClojureScript since April 2012. Datomic since September 2012. In production since Jan 2013!
  4. Before we dive in… some thanks: The Clojure community, for

    embodying the spirit of sharing and collaboration Rich set out when he started. Ryan and the CR17 team, for the opportunity to speak, and the excellent organisational work. All of you, for your time and attention. Thank you!
  5. And, a very special thank you to the Datomic team:

    Rich Hickey Stuart Halloway Tim Ewald Chris Redinger David Nolen Marshall Thompson Jaret Binford 
 (and alums Bobby Calderwood and Ben Kamphaus) No doubt many more. These folks have made our lives at Cognician a whole lot better. Thank you!
  6. On questions during this talk: I’m happy to take questions,

    
 but I prefer to answer them after my talk.
 
 I’m very happy to do a breakout session where we go Wild West and mess around in a REPL. MC Ryan, please poll our audience to see 
 who’d like to attend a Datomic breakout session?
  7. Disclaimer: I’m just a normal Datomic user. All mistakes are

    mine. Please, please correct me if I’m wrong!
  8. Part 2 Some lessons from doing this for a while

    (Some of these may be eye-rollingly obvious; we were newbies, I promise!)
  9. Database values as global vars. This includes wrapping over a

    function that automatically calls (d/db (d/connect ...)) for you in a data access layer, so that client functions don’t have to worry about it. Just. Don't. Do it. Treat databases like any other value: pass it around! 
 Keep those functions pure! A tip for web apps: use middleware to inject a db value into your requests, and pass it around from there. This keeps reads for a request on a consistent view of your data.
  10. Source of truth for schema. It’s your database, not your

    source code. Schema in source code is useful e.g. for creating testing databases, 
 but look to your database for the actual truth. Get comfortable with doing this. You’ll save yourself time! (I have something to share at the end, that’ll help you with this.)
  11. Annotate your transactions. Seriously. You’ll really wish you did, later.

    This is a great place to wrap the Datomic API with your own code.
  12. Cardinality-many retractions gotcha. New folks often think that to update

    a :cardinality/many attribute, they can simply assert the new collection, and magically Datomic will retract all the values not present in the new collection. Some folks get … annoyed, when it doesn’t do this.
  13. Cardinality-many retractions gotcha. I’ve got your back: New folks often

    think that to update a :cardinality/many attribute, they can simply assert the new collection, and magically Datomic will retract all the values not present in the new collection.
  14. Use Datalog when it’s actually necessary. I particularly encourage you

    to try to model your queries in terms of d/datoms and normal Clojure functions, 
 even if just to build your understanding of this stuff.
  15. What I hope you got from this. Knowing how the

    data is modelled by Datomic: Allows you to work with it more like any other in-memory Clojure data-structure, 
 rather than data “over there in the database”. Gives you a major advantage when learning the APIs. Greatly assists you when reasoning about scale. And some practical tips!
  16. One last thing :-) That’s all, folks. Thank you! github.com/cognician/datomic-doc

    Check out Datomic Doc, 
 a library I released recently, 
 for editing :db/doc strings in a web UI: Twitter: RobStuttaford Github: robert-stuttaford