Simplest “Fetch”
‣ Pros
• concise & clean
‣ Cons
• very slow with sequential HTTP/TCP calls
• duplicate requests (fetch same User a few times)
• hard to batch requests (i.e. use MGET for Redis)
Slide 8
Slide 8 text
core.async & dedup
Slide 9
Slide 9 text
Optimized “Fetch”
‣ Optimization leads to unnecessary complexity in code
‣ Hard to dig through the code
‣ We want concise code that operates efficiently
‣ Not only a Clojure problem
Slide 10
Slide 10 text
Known Solutions
Slide 11
Slide 11 text
Known Solutions
‣ Haxl - Haskell library, Facebook, open sourced
• Key idea: Applicative functors to manage
dependencies between data fetches under the
hood with implicit concurrency & batches
Slide 12
Slide 12 text
Known Solutions
‣ Stitch - Scala library, Twitter, not open sourced
• Key idea: Build declarative AST of all data fetch
operations and run special interpreter that will
choose the most efficient evaluation strategy
Slide 13
Slide 13 text
Known Solutions
‣ The idea behind Stitch should sound familiar
‣ go macro from core.async uses the same approach
Slide 14
Slide 14 text
What About Clojure?
‣ Muse library
‣ github.com/kachayev/muse
‣ Open sourced a couple of weeks ago
‣ Still in active development
‣ Uses the idea of building and interpreting AST
‣ Uses core.async to deal with concurrency
What Can It Do For You?
‣ Runs independent data fetches concurrently
• Uses BFS to group fetches level-by-level
‣ Caches previously made fetches during execution
‣ Batches requests when applicable
Slide 38
Slide 38 text
With Muse
Slide 39
Slide 39 text
With Muse
T1
P1
P2
P3
P4
U1
US1
U2
US2
U3
US3
Timeline Posts Users & Scores
Slide 40
Slide 40 text
With Muse
T1
P1
P2
P3
P4
U1
US1
U2
US2
U3
US3
Timeline Posts Users & Scores
Slide 41
Slide 41 text
With Muse
T1
P1
P2
P3
P4
U1
US1
U2
US2
U3
US3
Timeline Posts Users & Scores
Slide 42
Slide 42 text
With Muse
‣ how did we achieve this?
‣ nice separation of concerns:
• muse to tell WHAT do I want to do
• core.async to tell HOW
‣ generalized abstraction that doesn’t know nothing
about concrete data storages
Slide 43
Slide 43 text
Known Restrictions
‣ Assumes your data fetches are “side-effect free”
• You should not rely on the order
‣ You need enough memory to store fetches
‣ Uses core.async to run fetches concurrently
Slide 44
Slide 44 text
Future Plans
‣ Better error handling
‣ Debug-mode to trace all fetches with latencies
‣ Applicative functors interface
‣ Get rid of fmap & flat-map
‣ ClojureScript support
Slide 45
Slide 45 text
Future Plans
‣ Looking for feedback from adopters
‣ Stay tuned for more!