Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Datomic Spotlight
Search
Amitay Horwitz
August 24, 2017
Programming
0
90
Datomic Spotlight
Amitay Horwitz
August 24, 2017
Tweet
Share
More Decks by Amitay Horwitz
See All by Amitay Horwitz
Transducers
amitayh
0
41
Building event sourced systems with Kafka Streams
amitayh
1
800
Event Sourcing with Kafka Streams
amitayh
1
920
TDD For The Curious
amitayh
0
280
Other Decks in Programming
See All in Programming
イベント駆動で成長して委員会
happymana
1
270
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
790
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
4
1k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
340
JavaでLチカしたい! / JJUG CCC 2024 Fall LT
nhayato
0
120
役立つログに取り組もう
irof
28
9.4k
Outline View in SwiftUI
1024jp
1
290
現場で役立つモデリング 超入門
masuda220
PRO
15
3.1k
macOS でできる リアルタイム動画像処理
biacco42
9
2.3k
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
140
CSC509 Lecture 11
javiergs
PRO
0
180
リリース8年目のサービスの1800個のERBファイルをViewComponentに移行した方法とその結果
katty0324
5
4.2k
Featured
See All Featured
Visualization
eitanlees
145
15k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Docker and Python
trallard
40
3.1k
Happy Clients
brianwarren
97
6.7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
Agile that works and the tools we love
rasmusluckow
327
21k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
Code Review Best Practice
trishagee
64
17k
How GitHub (no longer) Works
holman
310
140k
Building an army of robots
kneath
302
42k
Designing for Performance
lara
604
68k
Transcript
DATOMIC @amitayh THE FUNCTIONAL DATABASE
FULL DISCLOSURE ⚠
ABOUT DATOMIC • Developed by Cognitect • Initial release 2012
• Designed by Rich Hickey (author of the Clojure programming language) • Used by Facebook, Netflix, more…
FACTS ✅
FACTS • “Abraham Lincoln is the president of the United
States”
FACTS • “Abraham Lincoln is the president of the United
States” • “Abraham Lincoln was elected president of the United States on March 4, 1861”
FACTS • Abraham Lincoln • Position • President • March
4, 1861 Entity Attribute Value Timestamp
FACT = DATOM Entity Attribute Value Tx Operation
FACT = DATOM Entity Attribute Value Tx Operation 1033 :first-name
"Abraham" 260 add 1033 :last-name "Lincoln" 260 add 1033 :position "Lawyer" 277 add
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
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
FACT BASED MODEL Facts Facts Facts Facts Facts Facts Facts
Facts Time Facts Facts Time
GIT Facts Facts Facts Facts Objects Facts Facts Objects Time
Facts Objects Time
A DATABASE • A collection of datoms • At a
specific point in time • An immutable value
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
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
QUERIES
DATALOG • Equivalent to relational model + recursion • Declarative,
expressive and powerful • Pattern matching style • No more string concatenation!
EXAMPLE DATABASE Entity Attribute Value 42 :email
[email protected]
43 :email
[email protected]
42 :orders 107 42 :orders 141
DATA PATTERN Constrains the results returned, binds variables: [?customer :email
?email] Attribute Value Entity
DATA PATTERN Constrains the results returned, binds variables: [?customer :email
?email] Constant Variable Variable
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]
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]
Entity Attribute Value 42 :email
[email protected]
43 :email
[email protected]
42
:orders 107 42 :orders 141 “What attributes does 42 have?” [42 ?attribute]
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]
WHERE CLAUSE [:find ?customer :where [?customer :email]] Data pattern
FIND CLAUSE [:find ?customer :where [?customer :email]]
IMPLICIT JOIN [:find ?customer :where [?customer :email] [?customer :orders]] “Find
all the customers who have placed orders”
PREDICATES [:find ?item :where [?item :item/price ?price] [(< 50 ?price)]]
“Find the expensive items”
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”
ARCHITECTURE
DATABASE ROLES • Queries • Transactions • Consistency • Storage
BREAK DOWN
DATOMIC COMPONENTS Peer library Transactor Storage
PEER LIBRARY Transactor Storage Peer library Your app • Embedded
in your app • Executed queries locally
Peer library Your app cache PEER LIBRARY Transactor Storage •
Reads data from storage • Caches locally
Peer library Your app cache Peer library Your app cache
Peer library Your app cache SCALE HORIZONTALLY Transactor Storage
TRANSACTOR Transactor Storage Peer library Your app • Standalone service
• Scales vertically
Transactor TRANSACTOR Transactor Storage Peer library Your app • Standalone
service • Scales vertically • Hot standby for failover
Transactor TRANSACTOR Storage Peer library Your app • Coordinates writes
• Guarantees ACID transactions (isolation level “serializable”)
Storage Transactor TRANSACTOR Peer library Your app • Writes transaction
log to storage • Generates indices
Peer library Your app cache Peer library Your app cache
Peer library Your app cache Storage Transactor TRANSACTOR • Broadcasts live updates
STORAGE Transactor Storage Peer library Your app • Provided as
a service • Many different backends
LOCAL STORAGE Transactor Storage Peer library Your app • Memory
• Filesystem • Great for testing!
NEARBY STORAGE Transactor Storage Peer library Your app • SQL
database (any JDBC)
DISTRIBUTED STORAGE ☁ Transactor Storage Peer library Your app •
DynamoDB • Riak • CouchBase • Cassandra • …
Peer library Your app cache Peer library Your app cache
Peer library Your app cache SHARED MEMCACHED Transactor Storage Memcached
EVENT SOURCING? • Datomic is lower level - facts vs
events • Annotate transactions! • Querying already built in • Listen on transaction queue to build reactive systems
Q&A
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