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
810
Event Sourcing with Kafka Streams
amitayh
1
930
TDD For The Curious
amitayh
0
280
Other Decks in Programming
See All in Programming
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
160
ドメインイベント増えすぎ問題
h0r15h0
2
480
情報漏洩させないための設計
kubotak
4
1.1k
103 Early Hints
sugi_0000
1
280
Online-Dokumentation, die hilft: Strukturen, Prozesse, Tools
ahus1
0
100
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
190
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
800
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
250
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.1k
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
100
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
210
Go の GC の不得意な部分を克服したい
taiyow
3
890
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
470
Optimising Largest Contentful Paint
csswizardry
33
3k
Documentation Writing (for coders)
carmenintech
67
4.5k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
190
Automating Front-end Workflow
addyosmani
1366
200k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
1
130
We Have a Design System, Now What?
morganepeng
51
7.3k
RailsConf 2023
tenderlove
29
950
What's in a price? How to price your products and services
michaelherold
244
12k
Navigating Team Friction
lara
183
15k
How STYLIGHT went responsive
nonsquared
96
5.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
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